diff --git a/.github/workflows/atda.yml b/.github/workflows/atda.yml new file mode 100644 index 0000000..73909fd --- /dev/null +++ b/.github/workflows/atda.yml @@ -0,0 +1,26 @@ +name: ATDA Pipeline + +on: + push: + branches: + - rtc_2020_poc + - rtc_2020 + 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: Run acceptance tests + env: + SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} + SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} + run: mvn test \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 0196d76..68fd184 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -2,6 +2,7 @@ + diff --git a/.idea/misc.xml b/.idea/misc.xml index 2ddcb2e..ffd943f 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -11,7 +11,7 @@ - + \ No newline at end of file diff --git a/pom.xml b/pom.xml index c609a05..71976e3 100644 --- a/pom.xml +++ b/pom.xml @@ -10,16 +10,6 @@ - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M4 - - all - 10 - all - - org.apache.maven.plugins @@ -30,6 +20,15 @@ 11 + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + all + 100 + + @@ -38,7 +37,6 @@ org.seleniumhq.selenium selenium-java 3.141.59 - test junit @@ -46,5 +44,16 @@ 4.12 test + + + io.github.bonigarcia + webdrivermanager + 4.0.0 + + + com.saucelabs + sauce_bindings + 1.0.0 + \ No newline at end of file diff --git a/resources/chromedriver b/resources/chromedriver deleted file mode 100755 index 1161497..0000000 Binary files a/resources/chromedriver and /dev/null differ diff --git a/selenium.java.iml b/selenium.java.iml deleted file mode 100644 index 78b2cc5..0000000 --- a/selenium.java.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java deleted file mode 100644 index 9fecfd9..0000000 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ /dev/null @@ -1,47 +0,0 @@ -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() { - //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/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(); - } -} diff --git a/src/test/java/com/atda/BasePage.java b/src/test/java/com/atda/BasePage.java new file mode 100644 index 0000000..c37cc23 --- /dev/null +++ b/src/test/java/com/atda/BasePage.java @@ -0,0 +1,11 @@ +package com.atda; + +import org.openqa.selenium.WebDriver; + +public class BasePage { + public WebDriver driver; + + public BasePage(WebDriver driver) { + this.driver = driver; + } +} diff --git a/src/test/java/com/atda/ProductsFeatureTests.java b/src/test/java/com/atda/ProductsFeatureTests.java new file mode 100644 index 0000000..807bf85 --- /dev/null +++ b/src/test/java/com/atda/ProductsFeatureTests.java @@ -0,0 +1,41 @@ +package com.atda; + +import com.saucelabs.saucebindings.SauceSession; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openqa.selenium.WebDriver; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ProductsFeatureTests { + private WebDriver driver; + private SauceSession session; + private ProductsPage productsPage; + + @Before + public void setUp() { + session = new SauceSession(); + driver = session.start(); + productsPage = new ProductsPage(driver); + } + + @After + public void tearDown() { + session.stop(true); + } + + @Test + public void shouldOpen() { + productsPage.open(); + assertTrue(productsPage.isLoaded()); + } + + @Test + public void canAddItemToCart() { + productsPage.open(); + productsPage.addItemToCart(); + assertEquals(1, new ShoppingCart(driver).itemCount()); + } +} diff --git a/src/test/java/com/atda/ProductsPage.java b/src/test/java/com/atda/ProductsPage.java new file mode 100644 index 0000000..3c087df --- /dev/null +++ b/src/test/java/com/atda/ProductsPage.java @@ -0,0 +1,23 @@ +package com.atda; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +public class ProductsPage extends BasePage{ + public ProductsPage(WebDriver driver) { + super(driver); + } + + public void open() { + driver.navigate().to("https://www.saucedemo.com/inventory.html"); + } + + public boolean isLoaded() { + return driver.findElement(By.id("inventory_filter_container")). + isDisplayed(); + } + + public void addItemToCart() { + driver.findElement(By.className("btn_inventory")).click(); + } +} diff --git a/src/test/java/com/atda/ShoppingCart.java b/src/test/java/com/atda/ShoppingCart.java new file mode 100644 index 0000000..72b277a --- /dev/null +++ b/src/test/java/com/atda/ShoppingCart.java @@ -0,0 +1,15 @@ +package com.atda; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +public class ShoppingCart extends BasePage { + public ShoppingCart(WebDriver driver) { + super(driver); + } + + public int itemCount() { + return Integer.parseInt( + driver.findElement(By.className("shopping_cart_badge")).getText()); + } +}