Skip to content

Commit d2c8b2a

Browse files
Fixed Date field format in automated tests (#13)
* fixed the date of birth field format in the test, added docker compose for toolshop website, updated the github actions workflow to use docker compose * fixed github actions issue by removing the working directory for seeding the db * fixed github actions workflow issue by updating the command to seed db and removed 60s sleep * added 60s delay before seeding the DB * added new logic to move to the warning message and get its text as it was not coming into view * changed window size * changed warning message locator * added footer link to check footer verifying that the message is displayed * increased delay to 90s * removed install java step as it is already available in checkout step * added steps to get version and post login after DB seeding * reverted to old github actions workflow
1 parent f82c21a commit d2c8b2a

File tree

8 files changed

+107
-91
lines changed

8 files changed

+107
-91
lines changed

.github/workflows/maven.yml

Lines changed: 50 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven
3-
4-
# This workflow uses actions that are not certified by GitHub.
5-
# They are provided by a third-party and are governed by
6-
# separate terms of service, privacy policy, and support
7-
# documentation.
8-
91
name: Java CI with Maven
102

113
on:
@@ -20,69 +12,59 @@ on:
2012
- issue-*
2113

2214
permissions:
23-
statuses: write
24-
checks: write
25-
contents: write
26-
pull-requests: write
15+
statuses: write
16+
checks: write
17+
contents: write
18+
pull-requests: write
2719

2820
jobs:
2921
build:
30-
name: Build and Test
22+
name: Build and Test
3123
runs-on: ubuntu-latest
3224

3325
steps:
34-
- uses: actions/checkout@v4
35-
- name: Set up JDK 17
36-
uses: actions/setup-java@v4
37-
with:
38-
java-version: '17'
39-
distribution: 'temurin'
40-
cache: maven
41-
42-
- name: Install Java and Maven
43-
uses: actions/setup-java@v4
44-
with:
45-
java-version: '17'
46-
distribution: 'adopt'
47-
cache: maven
48-
49-
- name: Checkout Practice Software Testing repo
50-
uses: actions/checkout@v4
51-
with:
52-
repository: testsmith-io/practice-software-testing
53-
path: practice-repo
54-
55-
- name: Start Practice Software Testing with Docker Compose
56-
working-directory: practice-repo
57-
run: docker compose -f docker-compose.yml up -d
58-
59-
- name: Sleep for 60 seconds
60-
run: sleep 60s
61-
shell: bash
62-
63-
- name: Create and Seed Database
64-
working-directory: practice-repo
65-
run: |
66-
docker compose exec laravel-api php artisan migrate:fresh --seed
67-
68-
- name: Install Chrome
69-
uses: browser-actions/setup-chrome@latest
70-
71-
- name: Build Project and run tests
72-
run: mvn clean install
73-
74-
- name: Upload screenshots
75-
if: always()
76-
uses: actions/upload-artifact@v4
77-
with:
78-
name: test-screenshots
79-
path: screenshots
80-
81-
- name: Test Report
82-
uses: dorny/test-reporter@v2
83-
if: success() || failure()
84-
with:
85-
name: Test Results
86-
path: ${{ github.workspace }}/target/surefire-reports/TEST-TestSuite.xml
87-
reporter: java-junit
88-
java-version: 17
26+
- uses: actions/checkout@v4
27+
- name: Set up JDK 17
28+
uses: actions/setup-java@v4
29+
with:
30+
java-version: '17'
31+
distribution: 'temurin'
32+
cache: maven
33+
34+
- name: Checkout Practice Software Testing repo
35+
uses: actions/checkout@v4
36+
with:
37+
repository: testsmith-io/practice-software-testing
38+
path: practice-repo
39+
40+
- name: Start Practice Software Testing with Docker Compose
41+
working-directory: practice-repo
42+
run: docker compose -f docker-compose.yml up -d
43+
44+
- name: Sleep for 60 seconds
45+
run: sleep 60s
46+
shell: bash
47+
48+
- name: Create and Seed Database
49+
working-directory: practice-repo
50+
run: |
51+
docker compose exec laravel-api php artisan migrate:fresh --seed
52+
53+
- name: Build Project and run tests
54+
run: mvn clean install
55+
56+
- name: Upload screenshots
57+
if: always()
58+
uses: actions/upload-artifact@v4
59+
with:
60+
name: test-screenshots
61+
path: screenshots
62+
63+
- name: Test Report
64+
uses: dorny/test-reporter@v2
65+
if: success() || failure()
66+
with:
67+
name: Test Results
68+
path: ${{ github.workspace }}/target/surefire-reports/TEST-TestSuite.xml
69+
reporter: java-junit
70+
java-version: 17

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
target/
22
.idea/
33
/screenshots/
4+
/API
5+
/UI
46

57
### VS Code ###
68
.vscode/

UI/package-lock.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

docker-compose-toolshop.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
version: '2'
2+
services:
3+
laravel-api:
4+
image: testsmith/practice-software-testing-sprint5-api
5+
environment:
6+
- "PHP_OPCACHE_VALIDATE_TIMESTAMPS=1"
7+
- "DB_PORT=3306"
8+
- "DB_HOST=mariadb"
9+
- "host=localhost"
10+
- DISABLE_LOGGING=true
11+
12+
angular-ui:
13+
image: testsmith/practice-software-testing-sprint5-ui
14+
ports:
15+
- 4200:4200
16+
command: >
17+
bash -c "ng serve --host 0.0.0.0 --port 4200"
18+
19+
web:
20+
image: testsmith/practice-software-testing-web
21+
ports:
22+
- 8091:80
23+
- 8000:81
24+
depends_on:
25+
- laravel-api
26+
27+
mariadb:
28+
image: yobasystems/alpine-mariadb:10.6.11
29+
ports:
30+
- 3306:3306
31+
expose:
32+
- 3306
33+
environment:
34+
MYSQL_ROOT_PASSWORD: root
35+
MYSQL_USER: user
36+
MYSQL_PASSWORD: root
37+
MYSQL_DATABASE: toolshop

src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package io.github.mfaisalkhatri.pages;
22

33
import java.time.Duration;
4-
import java.time.LocalDate;
5-
import java.time.format.DateTimeFormatter;
64

75
import io.github.mfaisalkhatri.data.RegistrationData;
86
import org.openqa.selenium.By;
97
import org.openqa.selenium.WebDriver;
108
import org.openqa.selenium.WebElement;
9+
import org.openqa.selenium.interactions.Actions;
1110
import org.openqa.selenium.support.ui.ExpectedConditions;
1211
import org.openqa.selenium.support.ui.Select;
1312
import org.openqa.selenium.support.ui.WebDriverWait;
@@ -29,7 +28,7 @@ public void fillRegistrationForm (final RegistrationData registrationData) {
2928
firstNameField ().sendKeys (registrationData.getFirstName ());
3029
lastNameField ().clear ();
3130
lastNameField ().sendKeys (registrationData.getLastName ());
32-
dobField ().sendKeys (dateOfBirth (registrationData.getDob ()));
31+
dobField ().sendKeys (registrationData.getDob ());
3332
streetField ().clear ();
3433
streetField ().sendKeys (registrationData.getStreet ());
3534
postalCodeField ().clear ();
@@ -54,8 +53,14 @@ public String pageHeader () {
5453
}
5554

5655
public String passwordAlertMessage () {
57-
return wait.until (ExpectedConditions.visibilityOfElementLocated (By.cssSelector (".alert-danger div")))
58-
.getText ();
56+
Actions actions = new Actions (driver);
57+
actions.moveToElement (footerField ()).build ().perform ();
58+
WebElement warningMessage = wait.until (
59+
ExpectedConditions.visibilityOfElementLocated (By.cssSelector ("div.alert")));
60+
actions.moveToElement (warningMessage)
61+
.build ()
62+
.perform ();
63+
return warningMessage.getText ();
5964
}
6065

6166
private WebElement cityField () {
@@ -110,12 +115,8 @@ private WebElement streetField () {
110115
return this.driver.findElement (By.id ("street"));
111116
}
112117

113-
private String dateOfBirth (String jsonDate) {
114-
115-
DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern ("dd/MM/yyyy");
116-
LocalDate date = LocalDate.parse (jsonDate, inputFormat);
117-
118-
DateTimeFormatter outputFormat = DateTimeFormatter.ofPattern ("MM/dd/yyyy");
119-
return date.format (outputFormat);
118+
private WebElement footerField () {
119+
return this.driver.findElement (By.cssSelector ("app-footer p"));
120120
}
121+
121122
}

src/test/java/io/github/mfaisalkhatri/test/BaseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public WebDriver getDriver () {
2121
@BeforeClass
2222
public void setup () {
2323
ChromeOptions chromeOptions = new ChromeOptions ();
24-
chromeOptions.addArguments ("--headless=new","--no-sandbox", "--window-size=1920,1080");
24+
chromeOptions.addArguments ("--headless=new","--no-sandbox","--window-size=1920,1080");
2525

2626
this.driver = new ChromeDriver (chromeOptions);
2727
this.driver.manage ()

src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public Iterator<RegistrationData> getValidRegistrationData () {
3232
@Test (dataProvider = "getValidRegistrationData")
3333
public void testRegistrationPasswordAlert (final RegistrationData registrationData) {
3434
this.driver.get ("http://localhost:4200/");
35-
//this.driver.get ("https://practicesoftwaretesting.com/auth/register");
35+
// this.driver.get ("https://practicesoftwaretesting.com/auth/register");
3636

3737
HomePage homePage = new HomePage (driver);
3838
LoginPage loginPage = homePage.navigateToLoginPage ();

src/test/resources/testdata.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"firstName": "Jason",
55
"lastName": "Langer",
6-
"dob": "17/05/1987",
6+
"dob": "1987-11-19",
77
"street": "11/2, Fort Street",
88
"postalCode": "113445",
99
"city": "California",
@@ -17,7 +17,7 @@
1717
{
1818
"firstName": "Michael",
1919
"lastName": "Justin",
20-
"dob": "23/07/1985",
20+
"dob": "1985-04-23",
2121
"street": "21/4, Dallas Street",
2222
"postalCode": "12976",
2323
"city": "California",
@@ -31,7 +31,7 @@
3131
{
3232
"firstName": "Abraham",
3333
"lastName": "Lord",
34-
"dob": "16/06/1981",
34+
"dob": "1981-08-30",
3535
"street": "30/2, Texas Street",
3636
"postalCode": "155642",
3737
"city": "California",

0 commit comments

Comments
 (0)