Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
caf0305
added github actions workflow for maven
mfaisalkhatri Jun 28, 2025
3d63108
added dependabot yml for weekly version update check
mfaisalkhatri Jun 28, 2025
3fdebc7
added steps to install Java, Maven and Chrome browser before running …
mfaisalkhatri Jun 28, 2025
6f59c05
added chromeoptions to run tests in headless mode
mfaisalkhatri Jun 28, 2025
3f34e70
added chromOptions in chromedriver
mfaisalkhatri Jun 28, 2025
d5a3192
added window size chrome options for github actions
mfaisalkhatri Jun 28, 2025
f9bee0d
removed window maximize code
mfaisalkhatri Jun 28, 2025
ac30c42
added explicit wait for locating elements
mfaisalkhatri Jun 28, 2025
24cb28e
added chromeoptions - no-sandbox and changed window size
mfaisalkhatri Jun 28, 2025
2fdc539
testng listener added to take screenshot on failure, added step to up…
mfaisalkhatri Jun 28, 2025
c9d0336
correct screensjhot upload path and formatted lines
mfaisalkhatri Jun 28, 2025
00525f3
added chrome option to use disable-link-features
mfaisalkhatri Jun 28, 2025
a21c941
updated BaseTest with automation extension arguments to handle cloudf…
mfaisalkhatri Jun 28, 2025
7100361
appended timestamp in the filename to get unique screenshot name ever…
mfaisalkhatri Jun 28, 2025
bc7aa2b
fixed screenshot filename issue
mfaisalkhatri Jun 28, 2025
5d232ec
fixed screenshot filename issue with timestamp
mfaisalkhatri Jun 28, 2025
69dd9f9
added registration page navigation steps
mfaisalkhatri Jun 28, 2025
c6c5e78
added steps to navigate to home, login and then registration page
mfaisalkhatri Jun 28, 2025
eac6b43
removed commented code to run test in headless mode
mfaisalkhatri Jun 28, 2025
1f11262
added practice software testing docker compose in github actions
mfaisalkhatri Jun 28, 2025
9ff5419
updated website link in test to use localhost
mfaisalkhatri Jun 28, 2025
a2e2db0
updated practice repo path in github actions
mfaisalkhatri Jun 28, 2025
e853bc2
added browser language/locale to enGB in basetest
mfaisalkhatri Jun 28, 2025
21d1cb4
added date formatter to handle date on different OS
mfaisalkhatri Jun 28, 2025
245bd77
removed the date formatters, updated testdata json with dateformat yy…
mfaisalkhatri Jun 28, 2025
c4cdc9f
added code to take screenshot after navigating to registration page
mfaisalkhatri Jun 28, 2025
6967c5b
updated dateformat to handle it in the github actions workflow
mfaisalkhatri Jun 29, 2025
f9db2aa
updated website link to run using docker
mfaisalkhatri Jun 29, 2025
54678d7
disabled maven workflow
mfaisalkhatri Jun 29, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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'
79 changes: 79 additions & 0 deletions .github/workflows/disabled_maven.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# 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: Install Java and Maven
uses: actions/setup-java@v4
with:
java-version: '17'
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

- 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()
with:
name: Test Results
path: ${{ github.workspace }}/target/surefire-reports/TEST-TestSuite.xml
reporter: java-junit
java-version: 17
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
target/
.idea/
/screenshots/

### VS Code ###
.vscode/
Expand Down
6 changes: 6 additions & 0 deletions UI/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<maven.compiler.version>3.13.0</maven.compiler.version>
<surefire-version>3.5.0</surefire-version>
<maven.source.encoding>UTF-8</maven.source.encoding>
<suite-xml>testng.xml</suite-xml>
<argLine>-Dfile.encoding=UTF-8 -Xdebug -Xnoagent</argLine>
</properties>
<dependencies>
<dependency>
Expand Down Expand Up @@ -76,6 +78,10 @@
<value>false</value>
</property>
</properties>
<suiteXmlFiles>
<suiteXmlFile>${suite-xml}</suiteXmlFile>
</suiteXmlFiles>
<argLine>${argLine}</argLine>
</configuration>
</plugin>
</plugins>
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/io/github/mfaisalkhatri/pages/HomePage.java
Original file line number Diff line number Diff line change
@@ -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 navigateToLoginPage() {
signInLink ().click ();
return new LoginPage (driver);

}
private WebElement signInLink() {
return this.driver.findElement (By.linkText ("Sign in"));
}


}
24 changes: 24 additions & 0 deletions src/test/java/io/github/mfaisalkhatri/pages/LoginPage.java
Original file line number Diff line number Diff line change
@@ -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);
}

}
25 changes: 22 additions & 3 deletions src/test/java/io/github/mfaisalkhatri/pages/RegistrationPage.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
package io.github.mfaisalkhatri.pages;

import java.time.Duration;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

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) {
firstNameField ().clear ();
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 ();
Expand All @@ -39,12 +49,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 ();
}

Expand Down Expand Up @@ -99,4 +109,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);
}
}
21 changes: 15 additions & 6 deletions src/test/java/io/github/mfaisalkhatri/test/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,37 @@

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 () {
this.driver = new ChromeDriver ();
this.driver.manage ()
.window ()
.maximize ();
ChromeOptions chromeOptions = new ChromeOptions ();
chromeOptions.addArguments ("--headless=new","--no-sandbox", "--window-size=1920,1080");

this.driver = new ChromeDriver (chromeOptions);
this.driver.manage ()
.timeouts ()
.implicitlyWait (Duration.ofSeconds (30));
}

@AfterClass
public void tearDown () {
this.driver.quit ();
if (driver != null) {
this.driver.quit ();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

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;
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.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

Expand All @@ -21,12 +31,27 @@ public Iterator<RegistrationData> getValidRegistrationData () {

@Test (dataProvider = "getValidRegistrationData")
public void testRegistrationPasswordAlert (final RegistrationData registrationData) {
final RegistrationPage registrationPage = new RegistrationPage (this.driver);
//this.driver.get ("http://localhost:4200/");
this.driver.get ("https://practicesoftwaretesting.com/auth/register");

HomePage homePage = new HomePage (driver);
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);

registrationPage.fillRegistrationForm (registrationData);
assertEquals (registrationPage.passwordAlertMessage (),
"The given password has appeared in a data leak. Please choose a different password.");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.github.mfaisalkhatri.utils;

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 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 ();
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 + "_" + filename));
} catch (IOException e) {
throw new RuntimeException (e);
}
}
}
}
Loading