Skip to content

Commit

Permalink
Creating configs to be able to run on all browsers, concurrently
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerrell committed Sep 5, 2023
1 parent ac58caa commit b8e6ff8
Show file tree
Hide file tree
Showing 16 changed files with 255 additions and 41 deletions.
1 change: 1 addition & 0 deletions wd-java/src/test/java/com/example/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ static RemoteWebDriver getWebDriver(String username, String accessKey) throws Ma
DesiredCapabilities caps = new DesiredCapabilities();
caps.setBrowserName("chrome");


return new RemoteWebDriver(new URL(webDriverUrl), caps);
}
}
4 changes: 4 additions & 0 deletions wd-sauce-bindings/src/test/java/org/example/BaselineTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package org.example;

public class BaselineTest {
}
13 changes: 13 additions & 0 deletions wd-sauce-bindings/src/test/java/org/example/DiffTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.example;

import org.junit.jupiter.api.Test;

public class DiffTest extends SauceVisualBaseTest {

@Test
public void forceDiff() {
homePage.setWithBugs(true);
homePage.open();
visual().check("DiffTest - Before Login");
}
}
13 changes: 13 additions & 0 deletions wd-sauce-bindings/src/test/java/org/example/IgnoreRegionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.example;

import com.saucelabs.visual.Options;
import org.junit.jupiter.api.Test;

public class IgnoreRegionTest extends SauceVisualBaseTest {
@Test
void checkHomePage() {
Options options = new Options();
options.setIgnoreElements(driver.findElements(homePage.getLogoLink()));
visual().check("IgnoreRegionTest - Home Page", options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,47 @@

import com.saucelabs.visual.Options;
import org.example.pageobjects.ContactPage;
import org.example.pageobjects.DashboardPage;
import org.example.pageobjects.LoginPage;
import org.junit.jupiter.api.Test;

public class NavigateTest extends SauceVisualBaseTest {

private final String adminLogin = "[email protected]";
private final String customerLogin = "[email protected]";
private final String customer2Login = "[email protected]";
private final String password = "welcome01";

public class ParallelTest extends SauceVisualBaseTest {
@Test
void checkLoginPage() {
void checkHomePage() {
Options options = new Options();
options.setIgnoreElements(driver.findElements(homePage.getLogoLink()));
visual().check("Home Page - Before Login", options);
LoginPage loginPage = homePage.navigateToLogin();
loginPage.login(adminLogin, password);

visual().check("After Login", options);
visual().check("Initial Home Page", options);
}

@Test
void checkContactPage() {
void checkReturnToHomePage() {
Options options = new Options();
options.setIgnoreElements(driver.findElements(homePage.getLogoLink()));
visual().check("Home Page", options);
visual().check("Home Page Before", options);
ContactPage contactPage = homePage.navigateToContactPage();
visual().check("Contact Page", options);
contactPage.navigateToHome();
visual().check("Contact Page After", options);
}

@Test
void checkReturnToHomePage() {
void checkDashboardPage() {
Options options = new Options();
options.setIgnoreElements(driver.findElements(homePage.getLogoLink()));
visual().check("Home Page Before", options);
ContactPage contactPage = homePage.navigateToContactPage();
visual().check("Contact Page", options);
contactPage.navigateToHome();
visual().check("Contact Page After", options);
visual().check("Home Page - Before Login", options);
LoginPage loginPage = homePage.navigateToLogin();
DashboardPage dashboardPage = loginPage.loginAdmin();
options.setIgnoreElements(dashboardPage.getIgnoreRegions());
visual().check("Dashboard Page", options);
}

@Test
void checkHomePage() {
void checkContactPage() {
Options options = new Options();
options.setIgnoreElements(driver.findElements(homePage.getLogoLink()));
visual().check("Initial Home Page", options);
visual().check("Home Page", options);
ContactPage contactPage = homePage.navigateToContactPage();
visual().check("Contact Page", options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@Execution(ExecutionMode.CONCURRENT)
public class SauceVisualBaseTest extends SauceBaseTest {
protected static ThreadLocal<VisualApi> threadLocalVisual = ThreadLocal.withInitial(() -> null);

protected HomePage homePage;

@BeforeEach
Expand All @@ -27,18 +28,13 @@ public void init() {

homePage = new HomePage(driver);
homePage.open();
homePage.sync();
}

protected VisualApi visual() {
return threadLocalVisual.get();
}

@BeforeEach
public void initTest() {
homePage = new HomePage(driver);
homePage.open();
}

@Override
public SauceOptions createSauceOptions() {
return SauceOptions.chrome().build();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.example.config;

import com.saucelabs.saucebindings.options.SauceOptions;
import org.example.ParallelTest;

public class ChromeTests extends ParallelTest {
@Override
public SauceOptions createSauceOptions() {
return SauceOptions.chrome().build();
}
}
11 changes: 11 additions & 0 deletions wd-sauce-bindings/src/test/java/org/example/config/EdgeTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.example.config;

import com.saucelabs.saucebindings.options.SauceOptions;
import org.example.ParallelTest;

public class EdgeTests extends ParallelTest {
@Override
public SauceOptions createSauceOptions() {
return SauceOptions.edge().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.example.config;

import com.saucelabs.saucebindings.options.SauceOptions;
import org.example.ParallelTest;

public class FirefoxTests extends ParallelTest {
@Override
public SauceOptions createSauceOptions() { return SauceOptions.firefox().build(); }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.example.config;

import com.saucelabs.saucebindings.options.SauceOptions;
import org.example.ParallelTest;

public class SafariTests extends ParallelTest {
@Override
public SauceOptions createSauceOptions() {
return SauceOptions.safari().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.example.pageobjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import java.util.List;

public class AccountPage extends BasePage {
public AccountPage(WebDriver driver) {
super(driver);
}

@Override
protected String getUrlPath() {
return "account";
}

@Override
protected void sync() {

}

@Override
public List<WebElement> getIgnoreRegions() {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import java.util.List;

public abstract class BasePage {
protected final WebDriver driver;
Expand All @@ -14,15 +15,19 @@ public abstract class BasePage {

protected abstract String getUrlPath();

protected abstract void sync();

public abstract List<WebElement> getIgnoreRegions();

public BasePage(WebDriver driver) {
this.driver = driver;
}

@Setter
private boolean with_bugs = false;
private boolean withBugs = false;

public void open() {
driver.get(getFullUrl(with_bugs));
driver.get(getFullUrl(withBugs));
}

protected String getFullUrl(boolean debug) {
Expand All @@ -33,6 +38,8 @@ protected String getFullUrl(boolean debug) {
public HomePage navigateToHome() {
WebElement home = driver.findElement(homeLink);
home.click();
return new HomePage(driver);
HomePage homePage = new HomePage(driver);
homePage.sync();
return homePage;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
package org.example.pageobjects;

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.WebDriverWait;

import java.time.Duration;
import java.util.List;

public class ContactPage extends BasePage {

private final By submitBtn = By.cssSelector("input[data-test=\"contact-submit\"]");

@Override
protected String getUrlPath() { return "contact"; }

@Override
protected void sync() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); // 10 is the timeout in seconds
wait.until(ExpectedConditions.presenceOfElementLocated(submitBtn));
}

@Override
public List<WebElement> getIgnoreRegions() {
return null;
}

public ContactPage(WebDriver driver) {
super(driver);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.example.pageobjects;

import lombok.val;
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.WebDriverWait;

import java.time.Duration;
import java.util.List;

public class DashboardPage extends BasePage {
public DashboardPage(WebDriver driver) {
super(driver);
}

@Override
protected String getUrlPath() {
return "admin/dashboard";
}

@Override
protected void sync() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.cssSelector(".chartjs-render-monitor")));
}

@Override
public List<WebElement> getIgnoreRegions() {
return driver.findElements(By.cssSelector(".chartjs-render-monitor"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,53 @@
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.WebDriverWait;

import java.time.Duration;
import java.util.List;

public class HomePage extends BasePage {
@Override
protected String getUrlPath() { return ""; }


@Getter
private final By contactLink = By.cssSelector("a[data-test=\"nav-contact\"]");
@Getter
private final By signInLink = By.cssSelector("a[data-test=\"nav-sign-in\"]");
@Getter
private final By logoLink = By.id("Layer_1");

private final By firstCard = By.cssSelector(".card-img-top:first-child");

@Override
public void sync() {
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(ExpectedConditions.presenceOfElementLocated(firstCard));
}

@Override
public List<WebElement> getIgnoreRegions() {
return null;
}

public HomePage(WebDriver driver) { super(driver); }

public LoginPage navigateToLogin() {
WebElement signIn = driver.findElement(signInLink);
signIn.click();
return new LoginPage(driver);
LoginPage loginPage = new LoginPage(driver);
loginPage.sync();
return loginPage;
}

public ContactPage navigateToContactPage() {
WebElement contact = driver.findElement(contactLink);
contact.click();
return new ContactPage(driver);
ContactPage contactPage = new ContactPage(driver);
contactPage.sync();
return contactPage;
}
}
Loading

0 comments on commit b8e6ff8

Please sign in to comment.