From b8e6ff8eddeea75b6fdedd90f4d32847853c7f2b Mon Sep 17 00:00:00 2001 From: Marcus Merrell Date: Tue, 5 Sep 2023 16:54:35 -0700 Subject: [PATCH] Creating configs to be able to run on all browsers, concurrently --- .../src/test/java/com/example/TestUtils.java | 1 + .../test/java/org/example/BaselineTest.java | 4 ++ .../src/test/java/org/example/DiffTest.java | 13 +++++ .../java/org/example/IgnoreRegionTest.java | 13 +++++ .../{NavigateTest.java => ParallelTest.java} | 40 +++++++------- .../java/org/example/SauceVisualBaseTest.java | 8 +-- .../java/org/example/config/ChromeTests.java | 11 ++++ .../java/org/example/config/EdgeTests.java | 11 ++++ .../java/org/example/config/FirefoxTests.java | 9 ++++ .../java/org/example/config/SafariTests.java | 11 ++++ .../org/example/pageobjects/AccountPage.java | 27 ++++++++++ .../org/example/pageobjects/BasePage.java | 13 +++-- .../org/example/pageobjects/ContactPage.java | 21 ++++++++ .../example/pageobjects/DashboardPage.java | 33 ++++++++++++ .../org/example/pageobjects/HomePage.java | 29 ++++++++++- .../org/example/pageobjects/LoginPage.java | 52 ++++++++++++++++--- 16 files changed, 255 insertions(+), 41 deletions(-) create mode 100644 wd-sauce-bindings/src/test/java/org/example/BaselineTest.java create mode 100644 wd-sauce-bindings/src/test/java/org/example/DiffTest.java create mode 100644 wd-sauce-bindings/src/test/java/org/example/IgnoreRegionTest.java rename wd-sauce-bindings/src/test/java/org/example/{NavigateTest.java => ParallelTest.java} (75%) create mode 100644 wd-sauce-bindings/src/test/java/org/example/config/ChromeTests.java create mode 100644 wd-sauce-bindings/src/test/java/org/example/config/EdgeTests.java create mode 100644 wd-sauce-bindings/src/test/java/org/example/config/FirefoxTests.java create mode 100644 wd-sauce-bindings/src/test/java/org/example/config/SafariTests.java create mode 100644 wd-sauce-bindings/src/test/java/org/example/pageobjects/AccountPage.java create mode 100644 wd-sauce-bindings/src/test/java/org/example/pageobjects/DashboardPage.java diff --git a/wd-java/src/test/java/com/example/TestUtils.java b/wd-java/src/test/java/com/example/TestUtils.java index c16faa2b..af87be21 100644 --- a/wd-java/src/test/java/com/example/TestUtils.java +++ b/wd-java/src/test/java/com/example/TestUtils.java @@ -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); } } diff --git a/wd-sauce-bindings/src/test/java/org/example/BaselineTest.java b/wd-sauce-bindings/src/test/java/org/example/BaselineTest.java new file mode 100644 index 00000000..139142bf --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/BaselineTest.java @@ -0,0 +1,4 @@ +package org.example; + +public class BaselineTest { +} diff --git a/wd-sauce-bindings/src/test/java/org/example/DiffTest.java b/wd-sauce-bindings/src/test/java/org/example/DiffTest.java new file mode 100644 index 00000000..849906b3 --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/DiffTest.java @@ -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"); + } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/IgnoreRegionTest.java b/wd-sauce-bindings/src/test/java/org/example/IgnoreRegionTest.java new file mode 100644 index 00000000..78b30c18 --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/IgnoreRegionTest.java @@ -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); + } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/NavigateTest.java b/wd-sauce-bindings/src/test/java/org/example/ParallelTest.java similarity index 75% rename from wd-sauce-bindings/src/test/java/org/example/NavigateTest.java rename to wd-sauce-bindings/src/test/java/org/example/ParallelTest.java index c3ff9b9f..97d2faef 100644 --- a/wd-sauce-bindings/src/test/java/org/example/NavigateTest.java +++ b/wd-sauce-bindings/src/test/java/org/example/ParallelTest.java @@ -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 = "admin@practicesoftwaretesting.com"; - private final String customerLogin = "customer@practicesoftwaretesting.com"; - private final String customer2Login = "customer2@practicesoftwaretesting.com"; - 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); } } diff --git a/wd-sauce-bindings/src/test/java/org/example/SauceVisualBaseTest.java b/wd-sauce-bindings/src/test/java/org/example/SauceVisualBaseTest.java index 75c5f12e..b7346bdb 100644 --- a/wd-sauce-bindings/src/test/java/org/example/SauceVisualBaseTest.java +++ b/wd-sauce-bindings/src/test/java/org/example/SauceVisualBaseTest.java @@ -14,6 +14,7 @@ @Execution(ExecutionMode.CONCURRENT) public class SauceVisualBaseTest extends SauceBaseTest { protected static ThreadLocal threadLocalVisual = ThreadLocal.withInitial(() -> null); + protected HomePage homePage; @BeforeEach @@ -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(); diff --git a/wd-sauce-bindings/src/test/java/org/example/config/ChromeTests.java b/wd-sauce-bindings/src/test/java/org/example/config/ChromeTests.java new file mode 100644 index 00000000..3239a69f --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/config/ChromeTests.java @@ -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(); + } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/config/EdgeTests.java b/wd-sauce-bindings/src/test/java/org/example/config/EdgeTests.java new file mode 100644 index 00000000..f2a61b64 --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/config/EdgeTests.java @@ -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(); + } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/config/FirefoxTests.java b/wd-sauce-bindings/src/test/java/org/example/config/FirefoxTests.java new file mode 100644 index 00000000..0bd3ae2c --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/config/FirefoxTests.java @@ -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(); } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/config/SafariTests.java b/wd-sauce-bindings/src/test/java/org/example/config/SafariTests.java new file mode 100644 index 00000000..50d0bcce --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/config/SafariTests.java @@ -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(); + } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/pageobjects/AccountPage.java b/wd-sauce-bindings/src/test/java/org/example/pageobjects/AccountPage.java new file mode 100644 index 00000000..60c9ed5b --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/pageobjects/AccountPage.java @@ -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 getIgnoreRegions() { + return null; + } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/pageobjects/BasePage.java b/wd-sauce-bindings/src/test/java/org/example/pageobjects/BasePage.java index 5287f193..1ea25aac 100644 --- a/wd-sauce-bindings/src/test/java/org/example/pageobjects/BasePage.java +++ b/wd-sauce-bindings/src/test/java/org/example/pageobjects/BasePage.java @@ -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; @@ -14,15 +15,19 @@ public abstract class BasePage { protected abstract String getUrlPath(); + protected abstract void sync(); + + public abstract List 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) { @@ -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; } } diff --git a/wd-sauce-bindings/src/test/java/org/example/pageobjects/ContactPage.java b/wd-sauce-bindings/src/test/java/org/example/pageobjects/ContactPage.java index 5e78eb7e..02717671 100644 --- a/wd-sauce-bindings/src/test/java/org/example/pageobjects/ContactPage.java +++ b/wd-sauce-bindings/src/test/java/org/example/pageobjects/ContactPage.java @@ -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 getIgnoreRegions() { + return null; + } + public ContactPage(WebDriver driver) { super(driver); } diff --git a/wd-sauce-bindings/src/test/java/org/example/pageobjects/DashboardPage.java b/wd-sauce-bindings/src/test/java/org/example/pageobjects/DashboardPage.java new file mode 100644 index 00000000..f2cf745a --- /dev/null +++ b/wd-sauce-bindings/src/test/java/org/example/pageobjects/DashboardPage.java @@ -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 getIgnoreRegions() { + return driver.findElements(By.cssSelector(".chartjs-render-monitor")); + } +} diff --git a/wd-sauce-bindings/src/test/java/org/example/pageobjects/HomePage.java b/wd-sauce-bindings/src/test/java/org/example/pageobjects/HomePage.java index 546b1fcf..7f38bd51 100644 --- a/wd-sauce-bindings/src/test/java/org/example/pageobjects/HomePage.java +++ b/wd-sauce-bindings/src/test/java/org/example/pageobjects/HomePage.java @@ -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 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; } } diff --git a/wd-sauce-bindings/src/test/java/org/example/pageobjects/LoginPage.java b/wd-sauce-bindings/src/test/java/org/example/pageobjects/LoginPage.java index 50de5b38..c36ab7f2 100644 --- a/wd-sauce-bindings/src/test/java/org/example/pageobjects/LoginPage.java +++ b/wd-sauce-bindings/src/test/java/org/example/pageobjects/LoginPage.java @@ -4,13 +4,13 @@ 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; -public class LoginPage extends BasePage { - - public LoginPage(WebDriver driver) { super(driver); } +import java.time.Duration; +import java.util.List; - @Override - protected String getUrlPath() { return "auth/login"; } +public class LoginPage extends BasePage { @Getter private final By usernameInput = By.cssSelector("input[data-test=\"email\"]"); @@ -21,9 +21,45 @@ public class LoginPage extends BasePage { @Getter private final By submitBtn = By.cssSelector("input[data-test=\"login-submit\"]"); - public void login(String username, String password) { + public LoginPage(WebDriver driver) { super(driver); } + + @Override + protected String getUrlPath() { return "auth/login"; } + + @Override + protected void sync() { + WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); + wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(submitBtn)); + } + + @Override + public List getIgnoreRegions() { + return null; + } + + public DashboardPage loginAdmin() { + driver.findElement(usernameInput).sendKeys("admin@practicesoftwaretesting.com"); + driver.findElement(passwordInput).sendKeys("welcome01"); + driver.findElement(submitBtn).click(); + DashboardPage dashboardPage = new DashboardPage(driver); + dashboardPage.sync(); + return dashboardPage; + } + + public AccountPage loginCustomer() { + driver.findElement(usernameInput).sendKeys("customer@practicesoftwaretesting.com"); + driver.findElement(passwordInput).sendKeys("welcome01"); + driver.findElement(submitBtn).click(); + AccountPage accountPage = new AccountPage(driver); + accountPage.sync(); + return accountPage; + } + + public AccountPage login(String username, String password) { driver.findElement(usernameInput).sendKeys(username); driver.findElement(passwordInput).sendKeys(password); driver.findElement(submitBtn).click(); - } -} + AccountPage accountPage = new AccountPage(driver); + accountPage.sync(); + return accountPage; + }}