Skip to content

Commit

Permalink
Refactored Juice Shop tests, reformatted all page object and test cla…
Browse files Browse the repository at this point in the history
…sses (#124)

* added new class with refactored kjuice shop tests

* formatting changes for src/main folder files

* formatting changes and refactoring done for page object classes

* formatting changes and refactoring done for tests, removed warnings and redundant code

* test order changed for form authentication tests

* test order changed for form authentication tests in selenium grid testng xml

* fixed code smell in the utility helper class
  • Loading branch information
mfaisalkhatri authored Aug 28, 2023
1 parent 2591292 commit 1b5b8e8
Show file tree
Hide file tree
Showing 86 changed files with 574 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Created By Faisal Khatri on 21-03-2022
*/
@Builder
public class DevToolsManager {
public final class DevToolsManager {

private static final Logger LOG = LogManager.getLogger("DevToolsSetup.class");
private static ChromeDriver chromeDriver;
Expand All @@ -25,7 +25,7 @@ public static void createDriver() {
Objects.requireNonNullElse(System.getProperty("headless"), "true"));
WebDriverManager.chromedriver()
.setup();
ChromeOptions options = new ChromeOptions();
final ChromeOptions options = new ChromeOptions();
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("--window-size=1050,600");
Expand All @@ -35,7 +35,7 @@ public static void createDriver() {
options.addArguments("--safebrowsing-disable-download-protection");

chromeDriver = new ChromeDriver(options);
DevTools chromeDevTools = chromeDriver.getDevTools();
final DevTools chromeDevTools = chromeDriver.getDevTools();
chromeDevTools.createSession();
chromeDevTools.send(Log.enable());
chromeDevTools.addListener(Log.entryAdded(), logEntry -> {
Expand All @@ -53,4 +53,8 @@ public static void quitDriver() {
chromeDriver.quit();
}
}

private DevToolsManager() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* @author Faisal Khatri
* @since 24/07/2022
*/
public class DriverManager {
public final class DriverManager {
private static final ThreadLocal<WebDriver> DRIVER = new ThreadLocal<> ();
private static final String GRID_URL = "@hub.lambdatest.com/wd/hub";
private static final String HUB_URL = "http://localhost:4444/wd/hub";
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/io/github/mfaisalkhatri/utilities/Helper.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@
import org.apache.logging.log4j.Logger;
import org.openqa.selenium.WebElement;

public class Helper {
public final class Helper {

private static final Logger LOG = LogManager.getLogger (Helper.class);

public static void enterText (WebElement element, String text) {
public static void enterText (final WebElement element, final String text) {
element.click ();
element.clear ();
element.sendKeys (text);
}

public static void pause (long timeInMillis) throws InterruptedException {
LOG.info ("Pausing the driver for " + timeInMillis + " ms");
public static void pause (final long timeInMillis) throws InterruptedException {
Thread.sleep (timeInMillis);
}

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/io/github/mfaisalkhatri/data/juiceshop/UserData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.mfaisalkhatri.data.juiceshop;


import lombok.Builder;
import lombok.Getter;

@Builder
@Getter
public final class UserData {

private String name;
private String email;
private String pass;
private int mobileNumber;
private String address;
private String city;
private String state;
private String zipcode;
private String country;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.github.mfaisalkhatri.data.juiceshop;

import net.datafaker.Faker;

public final class UserDataBuilder {

public static UserData getUserData() {

final Faker faker = new Faker();
return UserData.builder().name(faker.name()
.fullName()).email(faker.internet()
.emailAddress()).pass(faker.internet()
.password(6, 12)).mobileNumber(faker.number()
.numberBetween(99900000, 99988888)).address(faker.address()
.streetAddress()).city(faker.address()
.city()).state(faker.address()
.state()).zipcode(faker.number()
.digits(6)).country(faker.address()
.country()).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mfaisalkhatri.data;
package io.github.mfaisalkhatri.data.lambdatestecommerce;

import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.mfaisalkhatri.data;
package io.github.mfaisalkhatri.data.lambdatestecommerce;

import lombok.Builder;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package io.github.mfaisalkhatri.data;
package io.github.mfaisalkhatri.data.lambdatestecommerce;


import net.datafaker.Faker;

/**
* Created By Faisal Khatri on 25-07-2022
*/
public class TestDataBuilder {
public final class TestDataBuilder {

private static final Faker FAKER = new Faker();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.mfaisalkhatri.listeners;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import org.testng.IAnnotationTransformer;
import org.testng.annotations.ITestAnnotation;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

/**
* @author Faisal Khatri
* @since 11/2/2022
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public String getProductPriceUsingXpath () {
.getText ();
}

public void searchProduct (String product) {
public void searchProduct (final String product) {

getDriver ().findElement (By.id ("twotabsearchtextbox"))
.sendKeys (product);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

package io.github.mfaisalkhatri.pages.automationpractice;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.with;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.with;

/**
* Created By Faisal Khatri on 09-12-2021
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

package io.github.mfaisalkhatri.pages.automationpractice;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.with;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static org.openqa.selenium.support.locators.RelativeLocator.with;

/**
* Created By Faisal Khatri on 09-12-2021
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.mfaisalkhatri.pages.bstack;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

/**
* @author Faisal Khatri
* @since 12/27/2022
Expand All @@ -17,13 +17,13 @@ public String getPasswordText () {
}

public void openPasswordDropdown () {
WebElement dropdown = getDriver ().findElement (By.cssSelector ("#password > div > div.css-1wy0on6 > div"));
final WebElement dropdown = getDriver ().findElement (By.cssSelector ("#password > div > div.css-1wy0on6 > div"));
dropdown.click ();

}

public void selectAutofillPasswordText () {
WebElement autoFillPasswordValue = getDriver ().findElement (By.cssSelector (
final WebElement autoFillPasswordValue = getDriver ().findElement (By.cssSelector (
"#password > div.css-26l3qy-menu > div > div > div:nth-child(2) #react-select-3-option-0-0"));
autoFillPasswordValue.click ();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@

package io.github.mfaisalkhatri.pages.crossbrowsertesting;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

/**
* Created By Faisal Khatri on 30-12-2021
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@

package io.github.mfaisalkhatri.pages.demoqa;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

/**
* Created By Faisal Khatri on 30-12-2021
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.mfaisalkhatri.pages.geolocation;

import static io.github.mfaisalkhatri.drivers.DevToolsManager.getDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static io.github.mfaisalkhatri.drivers.DevToolsManager.getDriver;

/**
* @author Faisal Khatri
* @since 1/30/2023
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.github.mfaisalkhatri.pages.juiceshop;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

/**
* Created By Faisal Khatri on 18-04-2022
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.mfaisalkhatri.pages.juiceshop;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static io.github.mfaisalkhatri.utilities.Helper.enterText;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.time.Duration;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static io.github.mfaisalkhatri.utilities.Helper.enterText;

/**
* Created By Faisal Khatri on 17-04-2022
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.mfaisalkhatri.pages.juiceshop;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.time.Duration;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

/**
* Created By Faisal Khatri on 18-04-2022
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package io.github.mfaisalkhatri.pages.juiceshop;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static io.github.mfaisalkhatri.utilities.Helper.enterText;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;
import static io.github.mfaisalkhatri.utilities.Helper.enterText;

public class LoginPage {

public WebElement logOutLink () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.mfaisalkhatri.pages.juiceshop;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.time.Duration;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

public class MainPage {

public WebElement accountLink () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.mfaisalkhatri.pages.juiceshop;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import org.openqa.selenium.By;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

/**
* Created By Faisal Khatri on 19-04-2022
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package io.github.mfaisalkhatri.pages.juiceshop;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

import java.time.Duration;

import static io.github.mfaisalkhatri.drivers.DriverManager.getDriver;

/**
* Created By Faisal Khatri on 19-04-2022
*/
Expand Down
Loading

0 comments on commit 1b5b8e8

Please sign in to comment.