From 08f4410f320e479d8edd3dca615e209c8908ade5 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Mon, 24 Feb 2020 15:03:00 -0500 Subject: [PATCH 01/27] remove all implementation details --- pom.xml | 7 ----- .../AcceptanceTestDrivenAutomationTest.java | 31 ------------------- src/test/java/atda/BasePage.java | 15 --------- src/test/java/atda/LoginPage.java | 27 ---------------- src/test/java/atda/ProductsPage.java | 17 ---------- 5 files changed, 97 deletions(-) delete mode 100644 src/test/java/atda/BasePage.java delete mode 100644 src/test/java/atda/LoginPage.java delete mode 100644 src/test/java/atda/ProductsPage.java diff --git a/pom.xml b/pom.xml index c609a05..cb4b986 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,6 @@ org.ultimateqa selenium.java 1.0-SNAPSHOT - @@ -34,12 +33,6 @@ - - org.seleniumhq.selenium - selenium-java - 3.141.59 - test - junit junit diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 9fecfd9..199ce63 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -1,42 +1,11 @@ package atda; -import org.junit.After; -import org.junit.Before; import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - -import static org.junit.Assert.assertTrue; public class AcceptanceTestDrivenAutomationTest { - WebDriver driver; - @Before - public void setup() - { - driver = getDriver(); - } - @After - public void cleanup() - { - driver.quit(); - } @Test public void shouldOpen() { - LoginPage loginPage = new LoginPage(driver); - loginPage.open(); - assertTrue(loginPage.isLoaded()); - } - - @Test - public void shouldLogin() - { - LoginPage loginPage = new LoginPage(driver); - loginPage.open(); - assertTrue(loginPage.isLoaded()); - - loginPage.login("standard_user", "secret_sauce"); - assertTrue(new ProductsPage(driver).isLoaded()); } private WebDriver getDriver() { diff --git a/src/test/java/atda/BasePage.java b/src/test/java/atda/BasePage.java deleted file mode 100644 index eef3e5b..0000000 --- a/src/test/java/atda/BasePage.java +++ /dev/null @@ -1,15 +0,0 @@ -package atda; - -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.WebDriverWait; - -public class BasePage { - public final WebDriver driver; - WebDriverWait wait; - - - public BasePage(WebDriver driver) { - this.driver = driver; - wait = new WebDriverWait(driver, 10); - } -} diff --git a/src/test/java/atda/LoginPage.java b/src/test/java/atda/LoginPage.java deleted file mode 100644 index b5ca59c..0000000 --- a/src/test/java/atda/LoginPage.java +++ /dev/null @@ -1,27 +0,0 @@ -package atda; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -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); - } - - public void open() { - driver.get("http://www.saucedemo.com"); - } - - public boolean isLoaded() { - return wait.until(ExpectedConditions.presenceOfElementLocated(By.id("user-name"))).isDisplayed(); - } - - public void login(String userName, String password) { - driver.findElement(By.id("user-name")).sendKeys(userName); - driver.findElement(By.id("password")).sendKeys(password); - driver.findElement(By.className("btn_action")).submit(); - } -} diff --git a/src/test/java/atda/ProductsPage.java b/src/test/java/atda/ProductsPage.java deleted file mode 100644 index b8152a6..0000000 --- a/src/test/java/atda/ProductsPage.java +++ /dev/null @@ -1,17 +0,0 @@ -package atda; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -public class ProductsPage extends BasePage{ - public ProductsPage(WebDriver driver) { - super(driver); - } - - public boolean isLoaded() { - return wait.until( - ExpectedConditions.presenceOfElementLocated(By.id("inventory_filter_container"))).isDisplayed(); - } -} From 70947184f91e0d3d28edaef91493f8cce0048f11 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Wed, 26 Feb 2020 09:32:20 -0500 Subject: [PATCH 02/27] remove parallelization --- pom.xml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index cb4b986..299432e 100644 --- a/pom.xml +++ b/pom.xml @@ -9,16 +9,16 @@ - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M4 - - all - 10 - all - - + + + + + + + + + + org.apache.maven.plugins From 2f16bf3f6d65bcbe2ecde2b865816e92b410791b Mon Sep 17 00:00:00 2001 From: nadvolod Date: Mon, 2 Mar 2020 17:54:55 -0500 Subject: [PATCH 03/27] final code --- pom.xml | 26 ++++++++------ .../AcceptanceTestDrivenAutomationTest.java | 35 +++++++++++++++++-- src/test/java/atda/BasePage.java | 18 ++++++++++ src/test/java/atda/LoginPage.java | 30 ++++++++++++++++ src/test/java/atda/ProductsPage.java | 15 ++++++++ 5 files changed, 112 insertions(+), 12 deletions(-) create mode 100644 src/test/java/atda/BasePage.java create mode 100644 src/test/java/atda/LoginPage.java create mode 100644 src/test/java/atda/ProductsPage.java diff --git a/pom.xml b/pom.xml index 299432e..be41779 100644 --- a/pom.xml +++ b/pom.xml @@ -9,16 +9,16 @@ - - - - - - - - - - + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + all + 10 + all + + org.apache.maven.plugins @@ -39,5 +39,11 @@ 4.12 test + + org.seleniumhq.selenium + selenium-java + 3.141.59 + test + \ No newline at end of file diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 199ce63..59a2815 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -1,11 +1,42 @@ package atda; +import org.junit.After; +import org.junit.Before; import org.junit.Test; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; + +import static org.junit.Assert.assertTrue; public class AcceptanceTestDrivenAutomationTest { - @Test - public void shouldOpen() + private WebDriver driver; + + @Before + public void setup() { + driver = getDriver(); + } + @After + public void teardown() + { + driver.quit(); + } + @Test + public void shouldOpen() { + LoginPage loginPage = new LoginPage(driver); + loginPage.open(); + + assertTrue("Login page should load successfully", loginPage.isLoaded()); + } + + @Test + public void shouldLogin() { + LoginPage loginPage = new LoginPage(driver); + loginPage.open(); + assertTrue("Login page should load successfully", loginPage.isLoaded()); + + loginPage.login("standard_user", "secret_sauce"); + assertTrue("Products page should open when we login", new ProductsPage(driver).isLoaded()); } private WebDriver getDriver() { diff --git a/src/test/java/atda/BasePage.java b/src/test/java/atda/BasePage.java new file mode 100644 index 0000000..bc24900 --- /dev/null +++ b/src/test/java/atda/BasePage.java @@ -0,0 +1,18 @@ +package atda; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +public class BasePage { + public final WebDriver driver; + + public BasePage(WebDriver driver) { + this.driver = driver; + } + public boolean isElementDisplayed(By locator) { + WebDriverWait wait = new WebDriverWait(driver, 10); + return wait.until(ExpectedConditions.visibilityOfElementLocated(locator)).isDisplayed(); + } +} diff --git a/src/test/java/atda/LoginPage.java b/src/test/java/atda/LoginPage.java new file mode 100644 index 0000000..2ece306 --- /dev/null +++ b/src/test/java/atda/LoginPage.java @@ -0,0 +1,30 @@ +package atda; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; +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); + } + public By getUserNameLocator() + { + return By.id("user-name"); + } + public void open() { + driver.get("https://www.saucedemo.com/"); + } + + public boolean isLoaded() { + return isElementDisplayed(getUserNameLocator()); + } + + public void login(String username, String password) { + driver.findElement(getUserNameLocator()).sendKeys(username); + driver.findElement(By.id("password")).sendKeys(password); + driver.findElement(By.className("btn_action")).click(); + } +} diff --git a/src/test/java/atda/ProductsPage.java b/src/test/java/atda/ProductsPage.java new file mode 100644 index 0000000..1ea0d54 --- /dev/null +++ b/src/test/java/atda/ProductsPage.java @@ -0,0 +1,15 @@ +package atda; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +public class ProductsPage extends BasePage{ + + public ProductsPage(WebDriver driver) { + super(driver); + } + + public boolean isLoaded() { + return isElementDisplayed(By.id("inventory_container")); + } +} From 4867f1433959bf759e6adcc6be5b4638df89c997 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 3 Mar 2020 10:24:50 -0500 Subject: [PATCH 04/27] working parallel cross browser tests --- .../AcceptanceTestDrivenAutomationTest.java | 64 ++++++++++++++++--- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 59a2815..5101323 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -3,23 +3,54 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.chrome.ChromeOptions; +import org.openqa.selenium.remote.CapabilityType; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; import static org.junit.Assert.assertTrue; +@RunWith(Parameterized.class) public class AcceptanceTestDrivenAutomationTest { - private WebDriver driver; + public WebDriver driver; + + @Parameterized.Parameters + public static Collection data() { + return Arrays.asList(new Object[][] { + { "Chrome", "MacOS 10.12", "latest" }, + { "Safari", "MacOS 10.15", "latest" } + }); + } + + @Parameterized.Parameter // first data value (0) is default + public String browser; + + @Parameterized.Parameter(1) + public String platform; + + @Parameterized.Parameter(2) + public String browserVersion; @Before - public void setup() - { - driver = getDriver(); + public void setup() throws MalformedURLException { + createDriver(); } @After public void teardown() { - driver.quit(); + if(driver != null) + { + driver.quit(); + } } @Test public void shouldOpen() { @@ -39,9 +70,24 @@ public void shouldLogin() { assertTrue("Products page should open when we login", new ProductsPage(driver).isLoaded()); } - private WebDriver getDriver() { - //Telling the system where to find chromedriver. On Windows you also need to add .exe - System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - return new ChromeDriver(); + private void createDriver() throws MalformedURLException { + String sauceUsername = System.getenv("SAUCE_USERNAME"); + String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY"); + + MutableCapabilities sauceOpts = new MutableCapabilities(); + sauceOpts.setCapability("username", sauceUsername); + sauceOpts.setCapability("accessKey", sauceAccessKey); + sauceOpts.setCapability("build", "best-practices"); + sauceOpts.setCapability("tags", "['best-practices', 'best-practices']"); + + MutableCapabilities browserOptions = new MutableCapabilities(); + browserOptions.setCapability(CapabilityType.PLATFORM_NAME, platform); + browserOptions.setCapability(CapabilityType.BROWSER_VERSION, browserVersion); + browserOptions.setCapability(CapabilityType.BROWSER_NAME, browser); + browserOptions.setCapability("sauce:options", sauceOpts); + + String sauceUrl = "https://ondemand.saucelabs.com/wd/hub"; + URL url = new URL(sauceUrl); + driver = new RemoteWebDriver(url, browserOptions); } } From 3db2e5072d3d4932a6a7cf2314c93cdd2e088c75 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Fri, 1 May 2020 11:36:50 -0400 Subject: [PATCH 05/27] optimized imports --- .../java/atda/AcceptanceTestDrivenAutomationTest.java | 10 +++++++--- src/test/java/atda/LoginPage.java | 2 -- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 5101323..3073fa5 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -24,10 +24,14 @@ public class AcceptanceTestDrivenAutomationTest { public WebDriver driver; @Parameterized.Parameters - public static Collection data() { + public static Collection crossBrowserData() { return Arrays.asList(new Object[][] { - { "Chrome", "MacOS 10.12", "latest" }, - { "Safari", "MacOS 10.15", "latest" } + { "Chrome", "MacOS 10.14", "latest" }, + { "Chrome", "MacOS 10.15", "latest" }, + { "Chrome", "MacOS 10.14", "latest-1" }, + { "Chrome", "MacOS 10.15", "latest-1" }, + { "Safari", "MacOS 10.14", "latest" }, + { "Safari", "MacOS 10.15", "latest" }, }); } diff --git a/src/test/java/atda/LoginPage.java b/src/test/java/atda/LoginPage.java index 2ece306..7a73051 100644 --- a/src/test/java/atda/LoginPage.java +++ b/src/test/java/atda/LoginPage.java @@ -2,8 +2,6 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; public class LoginPage extends BasePage { From 00909d35fd5d3be95363bcb6cae8995ccf842fa1 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Fri, 1 May 2020 12:12:31 -0400 Subject: [PATCH 06/27] remove unused imports --- src/test/java/atda/AcceptanceTestDrivenAutomationTest.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 3073fa5..fb42e5f 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -7,8 +7,6 @@ import org.junit.runners.Parameterized; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.chrome.ChromeOptions; import org.openqa.selenium.remote.CapabilityType; import org.openqa.selenium.remote.RemoteWebDriver; @@ -81,8 +79,8 @@ private void createDriver() throws MalformedURLException { MutableCapabilities sauceOpts = new MutableCapabilities(); sauceOpts.setCapability("username", sauceUsername); sauceOpts.setCapability("accessKey", sauceAccessKey); - sauceOpts.setCapability("build", "best-practices"); - sauceOpts.setCapability("tags", "['best-practices', 'best-practices']"); + sauceOpts.setCapability("build", "ATDA"); + sauceOpts.setCapability("tags", "ATDA"); MutableCapabilities browserOptions = new MutableCapabilities(); browserOptions.setCapability(CapabilityType.PLATFORM_NAME, platform); From ba7db08649e42b352fabd2f72fdbe99d1eef3af7 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Fri, 1 May 2020 17:21:18 -0400 Subject: [PATCH 07/27] working cross browser --- pom.xml | 6 ++ .../AcceptanceTestDrivenAutomationTest.java | 68 +----------------- src/test/java/atda/BaseTest.java | 71 +++++++++++++++++++ 3 files changed, 78 insertions(+), 67 deletions(-) create mode 100644 src/test/java/atda/BaseTest.java diff --git a/pom.xml b/pom.xml index be41779..dc2f3bd 100644 --- a/pom.xml +++ b/pom.xml @@ -45,5 +45,11 @@ 3.141.59 test + + + com.saucelabs + sauce_bindings + 1.0.0 + \ No newline at end of file diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index fb42e5f..079fd12 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -1,59 +1,14 @@ package atda; -import org.junit.After; -import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import org.openqa.selenium.MutableCapabilities; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.remote.CapabilityType; -import org.openqa.selenium.remote.RemoteWebDriver; - -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Arrays; -import java.util.Collection; import static org.junit.Assert.assertTrue; @RunWith(Parameterized.class) -public class AcceptanceTestDrivenAutomationTest { - public WebDriver driver; - - @Parameterized.Parameters - public static Collection crossBrowserData() { - return Arrays.asList(new Object[][] { - { "Chrome", "MacOS 10.14", "latest" }, - { "Chrome", "MacOS 10.15", "latest" }, - { "Chrome", "MacOS 10.14", "latest-1" }, - { "Chrome", "MacOS 10.15", "latest-1" }, - { "Safari", "MacOS 10.14", "latest" }, - { "Safari", "MacOS 10.15", "latest" }, - }); - } - - @Parameterized.Parameter // first data value (0) is default - public String browser; +public class AcceptanceTestDrivenAutomationTest extends BaseTest { - @Parameterized.Parameter(1) - public String platform; - - @Parameterized.Parameter(2) - public String browserVersion; - - @Before - public void setup() throws MalformedURLException { - createDriver(); - } - @After - public void teardown() - { - if(driver != null) - { - driver.quit(); - } - } @Test public void shouldOpen() { LoginPage loginPage = new LoginPage(driver); @@ -71,25 +26,4 @@ public void shouldLogin() { loginPage.login("standard_user", "secret_sauce"); assertTrue("Products page should open when we login", new ProductsPage(driver).isLoaded()); } - - private void createDriver() throws MalformedURLException { - String sauceUsername = System.getenv("SAUCE_USERNAME"); - String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY"); - - MutableCapabilities sauceOpts = new MutableCapabilities(); - sauceOpts.setCapability("username", sauceUsername); - sauceOpts.setCapability("accessKey", sauceAccessKey); - sauceOpts.setCapability("build", "ATDA"); - sauceOpts.setCapability("tags", "ATDA"); - - MutableCapabilities browserOptions = new MutableCapabilities(); - browserOptions.setCapability(CapabilityType.PLATFORM_NAME, platform); - browserOptions.setCapability(CapabilityType.BROWSER_VERSION, browserVersion); - browserOptions.setCapability(CapabilityType.BROWSER_NAME, browser); - browserOptions.setCapability("sauce:options", sauceOpts); - - String sauceUrl = "https://ondemand.saucelabs.com/wd/hub"; - URL url = new URL(sauceUrl); - driver = new RemoteWebDriver(url, browserOptions); - } } diff --git a/src/test/java/atda/BaseTest.java b/src/test/java/atda/BaseTest.java new file mode 100644 index 0000000..6768732 --- /dev/null +++ b/src/test/java/atda/BaseTest.java @@ -0,0 +1,71 @@ +package atda; + +import org.junit.After; +import org.junit.Before; +import org.junit.runners.Parameterized; +import org.openqa.selenium.MutableCapabilities; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.remote.CapabilityType; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Arrays; +import java.util.Collection; + +public class BaseTest { + public WebDriver driver; + @Parameterized.Parameters + public static Collection crossBrowserData() { + return Arrays.asList(new Object[][] { + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + }); + } + + @Parameterized.Parameter // first data value (0) is default + public String browser; + + @Parameterized.Parameter(1) + public String platform; + + @Parameterized.Parameter(2) + public String browserVersion; + + @Before + public void setup() throws MalformedURLException { + createDriver(); + } + @After + public void teardown() + { + if(driver != null) + { + driver.quit(); + } + } + private void createDriver() throws MalformedURLException { + String sauceUsername = System.getenv("SAUCE_USERNAME"); + String sauceAccessKey = System.getenv("SAUCE_ACCESS_KEY"); + + MutableCapabilities sauceOpts = new MutableCapabilities(); + sauceOpts.setCapability("username", sauceUsername); + sauceOpts.setCapability("accessKey", sauceAccessKey); + sauceOpts.setCapability("build", "ATDA"); + sauceOpts.setCapability("tags", "ATDA"); + + MutableCapabilities browserOptions = new MutableCapabilities(); + browserOptions.setCapability(CapabilityType.PLATFORM_NAME, platform); + browserOptions.setCapability(CapabilityType.BROWSER_VERSION, browserVersion); + browserOptions.setCapability(CapabilityType.BROWSER_NAME, browser); + browserOptions.setCapability("sauce:options", sauceOpts); + + String sauceUrl = "https://ondemand.saucelabs.com/wd/hub"; + URL url = new URL(sauceUrl); + driver = new RemoteWebDriver(url, browserOptions); + } +} From 372ad8a7022a3750836d8f9a6fb1bc44d27cc5dd Mon Sep 17 00:00:00 2001 From: nadvolod Date: Thu, 7 May 2020 13:23:18 -0400 Subject: [PATCH 08/27] add test watcher --- src/test/java/atda/BaseTest.java | 1 - src/test/java/atda/SauceTestWatcher.java | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/test/java/atda/SauceTestWatcher.java diff --git a/src/test/java/atda/BaseTest.java b/src/test/java/atda/BaseTest.java index 6768732..3a00588 100644 --- a/src/test/java/atda/BaseTest.java +++ b/src/test/java/atda/BaseTest.java @@ -56,7 +56,6 @@ private void createDriver() throws MalformedURLException { sauceOpts.setCapability("username", sauceUsername); sauceOpts.setCapability("accessKey", sauceAccessKey); sauceOpts.setCapability("build", "ATDA"); - sauceOpts.setCapability("tags", "ATDA"); MutableCapabilities browserOptions = new MutableCapabilities(); browserOptions.setCapability(CapabilityType.PLATFORM_NAME, platform); diff --git a/src/test/java/atda/SauceTestWatcher.java b/src/test/java/atda/SauceTestWatcher.java new file mode 100644 index 0000000..0f1daec --- /dev/null +++ b/src/test/java/atda/SauceTestWatcher.java @@ -0,0 +1,14 @@ +package atda; + +import org.junit.runner.Description; + +public class SauceTestWatcher extends TestWatcher { + + protected void succeeded(Description description) { + sauceSession.stop("passed"); + } + + protected void failed(Description description) { + sauceSession.stop("failed"); + } +} From 932a807c9c7c0d768afefa9e8adbf413770fbc92 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Fri, 8 May 2020 14:28:38 -0400 Subject: [PATCH 09/27] add sauce test watcher --- src/test/java/atda/BaseTest.java | 24 +++++++++++++++--------- src/test/java/atda/SauceTestWatcher.java | 21 +++++++++++++++++++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/test/java/atda/BaseTest.java b/src/test/java/atda/BaseTest.java index 3a00588..c020e13 100644 --- a/src/test/java/atda/BaseTest.java +++ b/src/test/java/atda/BaseTest.java @@ -1,7 +1,8 @@ package atda; -import org.junit.After; import org.junit.Before; +import org.junit.Rule; +import org.junit.rules.TestName; import org.junit.runners.Parameterized; import org.openqa.selenium.MutableCapabilities; import org.openqa.selenium.WebDriver; @@ -15,6 +16,17 @@ public class BaseTest { public WebDriver driver; + + @Rule + public SauceTestWatcher resultReportingTestWatcher = new SauceTestWatcher(); + + @Rule + public TestName testName = new TestName() { + public String getMethodName() { + return String.format("%s", super.getMethodName()); + } + }; + @Parameterized.Parameters public static Collection crossBrowserData() { return Arrays.asList(new Object[][] { @@ -39,14 +51,7 @@ public static Collection crossBrowserData() { @Before public void setup() throws MalformedURLException { createDriver(); - } - @After - public void teardown() - { - if(driver != null) - { - driver.quit(); - } + resultReportingTestWatcher.setDriver(driver); } private void createDriver() throws MalformedURLException { String sauceUsername = System.getenv("SAUCE_USERNAME"); @@ -55,6 +60,7 @@ private void createDriver() throws MalformedURLException { MutableCapabilities sauceOpts = new MutableCapabilities(); sauceOpts.setCapability("username", sauceUsername); sauceOpts.setCapability("accessKey", sauceAccessKey); + sauceOpts.setCapability("name", testName.getMethodName()); sauceOpts.setCapability("build", "ATDA"); MutableCapabilities browserOptions = new MutableCapabilities(); diff --git a/src/test/java/atda/SauceTestWatcher.java b/src/test/java/atda/SauceTestWatcher.java index 0f1daec..8eb9e0a 100644 --- a/src/test/java/atda/SauceTestWatcher.java +++ b/src/test/java/atda/SauceTestWatcher.java @@ -1,14 +1,31 @@ package atda; +import org.junit.rules.TestWatcher; import org.junit.runner.Description; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; public class SauceTestWatcher extends TestWatcher { + private WebDriver driver; + + public void setDriver(WebDriver driver) + { + this.driver = driver; + } protected void succeeded(Description description) { - sauceSession.stop("passed"); + ((JavascriptExecutor) driver).executeScript("sauce:job-result=passed"); + if(driver != null) + { + driver.quit(); + } } protected void failed(Description description) { - sauceSession.stop("failed"); + ((JavascriptExecutor) driver).executeScript("sauce:job-result=failed"); + if(driver != null) + { + driver.quit(); + } } } From 59f4dc476cce5d3dd894e542d708a98a37bb237c Mon Sep 17 00:00:00 2001 From: nadvolod Date: Sat, 9 May 2020 14:19:19 -0400 Subject: [PATCH 10/27] add 2 more tests --- .../AcceptanceTestDrivenAutomationTest.java | 29 ++++++++++++------- src/test/java/atda/ProductsPage.java | 14 +++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 079fd12..2f2bc10 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -4,26 +4,35 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @RunWith(Parameterized.class) public class AcceptanceTestDrivenAutomationTest extends BaseTest { - @Test - public void shouldOpen() { - LoginPage loginPage = new LoginPage(driver); - loginPage.open(); - - assertTrue("Login page should load successfully", loginPage.isLoaded()); - } - @Test public void shouldLogin() { LoginPage loginPage = new LoginPage(driver); loginPage.open(); - assertTrue("Login page should load successfully", loginPage.isLoaded()); - + //I used to do this, now I learned it's not necessary + //assertTrue("Login page should load successfully", loginPage.isLoaded()); loginPage.login("standard_user", "secret_sauce"); assertTrue("Products page should open when we login", new ProductsPage(driver).isLoaded()); } + + @Test + public void shouldAddOneItemToCart() { + ProductsPage productsPage = new ProductsPage(driver); + productsPage.open(); + productsPage.addItemToCart(); + assertEquals("1", productsPage.getCountOfItemsInCart()); + } + @Test + public void shouldAddTwoItemsToCart() { + ProductsPage productsPage = new ProductsPage(driver); + productsPage.open(); + productsPage.addItemToCart(); + productsPage.addItemToCart(); + assertEquals("2", productsPage.getCountOfItemsInCart()); + } } diff --git a/src/test/java/atda/ProductsPage.java b/src/test/java/atda/ProductsPage.java index 1ea0d54..629faf6 100644 --- a/src/test/java/atda/ProductsPage.java +++ b/src/test/java/atda/ProductsPage.java @@ -2,6 +2,8 @@ import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; public class ProductsPage extends BasePage{ @@ -12,4 +14,16 @@ public ProductsPage(WebDriver driver) { public boolean isLoaded() { return isElementDisplayed(By.id("inventory_container")); } + + public void open() { + driver.navigate().to("https://www.saucedemo.com/inventory.html"); + } + + public void addItemToCart() { + WebDriverWait wait = new WebDriverWait(driver, 10); + wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("btn_primary"))).click(); + } + public String getCountOfItemsInCart() { + return driver.findElement(By.className("shopping_cart_badge")).getText(); + } } From f42dafb50ccafa35cf45f3558350b9a449fc0649 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Sat, 9 May 2020 16:28:27 -0400 Subject: [PATCH 11/27] test pipeline --- src/test/java/atda/AcceptanceTestDrivenAutomationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 2f2bc10..217cd17 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -19,7 +19,6 @@ public void shouldLogin() { loginPage.login("standard_user", "secret_sauce"); assertTrue("Products page should open when we login", new ProductsPage(driver).isLoaded()); } - @Test public void shouldAddOneItemToCart() { ProductsPage productsPage = new ProductsPage(driver); From a3245f4ccb45efcba0f2818596ec6704b06ab5d0 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Sat, 9 May 2020 16:46:11 -0400 Subject: [PATCH 12/27] test pipeline --- src/test/java/atda/AcceptanceTestDrivenAutomationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 217cd17..8e944bb 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -9,7 +9,6 @@ @RunWith(Parameterized.class) public class AcceptanceTestDrivenAutomationTest extends BaseTest { - @Test public void shouldLogin() { LoginPage loginPage = new LoginPage(driver); From 7c4fa4ab4716fcc9a5b29e3cafb9c2a3498ed0be Mon Sep 17 00:00:00 2001 From: nadvolod Date: Sat, 9 May 2020 16:48:42 -0400 Subject: [PATCH 13/27] try again --- src/test/java/atda/AcceptanceTestDrivenAutomationTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index 8e944bb..217cd17 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -9,6 +9,7 @@ @RunWith(Parameterized.class) public class AcceptanceTestDrivenAutomationTest extends BaseTest { + @Test public void shouldLogin() { LoginPage loginPage = new LoginPage(driver); From 96469b61f893c427f25310fb21b4d0133f74d32b Mon Sep 17 00:00:00 2001 From: nadvolod Date: Sun, 10 May 2020 09:22:24 -0400 Subject: [PATCH 14/27] fix compilation issue --- .../java/atda/AcceptanceTestDrivenAutomationTest.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java index cfe5625..217cd17 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java @@ -33,13 +33,5 @@ public void shouldAddTwoItemsToCart() { productsPage.addItemToCart(); productsPage.addItemToCart(); assertEquals("2", productsPage.getCountOfItemsInCart()); - - private WebDriver getDriver() { - //Telling the system where to find chromedriver on mac - //System.setProperty("webdriver.chrome.driver", "resources/mac/chromedriver"); - - //The path of chromedriver for windows - System.setProperty("webdriver.chrome.driver", "resources/windows/chromedriver.exe"); - return new ChromeDriver(); } } From 2547de360ad831604f00a5396e9470ed32280b72 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Sun, 10 May 2020 09:42:10 -0400 Subject: [PATCH 15/27] decrease timeout exception --- src/test/java/atda/BaseTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/atda/BaseTest.java b/src/test/java/atda/BaseTest.java index c020e13..5891306 100644 --- a/src/test/java/atda/BaseTest.java +++ b/src/test/java/atda/BaseTest.java @@ -62,6 +62,8 @@ private void createDriver() throws MalformedURLException { sauceOpts.setCapability("accessKey", sauceAccessKey); sauceOpts.setCapability("name", testName.getMethodName()); sauceOpts.setCapability("build", "ATDA"); + sauceOpts.setCapability("commandTimeout", "30"); + MutableCapabilities browserOptions = new MutableCapabilities(); browserOptions.setCapability(CapabilityType.PLATFORM_NAME, platform); From 759e48a2dc47f6dd8670f0471d7b242dd6c5239e Mon Sep 17 00:00:00 2001 From: nadvolod Date: Sun, 10 May 2020 10:05:16 -0400 Subject: [PATCH 16/27] updat .yml --- .github/workflows/maven.yml | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index b361193..4676ce6 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -14,10 +14,15 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Test with Maven - run: mvn test -X + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Run acceptance tests + env: + SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} + SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} + run: | + echo "$TEST_SECRET" + mvn test -X -Dtest=AcceptanceTestDrivenAutomationTest \ No newline at end of file From ddd2dd651a5a615d8d17e1000baea1e836b0a2e3 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Mon, 3 Aug 2020 19:04:12 -0400 Subject: [PATCH 17/27] delete unecessary code --- .github/workflows/maven.yml | 28 ------ src/test/java/HelloSeleniumTest.java | 15 --- src/test/java/advanced/tips/PageLoadTest.java | 35 ------- src/test/java/best/practices/Duplication.java | 91 ------------------- src/test/java/best/practices/LoginPage.java | 21 ----- .../java/best/practices/PersonalInfoPage.java | 28 ------ .../java/best/practices/ProductsPage.java | 16 ---- .../java/best/practices/ShoppingCartPage.java | 19 ---- .../java/best/practices/Synchronization.java | 74 --------------- .../elements/LocatingElementsTest.java | 74 --------------- 10 files changed, 401 deletions(-) delete mode 100644 .github/workflows/maven.yml delete mode 100644 src/test/java/HelloSeleniumTest.java delete mode 100644 src/test/java/advanced/tips/PageLoadTest.java delete mode 100644 src/test/java/best/practices/Duplication.java delete mode 100644 src/test/java/best/practices/LoginPage.java delete mode 100644 src/test/java/best/practices/PersonalInfoPage.java delete mode 100644 src/test/java/best/practices/ProductsPage.java delete mode 100644 src/test/java/best/practices/ShoppingCartPage.java delete mode 100644 src/test/java/best/practices/Synchronization.java delete mode 100644 src/test/java/locating/elements/LocatingElementsTest.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index f174da7..0000000 --- a/.github/workflows/maven.yml +++ /dev/null @@ -1,28 +0,0 @@ -# This workflow will build a Java project with Maven -# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: - - cross_browser_sauce_bindings - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 11 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Run acceptance tests - env: - SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} - SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} - run: | - echo "$TEST_SECRET" - mvn test -X -Dtest=AcceptanceTestDrivenAutomationTest diff --git a/src/test/java/HelloSeleniumTest.java b/src/test/java/HelloSeleniumTest.java deleted file mode 100644 index f48934a..0000000 --- a/src/test/java/HelloSeleniumTest.java +++ /dev/null @@ -1,15 +0,0 @@ -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - -public class HelloSeleniumTest { - @Test - public void firstTest() - { - //Telling the system where to find chromedriver. On Windows you also need to add .exe - System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - WebDriver driver = new ChromeDriver(); - driver.get("https://www.saucedemo.com/"); - driver.quit(); - } -} diff --git a/src/test/java/advanced/tips/PageLoadTest.java b/src/test/java/advanced/tips/PageLoadTest.java deleted file mode 100644 index 632af7e..0000000 --- a/src/test/java/advanced/tips/PageLoadTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package advanced.tips; - -import org.apache.commons.lang3.SystemUtils; -import org.junit.After; -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - -public class PageLoadTest { - private WebDriver driver; - - @Test - public void checkPageLoad() { - driver = getDriver(); - driver.navigate().to("https://www.saucedemo.com/"); - } - - @After - public void tearDown() { - driver.quit(); - } - - private WebDriver getDriver() { - if(SystemUtils.IS_OS_WINDOWS) - { - //The path of chromedriver for windows - System.setProperty("webdriver.chrome.driver", "resources/windows/chromedriver.exe"); - } - //Telling the system where to find chromedriver on mac - System.setProperty("webdriver.chrome.driver", "resources/mac/chromedriver"); - - - return new ChromeDriver(); - } -} diff --git a/src/test/java/best/practices/Duplication.java b/src/test/java/best/practices/Duplication.java deleted file mode 100644 index db26b68..0000000 --- a/src/test/java/best/practices/Duplication.java +++ /dev/null @@ -1,91 +0,0 @@ -package best.practices; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import static org.junit.Assert.assertTrue; - -public class Duplication { - WebDriver driver; - @Before - public void setup() - { - driver = getDriver(); - } - @After - public void cleanup() - { - driver.quit(); - } - @Test - public void test1() { - driver.get("http://www.saucedemo.com"); - driver.findElement(By.id("user-name")).sendKeys("standard_user"); - driver.findElement(By.id("password")).sendKeys("secret_sauce"); - driver.findElement(By.className("btn_action")).submit(); - WebDriverWait wait = new WebDriverWait(driver, 10); - boolean isDisplayed = wait.until( - ExpectedConditions.presenceOfElementLocated(By.id("inventory_filter_container"))).isDisplayed(); - assertTrue(isDisplayed); - } - @Test - public void test2() { - driver.get("http://www.saucedemo.com"); - driver.findElement(By.id("user-name")).sendKeys("problem_user"); - driver.findElement(By.id("password")).sendKeys("secret_sauce"); - driver.findElement(By.className("btn_action")).submit(); - WebDriverWait wait = new WebDriverWait(driver, 10); - boolean isDisplayed = wait.until( - ExpectedConditions.presenceOfElementLocated(By.id("inventory_filter_container"))).isDisplayed(); - assertTrue(isDisplayed); - } - @Test - public void test3() { - open(); - typeText(By.id("user-name"), "standard_user"); - typeText(By.id("password"), "secret_sauce"); - clickButton(By.className("btn_action")); - boolean isDisplayed = waitUntilDisplayed(By.id("inventory_filter_container")); - - assertTrue(isDisplayed); - } - @Test - public void test4() { - open(); - typeText(By.id("user-name"), "problem_user"); - typeText(By.id("password"), "secret_sauce"); - clickButton(By.className("btn_action")); - boolean isDisplayed = waitUntilDisplayed(By.id("inventory_filter_container")); - - assertTrue(isDisplayed); - } - private boolean waitUntilDisplayed(By locator) { - WebDriverWait wait = new WebDriverWait(driver, 10); - return wait.until( - ExpectedConditions.presenceOfElementLocated(locator)).isDisplayed(); - } - - private void clickButton(By locator) { - driver.findElement(locator).submit(); - } - - private void typeText(By locator, String string) { - driver.findElement(locator).sendKeys(string); - } - - private void open() { - driver.get("http://www.saucedemo.com"); - } - - private WebDriver getDriver() { - //Telling the system where to find chromedriver. On Windows you also need to add .exe - System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - return new ChromeDriver(); - } -} diff --git a/src/test/java/best/practices/LoginPage.java b/src/test/java/best/practices/LoginPage.java deleted file mode 100644 index c6cb60c..0000000 --- a/src/test/java/best/practices/LoginPage.java +++ /dev/null @@ -1,21 +0,0 @@ -package best.practices; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; - -public class LoginPage { - //Private driver for a page object so that it's never accessible to our tests - private WebDriver driver; - //Private element locator that is never open to our tests - private WebElement getUserNameField() - { - return driver.findElement(By.id("user-name")); - } - //Public login method, what the user does! - public void login(String userName, String password) { - getUserNameField().sendKeys(userName); - driver.findElement(By.id("password")).sendKeys(password); - driver.findElement(By.className("btn_action")).submit(); - } -} diff --git a/src/test/java/best/practices/PersonalInfoPage.java b/src/test/java/best/practices/PersonalInfoPage.java deleted file mode 100644 index 4be6c03..0000000 --- a/src/test/java/best/practices/PersonalInfoPage.java +++ /dev/null @@ -1,28 +0,0 @@ -package best.practices; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; - -public class PersonalInfoPage { - //Private driver for a page object so that it's never accessible to our tests - private WebDriver driver; - //Private element locator that is never open to our tests - private WebElement getFirstNameField() - { - return driver.findElement(By.id("FAKE LOCATOR")); - } - //Public login method, what the user does! - public void fillOutPersonalInformation() { - getFirstNameField().sendKeys("firstName"); - getLastNameField().sendKeys("firstName"); - getZipCodeField().sendKeys("firstName"); - } - - private WebElement getZipCodeField() { - return driver.findElement(By.id("FAKE LOCATOR")); - } - private WebElement getLastNameField() { - return driver.findElement(By.id("FAKE LOCATOR")); - } -} diff --git a/src/test/java/best/practices/ProductsPage.java b/src/test/java/best/practices/ProductsPage.java deleted file mode 100644 index e2f55cf..0000000 --- a/src/test/java/best/practices/ProductsPage.java +++ /dev/null @@ -1,16 +0,0 @@ -package best.practices; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; - -public class ProductsPage { - private WebDriver driver; - private WebElement getShoppingCartElement() - { - return driver.findElement(By.id("BLABHLABHLJ")); - } - public void openShoppingCart() { - getShoppingCartElement().click(); - } -} diff --git a/src/test/java/best/practices/ShoppingCartPage.java b/src/test/java/best/practices/ShoppingCartPage.java deleted file mode 100644 index 8c81f13..0000000 --- a/src/test/java/best/practices/ShoppingCartPage.java +++ /dev/null @@ -1,19 +0,0 @@ -package best.practices; - -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; - -public class ShoppingCartPage { - //Private driver for a page object so that it's never accessible to our tests - private WebDriver driver; - //Private element locator that is never open to our tests - private WebElement getCheckoutButton() - { - return driver.findElement(By.id("FAKE LOCATOR")); - } - //Public login method, what the user does! - public void startCheckout() { - getCheckoutButton().click(); - } -} diff --git a/src/test/java/best/practices/Synchronization.java b/src/test/java/best/practices/Synchronization.java deleted file mode 100644 index 263aae9..0000000 --- a/src/test/java/best/practices/Synchronization.java +++ /dev/null @@ -1,74 +0,0 @@ -package best.practices; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.util.concurrent.TimeUnit; - -public class Synchronization { - WebDriver driver; - String elementExistsInDOM = "https://the-internet.herokuapp.com/dynamic_loading/1"; - String elementRenderedAfter = "https://the-internet.herokuapp.com/dynamic_loading/2"; - By locator = By.id("finish"); - @Before - public void setup() - { - driver = getDriver(); - } - @After - public void cleanup() - { - driver.quit(); - } - @Test - public void implicitWaitFindsHiddenElement() { - driver.get(elementExistsInDOM); - driver.findElement(locator); - } - @Test - public void implicitWaitThrowsNoSuchElementException() { - driver.get(elementRenderedAfter); - driver.findElement(locator); - } - @Test - public void configuredImplicitWait() { - driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); - driver.get(elementRenderedAfter); - driver.findElement(locator); - } - @Test(expected = org.openqa.selenium.TimeoutException.class) - public void explicitWaitFixesImplicitWaitIssues() { - driver.get(elementExistsInDOM); - WebDriverWait wait = new WebDriverWait(driver, 5); - wait.until(ExpectedConditions.visibilityOfElementLocated(locator)); - } - @Test - public void explicitWaitWhenElementPresent() { - driver.get(elementExistsInDOM); - WebDriverWait wait = new WebDriverWait(driver, 5); - wait.until(ExpectedConditions.presenceOfElementLocated(locator)); - } - @Test - public void correctSynchronization() { - driver.get(elementRenderedAfter); - WebDriverWait wait = new WebDriverWait(driver, 5); - WebElement startButton = - wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("start"))).findElement(By.xpath("//button")); - startButton.click(); - WebElement helloWorldElement = - wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("finish"))); - } - - private WebDriver getDriver() { - //Telling the system where to find chromedriver. On Windows you also need to add .exe - System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - return new ChromeDriver(); - } -} diff --git a/src/test/java/locating/elements/LocatingElementsTest.java b/src/test/java/locating/elements/LocatingElementsTest.java deleted file mode 100644 index e253970..0000000 --- a/src/test/java/locating/elements/LocatingElementsTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package locating.elements; - -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; - -import static org.junit.Assert.assertTrue; - -public class LocatingElementsTest { - - @Test - public void elementsQuiz1() - { - //Telling the system where to find chromedriver. On Windows you also need to add .exe - System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - //1. Instantiate the driver - WebDriver driver = new ChromeDriver(); - //2. navigate to the URL - driver.get("https://www.saucedemo.com/"); - //3. Find element //4. check the state - WebDriverWait wait = new WebDriverWait(driver, 10); - WebElement element = wait.until( - ExpectedConditions.presenceOfElementLocated(By.id("user-name"))); - //5. take action //6. record the result - assertTrue(element.isDisplayed()); - //7. quit the driver - driver.quit(); - } - @Test - public void typesOfLocators() - { - //Telling the system where to find chromedriver. On Windows you also need to add .exe - System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - //1. Instantiate the driver - WebDriver driver = new ChromeDriver(); - //2. navigate to the URL - driver.get("https://www.saucedemo.com/"); - //3. Find element - WebElement element; - //ID - element = driver.findElement(By.id("user-name")); - //Name - //driver.findElement(By.name("name of locator")); - //Class name - driver.findElement(By.className("form_input")); - //Tag name - driver.findElement(By.tagName("input")); - //Css selector - //#user-name - driver.findElement(By.cssSelector("#user-name")); - //Xpath - // //*[@id="user-name"] - driver.findElement(By.xpath("//*[@id=\"user-name\"]")); - driver.quit(); - - - //Telling the system where to find chromedriver. On Windows you also need to add .exe - System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - //1. Instantiate the driver - driver = new ChromeDriver(); - //2. navigate to the URL - driver.get("https://ultimateqa.com/simple-html-elements-for-automation/"); - //Link text - driver.findElement(By.linkText("Click me using this link text!")); - //Partial link text - driver.findElement(By.partialLinkText("link text!")); - //7. quit the driver - driver.quit(); - } -} From 03d903dfe5778b6e6f1df63524b38e9721ae8404 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Mon, 3 Aug 2020 19:18:55 -0400 Subject: [PATCH 18/27] turn on 100 parallel --- pom.xml | 9 ++++ src/test/java/atda/BaseTest.java | 44 +++++++++++++++++++ ...mationTest.java => RandomFeatureTest.java} | 11 +---- 3 files changed, 54 insertions(+), 10 deletions(-) rename src/test/java/atda/{AcceptanceTestDrivenAutomationTest.java => RandomFeatureTest.java} (71%) diff --git a/pom.xml b/pom.xml index 3c73264..47fbcbb 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,15 @@ 11 + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + all + 100 + + diff --git a/src/test/java/atda/BaseTest.java b/src/test/java/atda/BaseTest.java index 5891306..c1cd9fe 100644 --- a/src/test/java/atda/BaseTest.java +++ b/src/test/java/atda/BaseTest.java @@ -36,6 +36,50 @@ public static Collection crossBrowserData() { { "Chrome", "macOS 10.15", "latest-1" }, { "Safari", "macOS 10.14", "latest" }, { "Safari", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest" }, + { "Chrome", "macOS 10.15", "latest" }, + { "Chrome", "macOS 10.14", "latest-1" }, + { "Chrome", "macOS 10.15", "latest-1" }, + { "Safari", "macOS 10.14", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Safari", "macOS 10.15", "latest" }, + { "Safari", "macOS 10.15", "latest" }, }); } diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/RandomFeatureTest.java similarity index 71% rename from src/test/java/atda/AcceptanceTestDrivenAutomationTest.java rename to src/test/java/atda/RandomFeatureTest.java index 217cd17..ea30707 100644 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ b/src/test/java/atda/RandomFeatureTest.java @@ -8,8 +8,7 @@ import static org.junit.Assert.assertTrue; @RunWith(Parameterized.class) -public class AcceptanceTestDrivenAutomationTest extends BaseTest { - +public class RandomFeatureTest extends BaseTest { @Test public void shouldLogin() { LoginPage loginPage = new LoginPage(driver); @@ -26,12 +25,4 @@ public void shouldAddOneItemToCart() { productsPage.addItemToCart(); assertEquals("1", productsPage.getCountOfItemsInCart()); } - @Test - public void shouldAddTwoItemsToCart() { - ProductsPage productsPage = new ProductsPage(driver); - productsPage.open(); - productsPage.addItemToCart(); - productsPage.addItemToCart(); - assertEquals("2", productsPage.getCountOfItemsInCart()); - } } From 470eca9cc937b4047e24f26407c6c40b39b0b2d9 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Mon, 3 Aug 2020 20:04:50 -0400 Subject: [PATCH 19/27] rename package --- pom.xml | 6 ------ src/test/java/{atda => com/acceptance}/BasePage.java | 2 +- src/test/java/{atda => com/acceptance}/BaseTest.java | 2 +- src/test/java/{atda => com/acceptance}/LoginPage.java | 3 +-- src/test/java/{atda => com/acceptance}/ProductsPage.java | 2 +- .../java/{atda => com/acceptance}/RandomFeatureTest.java | 2 +- .../java/{atda => com/acceptance}/SauceTestWatcher.java | 2 +- 7 files changed, 6 insertions(+), 13 deletions(-) rename src/test/java/{atda => com/acceptance}/BasePage.java (95%) rename src/test/java/{atda => com/acceptance}/BaseTest.java (99%) rename src/test/java/{atda => com/acceptance}/LoginPage.java (90%) rename src/test/java/{atda => com/acceptance}/ProductsPage.java (97%) rename src/test/java/{atda => com/acceptance}/RandomFeatureTest.java (97%) rename src/test/java/{atda => com/acceptance}/SauceTestWatcher.java (96%) diff --git a/pom.xml b/pom.xml index 47fbcbb..8f9b287 100644 --- a/pom.xml +++ b/pom.xml @@ -32,12 +32,6 @@ - - junit - junit - 4.12 - test - org.seleniumhq.selenium selenium-java diff --git a/src/test/java/atda/BasePage.java b/src/test/java/com/acceptance/BasePage.java similarity index 95% rename from src/test/java/atda/BasePage.java rename to src/test/java/com/acceptance/BasePage.java index bc24900..cf56824 100644 --- a/src/test/java/atda/BasePage.java +++ b/src/test/java/com/acceptance/BasePage.java @@ -1,4 +1,4 @@ -package atda; +package com.acceptance; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; diff --git a/src/test/java/atda/BaseTest.java b/src/test/java/com/acceptance/BaseTest.java similarity index 99% rename from src/test/java/atda/BaseTest.java rename to src/test/java/com/acceptance/BaseTest.java index c1cd9fe..0955b49 100644 --- a/src/test/java/atda/BaseTest.java +++ b/src/test/java/com/acceptance/BaseTest.java @@ -1,4 +1,4 @@ -package atda; +package com.acceptance; import org.junit.Before; import org.junit.Rule; diff --git a/src/test/java/atda/LoginPage.java b/src/test/java/com/acceptance/LoginPage.java similarity index 90% rename from src/test/java/atda/LoginPage.java rename to src/test/java/com/acceptance/LoginPage.java index 29c0862..4685259 100644 --- a/src/test/java/atda/LoginPage.java +++ b/src/test/java/com/acceptance/LoginPage.java @@ -1,8 +1,7 @@ -package atda; +package com.acceptance; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; -import org.openqa.selenium.support.ui.ExpectedConditions; public class LoginPage extends BasePage { diff --git a/src/test/java/atda/ProductsPage.java b/src/test/java/com/acceptance/ProductsPage.java similarity index 97% rename from src/test/java/atda/ProductsPage.java rename to src/test/java/com/acceptance/ProductsPage.java index 629faf6..8c75ae6 100644 --- a/src/test/java/atda/ProductsPage.java +++ b/src/test/java/com/acceptance/ProductsPage.java @@ -1,4 +1,4 @@ -package atda; +package com.acceptance; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; diff --git a/src/test/java/atda/RandomFeatureTest.java b/src/test/java/com/acceptance/RandomFeatureTest.java similarity index 97% rename from src/test/java/atda/RandomFeatureTest.java rename to src/test/java/com/acceptance/RandomFeatureTest.java index ea30707..f627569 100644 --- a/src/test/java/atda/RandomFeatureTest.java +++ b/src/test/java/com/acceptance/RandomFeatureTest.java @@ -1,4 +1,4 @@ -package atda; +package com.acceptance; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/src/test/java/atda/SauceTestWatcher.java b/src/test/java/com/acceptance/SauceTestWatcher.java similarity index 96% rename from src/test/java/atda/SauceTestWatcher.java rename to src/test/java/com/acceptance/SauceTestWatcher.java index 8eb9e0a..3f322a5 100644 --- a/src/test/java/atda/SauceTestWatcher.java +++ b/src/test/java/com/acceptance/SauceTestWatcher.java @@ -1,4 +1,4 @@ -package atda; +package com.acceptance; import org.junit.rules.TestWatcher; import org.junit.runner.Description; From 62901d4076162c9a87d561eb44cd1de6c5ceca1e Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:04:21 -0400 Subject: [PATCH 20/27] add yml --- .github/workflows/gold.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/gold.yml diff --git a/.github/workflows/gold.yml b/.github/workflows/gold.yml new file mode 100644 index 0000000..f36c83a --- /dev/null +++ b/.github/workflows/gold.yml @@ -0,0 +1,24 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Gold pipeline + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Build with Maven + run: mvn test \ No newline at end of file From 3176ba7d8905cd3bdef699cbcab5cf6e95431815 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:06:15 -0400 Subject: [PATCH 21/27] change to ci3 --- .github/workflows/gold.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gold.yml b/.github/workflows/gold.yml index f36c83a..d1de533 100644 --- a/.github/workflows/gold.yml +++ b/.github/workflows/gold.yml @@ -5,9 +5,9 @@ name: Gold pipeline on: push: - branches: [ master ] + branches: [ ci3 ] pull_request: - branches: [ master ] + branches: [ ci3 ] jobs: build: From ce7dc8839a27d7292e25769806558b87840bfc15 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:11:29 -0400 Subject: [PATCH 22/27] add unit test --- .github/workflows/gold.yml | 4 ++-- src/test/java/com/unit/UnitTests.java | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 src/test/java/com/unit/UnitTests.java diff --git a/.github/workflows/gold.yml b/.github/workflows/gold.yml index d1de533..6b04113 100644 --- a/.github/workflows/gold.yml +++ b/.github/workflows/gold.yml @@ -20,5 +20,5 @@ jobs: uses: actions/setup-java@v1 with: java-version: 11 - - name: Build with Maven - run: mvn test \ No newline at end of file + - name: Run unit tests + run: mvn -Dtest=UnitTests test \ No newline at end of file diff --git a/src/test/java/com/unit/UnitTests.java b/src/test/java/com/unit/UnitTests.java new file mode 100644 index 0000000..eadf1c4 --- /dev/null +++ b/src/test/java/com/unit/UnitTests.java @@ -0,0 +1,11 @@ +package com.unit; + +import org.junit.Assert; +import org.junit.Test; + +public class UnitTests { + @Test + public void shouldPass() { + Assert.assertTrue(true); + } +} From f927ccce370af5cbcbe91593a7e1c8c46d55cf02 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:14:24 -0400 Subject: [PATCH 23/27] add integration --- .github/workflows/gold.yml | 4 +++- src/test/java/com/integration/IntegrationTests.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/integration/IntegrationTests.java diff --git a/.github/workflows/gold.yml b/.github/workflows/gold.yml index 6b04113..b6cb5bb 100644 --- a/.github/workflows/gold.yml +++ b/.github/workflows/gold.yml @@ -21,4 +21,6 @@ jobs: with: java-version: 11 - name: Run unit tests - run: mvn -Dtest=UnitTests test \ No newline at end of file + run: mvn -Dtest=UnitTests test + - name: Run integration tests + run: mvn -Dtest=IntegrationTests test \ No newline at end of file diff --git a/src/test/java/com/integration/IntegrationTests.java b/src/test/java/com/integration/IntegrationTests.java new file mode 100644 index 0000000..4995c2a --- /dev/null +++ b/src/test/java/com/integration/IntegrationTests.java @@ -0,0 +1,11 @@ +package com.integration; + +import org.junit.Assert; +import org.junit.Test; + +public class IntegrationTests { + @Test + public void integrationShouldPass() { + Assert.assertTrue(true); + } +} From 228d233e131fc255544ef9b6fbadafd627336338 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:18:12 -0400 Subject: [PATCH 24/27] add acceptance --- .github/workflows/gold.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/gold.yml b/.github/workflows/gold.yml index b6cb5bb..4d2c26e 100644 --- a/.github/workflows/gold.yml +++ b/.github/workflows/gold.yml @@ -23,4 +23,6 @@ jobs: - name: Run unit tests run: mvn -Dtest=UnitTests test - name: Run integration tests - run: mvn -Dtest=IntegrationTests test \ No newline at end of file + run: mvn -Dtest=IntegrationTests test + - name: Run acceptance tests + run: mvn -Dtest=*FeatureTest test \ No newline at end of file From 769c6e1894081ad14cba731f7b943d53fe2dca19 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:21:57 -0400 Subject: [PATCH 25/27] add creds --- .github/workflows/gold.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/gold.yml b/.github/workflows/gold.yml index 4d2c26e..2a687d5 100644 --- a/.github/workflows/gold.yml +++ b/.github/workflows/gold.yml @@ -25,4 +25,7 @@ jobs: - name: Run integration tests run: mvn -Dtest=IntegrationTests test - name: Run acceptance tests + env: + SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} + SAUCE_ACCES_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} run: mvn -Dtest=*FeatureTest test \ No newline at end of file From d8211340d41da5a09d4be3f94a431784d1aa610b Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:24:19 -0400 Subject: [PATCH 26/27] fix typo --- .github/workflows/gold.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gold.yml b/.github/workflows/gold.yml index 2a687d5..66a2f73 100644 --- a/.github/workflows/gold.yml +++ b/.github/workflows/gold.yml @@ -27,5 +27,5 @@ jobs: - name: Run acceptance tests env: SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} - SAUCE_ACCES_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} + SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} run: mvn -Dtest=*FeatureTest test \ No newline at end of file From e8b48faaab9fcee6398d104fe389f8db9145e5e8 Mon Sep 17 00:00:00 2001 From: nadvolod Date: Tue, 4 Aug 2020 19:33:02 -0400 Subject: [PATCH 27/27] add silver pipeline --- .github/workflows/silver.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 .github/workflows/silver.yml diff --git a/.github/workflows/silver.yml b/.github/workflows/silver.yml new file mode 100644 index 0000000..4c6027f --- /dev/null +++ b/.github/workflows/silver.yml @@ -0,0 +1,27 @@ +# This workflow will build a Java project with Maven +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven + +name: Silver pipeline + +on: + push: + branches: [ ci3 ] + pull_request: + branches: [ ci3 ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 11 + uses: actions/setup-java@v1 + with: + java-version: 11 + - name: Run acceptance tests + env: + SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} + SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} + run: mvn -Dtest=*FeatureTest test \ No newline at end of file