From caf03051cbb27028a8e523b3f41472aad34e2f23 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 17:43:56 +0300 Subject: [PATCH 01/29] added github actions workflow for maven --- .github/workflows/maven.yml | 52 +++++++++++++++++++++++++++++++++++++ pom.xml | 6 +++++ 2 files changed, 58 insertions(+) create mode 100644 .github/workflows/maven.yml diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml new file mode 100644 index 0000000..978859a --- /dev/null +++ b/.github/workflows/maven.yml @@ -0,0 +1,52 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: + - main + - issue-* + + pull_request: + branches: + - main + - issue-* + +permissions: + statuses: write + checks: write + contents: write + pull-requests: write + +jobs: + build: + name: Build and Test + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + - name: Build Project and run tests + run: mvn clean install + + - name: Test Report + uses: dorny/test-reporter@v2 + if: success() || failure() + with: + name: Test Results + path: ${{ github.workspace }}/target/surefire-reports/TEST-TestSuite.xml + reporter: java-junit + java-version: 17 \ No newline at end of file diff --git a/pom.xml b/pom.xml index 87d60f1..9ecdc5b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,8 @@ 3.13.0 3.5.0 UTF-8 + testng.xml + -Dfile.encoding=UTF-8 -Xdebug -Xnoagent @@ -76,6 +78,10 @@ false + + ${suite-xml} + + ${argLine} From 3d63108494f21c48fb706d526a96284229e5b5c1 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 17:44:52 +0300 Subject: [PATCH 02/29] added dependabot yml for weekly version update check --- .github/dependabot.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..35471d4 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,26 @@ +# Please see the documentation for all configuration options: +# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file + +version: 2 +updates: + - package-ecosystem: "maven" + directory: "/" + target-branch: main + open-pull-requests-limit: 20 + schedule: + interval: "weekly" + timezone: "Asia/Calcutta" + groups: + dependencies: + dependency-type: 'production' + + - package-ecosystem: "github-actions" + directory: "/" + target-branch: main + open-pull-requests-limit: 20 + schedule: + interval: "weekly" + timezone: "Asia/Calcutta" + groups: + dependencies: + dependency-type: 'production' From 3fdebc72a45d70151fa72a6ce791f54785612a47 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 17:48:12 +0300 Subject: [PATCH 03/29] added steps to install Java, Maven and Chrome browser before running the tests --- .github/workflows/maven.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 978859a..603372f 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -39,6 +39,16 @@ jobs: distribution: 'temurin' cache: maven + - name: Install Java and Maven + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'adopt' + cache: maven + + - name: Install Chrome + uses: browser-actions/setup-chrome@latest + - name: Build Project and run tests run: mvn clean install From 6f59c05f503d3b4fc9fb0d2d4b76ca716518e9ac Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 18:01:23 +0300 Subject: [PATCH 04/29] added chromeoptions to run tests in headless mode --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 6cffe1e..121045f 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -4,6 +4,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -13,6 +14,11 @@ public class BaseTest { @BeforeClass public void setup () { + ChromeOptions chromeOptions = new ChromeOptions (); + chromeOptions.addArguments ("--headless=new"); + chromeOptions.addArguments ("disable-gpu"); + chromeOptions.addArguments("--disable-dev-shm-usage"); + this.driver = new ChromeDriver (); this.driver.manage () .window () From 3f34e7006aea4a37f3ce5d90bf698bf8879e8215 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 18:03:01 +0300 Subject: [PATCH 05/29] added chromOptions in chromedriver --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 121045f..14c9faa 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -19,7 +19,7 @@ public void setup () { chromeOptions.addArguments ("disable-gpu"); chromeOptions.addArguments("--disable-dev-shm-usage"); - this.driver = new ChromeDriver (); + this.driver = new ChromeDriver (chromeOptions); this.driver.manage () .window () .maximize (); From d5a319226f4a197b5c56f81cb817cffeb6e39805 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 18:07:33 +0300 Subject: [PATCH 06/29] added window size chrome options for github actions --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 14c9faa..e986f35 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -18,6 +18,7 @@ public void setup () { chromeOptions.addArguments ("--headless=new"); chromeOptions.addArguments ("disable-gpu"); chromeOptions.addArguments("--disable-dev-shm-usage"); + chromeOptions.addArguments ("--window-size=1280,1024"); this.driver = new ChromeDriver (chromeOptions); this.driver.manage () From f9bee0db43cca94a11ad2a8b3b0e3f1b0d54dda4 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 18:13:06 +0300 Subject: [PATCH 07/29] removed window maximize code --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index e986f35..5b515e1 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -21,9 +21,6 @@ public void setup () { chromeOptions.addArguments ("--window-size=1280,1024"); this.driver = new ChromeDriver (chromeOptions); - this.driver.manage () - .window () - .maximize (); this.driver.manage () .timeouts () .implicitlyWait (Duration.ofSeconds (30)); From ac30c429cc5b8a7dc51df197fb9b171d2cfcd01a Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 18:19:40 +0300 Subject: [PATCH 08/29] added explicit wait for locating elements --- .../github/mfaisalkhatri/pages/RegistrationPage.java | 12 ++++++++++-- .../mfaisalkhatri/test/JsonDataProviderTest.java | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java index da4233e..f2297c2 100644 --- a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java +++ b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java @@ -1,17 +1,25 @@ package io.github.mfaisalkhatri.pages; +import java.time.Duration; + import io.github.mfaisalkhatri.data.RegistrationData; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; public class RegistrationPage { private final WebDriver driver; + private final WebDriverWait wait; + public RegistrationPage (final WebDriver driver) { + this.driver = driver; + this.wait = new WebDriverWait (driver, Duration.ofSeconds (30)); } public void fillRegistrationForm (final RegistrationData registrationData) { @@ -39,12 +47,12 @@ public void fillRegistrationForm (final RegistrationData registrationData) { } public String pageHeader () { - return this.driver.findElement (By.cssSelector ("app-register h3")) + return wait.until (ExpectedConditions.visibilityOfElementLocated (By.cssSelector ("app-register h3"))) .getText (); } public String passwordAlertMessage () { - return this.driver.findElement (By.cssSelector (".alert-danger div")) + return wait.until (ExpectedConditions.visibilityOfElementLocated (By.cssSelector (".alert-danger div"))) .getText (); } diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index 8e55872..0122863 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -23,8 +23,10 @@ public Iterator getValidRegistrationData () { public void testRegistrationPasswordAlert (final RegistrationData registrationData) { final RegistrationPage registrationPage = new RegistrationPage (this.driver); this.driver.get ("https://practicesoftwaretesting.com/auth/register"); + System.out.println ("Navigate to the url success!"); assertEquals (registrationPage.pageHeader (), "Customer registration"); + System.out.println ("verified page header!"); registrationPage.fillRegistrationForm (registrationData); assertEquals (registrationPage.passwordAlertMessage (), From 24cb28ed46be049cb4105a4f80d43db3d3281858 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 18:24:48 +0300 Subject: [PATCH 09/29] added chromeoptions - no-sandbox and changed window size --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 5b515e1..2526da0 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -18,7 +18,8 @@ public void setup () { chromeOptions.addArguments ("--headless=new"); chromeOptions.addArguments ("disable-gpu"); chromeOptions.addArguments("--disable-dev-shm-usage"); - chromeOptions.addArguments ("--window-size=1280,1024"); + chromeOptions.addArguments ("--window-size=1920,1080"); + chromeOptions.addArguments("--no-sandbox"); this.driver = new ChromeDriver (chromeOptions); this.driver.manage () From 2fdc539835cb33098ce388c9c1b2d8cb347625b6 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 19:03:50 +0300 Subject: [PATCH 10/29] testng listener added to take screenshot on failure, added step to upload screenshot on failure in github actions --- .github/workflows/maven.yml | 7 ++++ .../github/mfaisalkhatri/test/BaseTest.java | 18 ++++++---- .../utils/ScreenshotListener.java | 33 +++++++++++++++++++ .../utils/WebDriverProvider.java | 7 ++++ testng.xml | 3 ++ 5 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java create mode 100644 src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 603372f..45b2736 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -52,6 +52,13 @@ jobs: - name: Build Project and run tests run: mvn clean install + - name: Upload screenshots + if: always() + uses: actions/upload-artifact@v4 + with: + name: test-screenshots + path: screenshots + - name: Test Report uses: dorny/test-reporter@v2 if: success() || failure() diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 2526da0..ec423bc 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -2,24 +2,26 @@ import java.time.Duration; +import io.github.mfaisalkhatri.utils.WebDriverProvider; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; -public class BaseTest { +public class BaseTest implements WebDriverProvider { protected WebDriver driver; + @Override + public WebDriver getDriver () { + return driver; + } + @BeforeClass public void setup () { ChromeOptions chromeOptions = new ChromeOptions (); - chromeOptions.addArguments ("--headless=new"); - chromeOptions.addArguments ("disable-gpu"); - chromeOptions.addArguments("--disable-dev-shm-usage"); - chromeOptions.addArguments ("--window-size=1920,1080"); - chromeOptions.addArguments("--no-sandbox"); + chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); this.driver = new ChromeDriver (chromeOptions); this.driver.manage () @@ -29,6 +31,8 @@ public void setup () { @AfterClass public void tearDown () { - this.driver.quit (); + if (driver != null) { + this.driver.quit (); + } } } diff --git a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java new file mode 100644 index 0000000..3345ac1 --- /dev/null +++ b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java @@ -0,0 +1,33 @@ +package io.github.mfaisalkhatri.utils; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; +import org.openqa.selenium.WebDriver; +import org.testng.ITestListener; +import org.testng.ITestResult; + +public class ScreenshotListener implements ITestListener { + @Override + public void onTestFailure (final ITestResult result) { + Object testClass = result.getInstance (); + WebDriver driver = ((WebDriverProvider) testClass).getDriver (); + + if (driver != null) { + String testName = result.getMethod () + .getMethodName (); + File screenshot = ((TakesScreenshot) driver).getScreenshotAs (OutputType.FILE); + try { + Files.createDirectories (Paths.get ("screenshots")); + Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName, ".png")); + } catch (IOException e) { + throw new RuntimeException (e); + } + } + + } +} diff --git a/src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java b/src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java new file mode 100644 index 0000000..c86a4bf --- /dev/null +++ b/src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java @@ -0,0 +1,7 @@ +package io.github.mfaisalkhatri.utils; + +import org.openqa.selenium.WebDriver; + +public interface WebDriverProvider { + WebDriver getDriver (); +} diff --git a/testng.xml b/testng.xml index a359927..40495cd 100644 --- a/testng.xml +++ b/testng.xml @@ -1,6 +1,9 @@ + + + From c9d033615b7228e2d2662c77da149ad9bd8e8248 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 19:07:16 +0300 Subject: [PATCH 11/29] correct screensjhot upload path and formatted lines --- .../java/io/github/mfaisalkhatri/utils/ScreenshotListener.java | 3 +-- .../java/io/github/mfaisalkhatri/utils/WebDriverProvider.java | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java index 3345ac1..8ccde18 100644 --- a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java +++ b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java @@ -23,11 +23,10 @@ public void onTestFailure (final ITestResult result) { File screenshot = ((TakesScreenshot) driver).getScreenshotAs (OutputType.FILE); try { Files.createDirectories (Paths.get ("screenshots")); - Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName, ".png")); + Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName+ ".png")); } catch (IOException e) { throw new RuntimeException (e); } } - } } diff --git a/src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java b/src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java index c86a4bf..9d1ed96 100644 --- a/src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java +++ b/src/test/java/io/github/mfaisalkhatri/utils/WebDriverProvider.java @@ -4,4 +4,4 @@ public interface WebDriverProvider { WebDriver getDriver (); -} +} \ No newline at end of file From 00525f334544ee12a861ed9f682b05bb99dafb41 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 19:14:34 +0300 Subject: [PATCH 12/29] added chrome option to use disable-link-features --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index ec423bc..89bc6ea 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -21,6 +21,7 @@ public WebDriver getDriver () { @BeforeClass public void setup () { ChromeOptions chromeOptions = new ChromeOptions (); + chromeOptions.addArguments("--disable-blink-features=AutomationControlled"); chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); this.driver = new ChromeDriver (chromeOptions); From a21c941c397e68a77815c695e383733860161d69 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 19:20:28 +0300 Subject: [PATCH 13/29] updated BaseTest with automation extension arguments to handle cloudfare popup in github actions run --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 89bc6ea..58556ec 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -22,6 +22,7 @@ public WebDriver getDriver () { public void setup () { ChromeOptions chromeOptions = new ChromeOptions (); chromeOptions.addArguments("--disable-blink-features=AutomationControlled"); + chromeOptions.setExperimentalOption("useAutomationExtension", false); chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); this.driver = new ChromeDriver (chromeOptions); From 71003610aa8f561bc57b9c6c64ba883aa68d0249 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 20:01:14 +0300 Subject: [PATCH 14/29] appended timestamp in the filename to get unique screenshot name every time --- .../io/github/mfaisalkhatri/utils/ScreenshotListener.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java index 8ccde18..3889b0f 100644 --- a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java +++ b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java @@ -4,6 +4,8 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; import org.openqa.selenium.OutputType; import org.openqa.selenium.TakesScreenshot; @@ -16,14 +18,17 @@ public class ScreenshotListener implements ITestListener { public void onTestFailure (final ITestResult result) { Object testClass = result.getInstance (); WebDriver driver = ((WebDriverProvider) testClass).getDriver (); + String timestamp = new SimpleDateFormat ("yyyyMMdd_HHmmss_SSS").format (new Date ()); + if (driver != null) { String testName = result.getMethod () .getMethodName (); File screenshot = ((TakesScreenshot) driver).getScreenshotAs (OutputType.FILE); + String filename = timestamp + ".png"; try { Files.createDirectories (Paths.get ("screenshots")); - Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName+ ".png")); + Files.copy (screenshot.toPath (), Paths.get (testName, filename)); } catch (IOException e) { throw new RuntimeException (e); } From bc7aa2b21e0b25ebc29e488c8c7f5e26c7c9d286 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 20:21:53 +0300 Subject: [PATCH 15/29] fixed screenshot filename issue --- .../java/io/github/mfaisalkhatri/utils/ScreenshotListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java index 3889b0f..e79c616 100644 --- a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java +++ b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java @@ -28,7 +28,7 @@ public void onTestFailure (final ITestResult result) { String filename = timestamp + ".png"; try { Files.createDirectories (Paths.get ("screenshots")); - Files.copy (screenshot.toPath (), Paths.get (testName, filename)); + Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName, filename)); } catch (IOException e) { throw new RuntimeException (e); } From 5d232ec361a798b5f804cf39c3f0673f58ac4b7f Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 20:24:14 +0300 Subject: [PATCH 16/29] fixed screenshot filename issue with timestamp --- .../java/io/github/mfaisalkhatri/utils/ScreenshotListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java index e79c616..184349d 100644 --- a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java +++ b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java @@ -28,7 +28,7 @@ public void onTestFailure (final ITestResult result) { String filename = timestamp + ".png"; try { Files.createDirectories (Paths.get ("screenshots")); - Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName, filename)); + Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName+"_"+filename)); } catch (IOException e) { throw new RuntimeException (e); } From 69dd9f9e8b953e6ce9be01c3c54c6aa83584c2de Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 20:38:06 +0300 Subject: [PATCH 17/29] added registration page navigation steps --- .../github/mfaisalkhatri/pages/HomePage.java | 25 +++++++++++++++++++ .../github/mfaisalkhatri/pages/LoginPage.java | 24 ++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/test/java/io/github/mfaisalkhatri/pages/HomePage.java create mode 100644 src/test/java/io/github/mfaisalkhatri/pages/LoginPage.java diff --git a/src/test/java/io/github/mfaisalkhatri/pages/HomePage.java b/src/test/java/io/github/mfaisalkhatri/pages/HomePage.java new file mode 100644 index 0000000..6ea17d4 --- /dev/null +++ b/src/test/java/io/github/mfaisalkhatri/pages/HomePage.java @@ -0,0 +1,25 @@ +package io.github.mfaisalkhatri.pages; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class HomePage { + + private final WebDriver driver; + + public HomePage(WebDriver driver) { + this.driver=driver; + } + + public LoginPage navigateToRegistrationPage() { + signInLink ().click (); + return new LoginPage (driver); + + } + private WebElement signInLink() { + return this.driver.findElement (By.linkText ("Sign in")); + } + + +} diff --git a/src/test/java/io/github/mfaisalkhatri/pages/LoginPage.java b/src/test/java/io/github/mfaisalkhatri/pages/LoginPage.java new file mode 100644 index 0000000..977374b --- /dev/null +++ b/src/test/java/io/github/mfaisalkhatri/pages/LoginPage.java @@ -0,0 +1,24 @@ +package io.github.mfaisalkhatri.pages; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; + +public class LoginPage { + + private WebDriver driver; + + public LoginPage (WebDriver driver) { + this.driver = driver; + } + + private WebElement registerYourAccountLink () { + return this.driver.findElement (By.linkText ("Register your account")); + } + + public RegistrationPage navigateToRegistrationPage () { + registerYourAccountLink ().click (); + return new RegistrationPage (driver); + } + +} From c6c5e78a17162ada81720d24ab9fb84f9da5976e Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 20:49:49 +0300 Subject: [PATCH 18/29] added steps to navigate to home, login and then registration page --- .../io/github/mfaisalkhatri/pages/HomePage.java | 2 +- .../java/io/github/mfaisalkhatri/test/BaseTest.java | 9 ++++----- .../mfaisalkhatri/test/JsonDataProviderTest.java | 13 ++++++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/pages/HomePage.java b/src/test/java/io/github/mfaisalkhatri/pages/HomePage.java index 6ea17d4..2020009 100644 --- a/src/test/java/io/github/mfaisalkhatri/pages/HomePage.java +++ b/src/test/java/io/github/mfaisalkhatri/pages/HomePage.java @@ -12,7 +12,7 @@ public HomePage(WebDriver driver) { this.driver=driver; } - public LoginPage navigateToRegistrationPage() { + public LoginPage navigateToLoginPage() { signInLink ().click (); return new LoginPage (driver); diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 58556ec..433549c 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -20,12 +20,11 @@ public WebDriver getDriver () { @BeforeClass public void setup () { - ChromeOptions chromeOptions = new ChromeOptions (); - chromeOptions.addArguments("--disable-blink-features=AutomationControlled"); - chromeOptions.setExperimentalOption("useAutomationExtension", false); - chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); + //ChromeOptions chromeOptions = new ChromeOptions (); + //chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); - this.driver = new ChromeDriver (chromeOptions); + // this.driver = new ChromeDriver (chromeOptions); + this.driver = new ChromeDriver (); this.driver.manage () .timeouts () .implicitlyWait (Duration.ofSeconds (30)); diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index 0122863..2a725af 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -6,6 +6,8 @@ import io.github.mfaisalkhatri.data.RegistrationData; import io.github.mfaisalkhatri.data.RegistrationDataBuilder; +import io.github.mfaisalkhatri.pages.HomePage; +import io.github.mfaisalkhatri.pages.LoginPage; import io.github.mfaisalkhatri.pages.RegistrationPage; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -21,14 +23,15 @@ public Iterator getValidRegistrationData () { @Test (dataProvider = "getValidRegistrationData") public void testRegistrationPasswordAlert (final RegistrationData registrationData) { - final RegistrationPage registrationPage = new RegistrationPage (this.driver); - this.driver.get ("https://practicesoftwaretesting.com/auth/register"); - System.out.println ("Navigate to the url success!"); + this.driver.get ("https://practicesoftwaretesting.com"); + + HomePage homePage = new HomePage (driver); + LoginPage loginPage = homePage.navigateToLoginPage (); + RegistrationPage registrationPage = loginPage.navigateToRegistrationPage (); assertEquals (registrationPage.pageHeader (), "Customer registration"); - System.out.println ("verified page header!"); - registrationPage.fillRegistrationForm (registrationData); + registrationPage.fillRegistrationForm (registrationData); assertEquals (registrationPage.passwordAlertMessage (), "The given password has appeared in a data leak. Please choose a different password."); } From eac6b4391fc1e0503954a2169f2f54117ef0619c Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 20:50:51 +0300 Subject: [PATCH 19/29] removed commented code to run test in headless mode --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 433549c..ec423bc 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -20,11 +20,10 @@ public WebDriver getDriver () { @BeforeClass public void setup () { - //ChromeOptions chromeOptions = new ChromeOptions (); - //chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); + ChromeOptions chromeOptions = new ChromeOptions (); + chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); - // this.driver = new ChromeDriver (chromeOptions); - this.driver = new ChromeDriver (); + this.driver = new ChromeDriver (chromeOptions); this.driver.manage () .timeouts () .implicitlyWait (Duration.ofSeconds (30)); From 1f11262b7ca45feb7ce223662deedd5c6f91d9e6 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 21:53:09 +0300 Subject: [PATCH 20/29] added practice software testing docker compose in github actions --- .github/workflows/maven.yml | 10 ++++++++++ .gitignore | 1 + UI/package-lock.json | 6 ++++++ .../java/io/github/mfaisalkhatri/test/BaseTest.java | 2 +- .../mfaisalkhatri/test/JsonDataProviderTest.java | 2 +- 5 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 UI/package-lock.json diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 45b2736..410e040 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -46,6 +46,16 @@ jobs: distribution: 'adopt' cache: maven + - name: Checkout Practice Software Testing repo + uses: actions/checkout@v4 + with: + repository: testsmith-io/practice-software-testing/ + path: practice-repo + + - name: Start Practice Software Testing with Docker Compose + working-directory: practice-repo + run: docker compose up -d + - name: Install Chrome uses: browser-actions/setup-chrome@latest diff --git a/.gitignore b/.gitignore index af27779..73f7c40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ target/ .idea/ +/screenshots/ ### VS Code ### .vscode/ diff --git a/UI/package-lock.json b/UI/package-lock.json new file mode 100644 index 0000000..4ca926f --- /dev/null +++ b/UI/package-lock.json @@ -0,0 +1,6 @@ +{ + "name": "app", + "lockfileVersion": 3, + "requires": true, + "packages": {} +} diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index ec423bc..3d13aee 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -21,7 +21,7 @@ public WebDriver getDriver () { @BeforeClass public void setup () { ChromeOptions chromeOptions = new ChromeOptions (); - chromeOptions.addArguments ("--headless=new", "--no-sandbox", "--window-size=1920,1080"); + chromeOptions.addArguments ("--headless=new","--no-sandbox", "--window-size=1920,1080"); this.driver = new ChromeDriver (chromeOptions); this.driver.manage () diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index 2a725af..ded5a1a 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -23,7 +23,7 @@ public Iterator getValidRegistrationData () { @Test (dataProvider = "getValidRegistrationData") public void testRegistrationPasswordAlert (final RegistrationData registrationData) { - this.driver.get ("https://practicesoftwaretesting.com"); + this.driver.get ("https://practicesoftwaretesting.com/"); HomePage homePage = new HomePage (driver); LoginPage loginPage = homePage.navigateToLoginPage (); From 9ff541903e9ff3d3d9c233da353ad1d449fef088 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 21:53:31 +0300 Subject: [PATCH 21/29] updated website link in test to use localhost --- .../java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index ded5a1a..4e76b9e 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -23,7 +23,7 @@ public Iterator getValidRegistrationData () { @Test (dataProvider = "getValidRegistrationData") public void testRegistrationPasswordAlert (final RegistrationData registrationData) { - this.driver.get ("https://practicesoftwaretesting.com/"); + this.driver.get ("http://localhost:4200/"); HomePage homePage = new HomePage (driver); LoginPage loginPage = homePage.navigateToLoginPage (); From a2e2db0065cb6d91ccf869608fc0dc65615ffd5c Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 21:57:24 +0300 Subject: [PATCH 22/29] updated practice repo path in github actions --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 410e040..f7586dd 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -49,7 +49,7 @@ jobs: - name: Checkout Practice Software Testing repo uses: actions/checkout@v4 with: - repository: testsmith-io/practice-software-testing/ + repository: testsmith-io/practice-software-testing path: practice-repo - name: Start Practice Software Testing with Docker Compose From e853bc2bae0c92f6e57ea15dbb052b580d43e47c Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 22:24:13 +0300 Subject: [PATCH 23/29] added browser language/locale to enGB in basetest --- src/test/java/io/github/mfaisalkhatri/test/BaseTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 3d13aee..8d5b219 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -22,6 +22,7 @@ public WebDriver getDriver () { public void setup () { ChromeOptions chromeOptions = new ChromeOptions (); chromeOptions.addArguments ("--headless=new","--no-sandbox", "--window-size=1920,1080"); + chromeOptions.addArguments("--lang=en-GB"); this.driver = new ChromeDriver (chromeOptions); this.driver.manage () From 21d1cb4f05e274b30fdc446df81bb9430372576d Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 22:37:22 +0300 Subject: [PATCH 24/29] added date formatter to handle date on different OS --- .../github/mfaisalkhatri/pages/RegistrationPage.java | 11 ++++++++++- .../java/io/github/mfaisalkhatri/test/BaseTest.java | 1 - 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java index f2297c2..672f1f1 100644 --- a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java +++ b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java @@ -1,6 +1,10 @@ package io.github.mfaisalkhatri.pages; +import java.text.DateFormat; import java.time.Duration; +import java.time.format.DateTimeFormatter; +import java.util.Date; +import java.util.Locale; import io.github.mfaisalkhatri.data.RegistrationData; import org.openqa.selenium.By; @@ -27,7 +31,12 @@ public void fillRegistrationForm (final RegistrationData registrationData) { firstNameField ().sendKeys (registrationData.getFirstName ()); lastNameField ().clear (); lastNameField ().sendKeys (registrationData.getLastName ()); - dobField ().sendKeys (registrationData.getDob ()); + + Locale defaultLocale = Locale.getDefault (); + DateFormat dateFormat = DateFormat.getDateInstance (DateFormat.SHORT, defaultLocale); + String formattedDate = dateFormat.format (registrationData.getDob ()); + dobField ().sendKeys (formattedDate); + streetField ().clear (); streetField ().sendKeys (registrationData.getStreet ()); postalCodeField ().clear (); diff --git a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java index 8d5b219..3d13aee 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/BaseTest.java @@ -22,7 +22,6 @@ public WebDriver getDriver () { public void setup () { ChromeOptions chromeOptions = new ChromeOptions (); chromeOptions.addArguments ("--headless=new","--no-sandbox", "--window-size=1920,1080"); - chromeOptions.addArguments("--lang=en-GB"); this.driver = new ChromeDriver (chromeOptions); this.driver.manage () From 245bd77f5b9d58b886a125484b04f8d67f415ece Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 22:59:32 +0300 Subject: [PATCH 25/29] removed the date formatters, updated testdata json with dateformat yyyy-mm-dd --- .../io/github/mfaisalkhatri/pages/RegistrationPage.java | 7 +------ src/test/resources/testdata.json | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java index 672f1f1..66fdc45 100644 --- a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java +++ b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java @@ -31,12 +31,7 @@ public void fillRegistrationForm (final RegistrationData registrationData) { firstNameField ().sendKeys (registrationData.getFirstName ()); lastNameField ().clear (); lastNameField ().sendKeys (registrationData.getLastName ()); - - Locale defaultLocale = Locale.getDefault (); - DateFormat dateFormat = DateFormat.getDateInstance (DateFormat.SHORT, defaultLocale); - String formattedDate = dateFormat.format (registrationData.getDob ()); - dobField ().sendKeys (formattedDate); - + dobField ().sendKeys (registrationData.getDob ()); streetField ().clear (); streetField ().sendKeys (registrationData.getStreet ()); postalCodeField ().clear (); diff --git a/src/test/resources/testdata.json b/src/test/resources/testdata.json index 195a994..92e11e9 100644 --- a/src/test/resources/testdata.json +++ b/src/test/resources/testdata.json @@ -3,7 +3,7 @@ { "firstName": "Jason", "lastName": "Langer", - "dob": "01/04/1987", + "dob": "1987-04-01", "street": "11/2, Fort Street", "postalCode": "113445", "city": "California", @@ -17,7 +17,7 @@ { "firstName": "Michael", "lastName": "Justin", - "dob": "23/07/1981", + "dob": "1981-07-23", "street": "21/4, Dallas Street", "postalCode": "12976", "city": "California", From c4cdc9f0243071922ee92474da5b38b36ec26585 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sat, 28 Jun 2025 23:22:15 +0300 Subject: [PATCH 26/29] added code to take screenshot after navigating to registration page --- .../mfaisalkhatri/pages/RegistrationPage.java | 4 ---- .../test/JsonDataProviderTest.java | 19 +++++++++++++++++++ .../utils/ScreenshotListener.java | 3 +-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java index 66fdc45..f2297c2 100644 --- a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java +++ b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java @@ -1,10 +1,6 @@ package io.github.mfaisalkhatri.pages; -import java.text.DateFormat; import java.time.Duration; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.Locale; import io.github.mfaisalkhatri.data.RegistrationData; import org.openqa.selenium.By; diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index 4e76b9e..0b1fc63 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -2,6 +2,12 @@ import static org.testng.Assert.assertEquals; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Iterator; import io.github.mfaisalkhatri.data.RegistrationData; @@ -9,6 +15,8 @@ import io.github.mfaisalkhatri.pages.HomePage; import io.github.mfaisalkhatri.pages.LoginPage; import io.github.mfaisalkhatri.pages.RegistrationPage; +import org.openqa.selenium.OutputType; +import org.openqa.selenium.TakesScreenshot; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -29,6 +37,17 @@ public void testRegistrationPasswordAlert (final RegistrationData registrationDa LoginPage loginPage = homePage.navigateToLoginPage (); RegistrationPage registrationPage = loginPage.navigateToRegistrationPage (); + String timestamp = new SimpleDateFormat ("yyyyMMdd_HHmmss_SSS").format (new Date ()); + + File screenshot = ((TakesScreenshot) driver).getScreenshotAs (OutputType.FILE); + String filename = timestamp + ".png"; + try { + Files.createDirectories (Paths.get ("screenshots")); + Files.copy (screenshot.toPath (), Paths.get ("screenshots", filename)); + } catch (IOException e) { + throw new RuntimeException (e); + } + assertEquals (registrationPage.pageHeader (), "Customer registration"); registrationPage.fillRegistrationForm (registrationData); diff --git a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java index 184349d..b16ce3c 100644 --- a/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java +++ b/src/test/java/io/github/mfaisalkhatri/utils/ScreenshotListener.java @@ -20,7 +20,6 @@ public void onTestFailure (final ITestResult result) { WebDriver driver = ((WebDriverProvider) testClass).getDriver (); String timestamp = new SimpleDateFormat ("yyyyMMdd_HHmmss_SSS").format (new Date ()); - if (driver != null) { String testName = result.getMethod () .getMethodName (); @@ -28,7 +27,7 @@ public void onTestFailure (final ITestResult result) { String filename = timestamp + ".png"; try { Files.createDirectories (Paths.get ("screenshots")); - Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName+"_"+filename)); + Files.copy (screenshot.toPath (), Paths.get ("screenshots", testName + "_" + filename)); } catch (IOException e) { throw new RuntimeException (e); } From 6967c5bd6ca7db01c9ab7ad41aca0858b830f8ab Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sun, 29 Jun 2025 19:49:11 +0300 Subject: [PATCH 27/29] updated dateformat to handle it in the github actions workflow --- .../mfaisalkhatri/pages/RegistrationPage.java | 15 ++++++++++++++- .../mfaisalkhatri/test/JsonDataProviderTest.java | 3 ++- src/test/resources/testdata.json | 4 ++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java index f2297c2..89a8433 100644 --- a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java +++ b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java @@ -1,6 +1,10 @@ package io.github.mfaisalkhatri.pages; import java.time.Duration; +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; +import java.time.format.FormatStyle; +import java.util.Locale; import io.github.mfaisalkhatri.data.RegistrationData; import org.openqa.selenium.By; @@ -27,7 +31,7 @@ public void fillRegistrationForm (final RegistrationData registrationData) { firstNameField ().sendKeys (registrationData.getFirstName ()); lastNameField ().clear (); lastNameField ().sendKeys (registrationData.getLastName ()); - dobField ().sendKeys (registrationData.getDob ()); + dobField ().sendKeys (dateOfBirth (registrationData.getDob ())); streetField ().clear (); streetField ().sendKeys (registrationData.getStreet ()); postalCodeField ().clear (); @@ -107,4 +111,13 @@ private WebElement stateField () { private WebElement streetField () { return this.driver.findElement (By.id ("street")); } + + private String dateOfBirth (String jsonDate) { + + DateTimeFormatter inputFormat = DateTimeFormatter.ofPattern ("dd/MM/yyyy"); + LocalDate date = LocalDate.parse (jsonDate, inputFormat); + + DateTimeFormatter outputFormat = DateTimeFormatter.ofPattern ("MM/dd/yyyy"); + return date.format (outputFormat); + } } diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index 0b1fc63..e7185e2 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -31,7 +31,8 @@ public Iterator getValidRegistrationData () { @Test (dataProvider = "getValidRegistrationData") public void testRegistrationPasswordAlert (final RegistrationData registrationData) { - this.driver.get ("http://localhost:4200/"); + //this.driver.get ("http://localhost:4200/"); + this.driver.get ("https://practicesoftwaretesting.com/auth/register"); HomePage homePage = new HomePage (driver); LoginPage loginPage = homePage.navigateToLoginPage (); diff --git a/src/test/resources/testdata.json b/src/test/resources/testdata.json index 92e11e9..49beac3 100644 --- a/src/test/resources/testdata.json +++ b/src/test/resources/testdata.json @@ -3,7 +3,7 @@ { "firstName": "Jason", "lastName": "Langer", - "dob": "1987-04-01", + "dob": "17/05/1987", "street": "11/2, Fort Street", "postalCode": "113445", "city": "California", @@ -17,7 +17,7 @@ { "firstName": "Michael", "lastName": "Justin", - "dob": "1981-07-23", + "dob": "23/07/1985", "street": "21/4, Dallas Street", "postalCode": "12976", "city": "California", From f9db2aafdb3fe98569fba4c74507a55b6662d084 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sun, 29 Jun 2025 19:57:10 +0300 Subject: [PATCH 28/29] updated website link to run using docker --- .../io/github/mfaisalkhatri/test/JsonDataProviderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index e7185e2..f460891 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -31,8 +31,8 @@ public Iterator getValidRegistrationData () { @Test (dataProvider = "getValidRegistrationData") public void testRegistrationPasswordAlert (final RegistrationData registrationData) { - //this.driver.get ("http://localhost:4200/"); - this.driver.get ("https://practicesoftwaretesting.com/auth/register"); + this.driver.get ("http://localhost:4200/"); + //this.driver.get ("https://practicesoftwaretesting.com/auth/register"); HomePage homePage = new HomePage (driver); LoginPage loginPage = homePage.navigateToLoginPage (); From 54678d72113cd21daaf0c9d800e4a3a64e18eeb2 Mon Sep 17 00:00:00 2001 From: "mohammadfaisalkhatri@gmail.com" Date: Sun, 29 Jun 2025 20:31:02 +0300 Subject: [PATCH 29/29] disabled maven workflow --- .github/workflows/{maven.yml => disabled_maven.yml} | 0 .../java/io/github/mfaisalkhatri/pages/RegistrationPage.java | 2 -- .../io/github/mfaisalkhatri/test/JsonDataProviderTest.java | 4 ++-- 3 files changed, 2 insertions(+), 4 deletions(-) rename .github/workflows/{maven.yml => disabled_maven.yml} (100%) diff --git a/.github/workflows/maven.yml b/.github/workflows/disabled_maven.yml similarity index 100% rename from .github/workflows/maven.yml rename to .github/workflows/disabled_maven.yml diff --git a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java index 89a8433..2340321 100644 --- a/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java +++ b/src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java @@ -3,8 +3,6 @@ import java.time.Duration; import java.time.LocalDate; import java.time.format.DateTimeFormatter; -import java.time.format.FormatStyle; -import java.util.Locale; import io.github.mfaisalkhatri.data.RegistrationData; import org.openqa.selenium.By; diff --git a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java index f460891..e7185e2 100644 --- a/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java +++ b/src/test/java/io/github/mfaisalkhatri/test/JsonDataProviderTest.java @@ -31,8 +31,8 @@ public Iterator getValidRegistrationData () { @Test (dataProvider = "getValidRegistrationData") public void testRegistrationPasswordAlert (final RegistrationData registrationData) { - this.driver.get ("http://localhost:4200/"); - //this.driver.get ("https://practicesoftwaretesting.com/auth/register"); + //this.driver.get ("http://localhost:4200/"); + this.driver.get ("https://practicesoftwaretesting.com/auth/register"); HomePage homePage = new HomePage (driver); LoginPage loginPage = homePage.navigateToLoginPage ();