diff --git a/.github/workflows/gold-standard.yml b/.github/workflows/gold-standard.yml new file mode 100644 index 0000000..3d21f3d --- /dev/null +++ b/.github/workflows/gold-standard.yml @@ -0,0 +1,45 @@ +# 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 standard 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: Use Node.js + uses: actions/setup-node@v1 + with: + node-version: 12.x + - name: Build application + run: echo "Building our application" + - name: Run unit tests + run: mvn -Dtest=UnitTests test + - name: Run integration tests + run: mvn -Dtest=*IntegrationTests test + - name: Run acceptance tests + env: + SAUCE_USERNAME: ${{ secrets.SAUCE_USERNAME }} + SAUCE_ACCESS_KEY: ${{ secrets.SAUCE_ACCESS_KEY }} + run: mvn -Dtest=*FeatureTest test + # https://wiki.saucelabs.com/display/DOCS/Test+Performance+Using+Speedo + - name: Run front-end performance + env: + SAUCE_USERNAME: secrets.SAUCE_USERNAME + SAUCE_ACCESS_KEY: secrets.SAUCE_ACCESS_KEY + run: | + npm install -g speedo + speedo run https://www.saucedemo.com/ \ No newline at end of file diff --git a/.github/workflows/maven.build.master.yml b/.github/workflows/maven.build.master.yml deleted file mode 100644 index 9174dd5..0000000 --- a/.github/workflows/maven.build.master.yml +++ /dev/null @@ -1,24 +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: [ master ] - pull_request: - branches: [ master ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 111 - uses: actions/setup-java@v1 - with: - java-version: 11 - - name: Build with Maven - run: mvn compile -X diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml deleted file mode 100644 index 9ec7918..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/.github/workflows/maven2.yml b/.github/workflows/maven2.yml deleted file mode 100644 index 8f912a4..0000000 --- a/.github/workflows/maven2.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: Selenium Automation - -on: - push: - branches: - - ci - 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 -X test diff --git a/.github/workflows/silver-standard.yml b/.github/workflows/silver-standard.yml new file mode 100644 index 0000000..afbcef9 --- /dev/null +++ b/.github/workflows/silver-standard.yml @@ -0,0 +1,29 @@ +# 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 standard 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: Run sanity tests + run: mvn -Dtest=UnitTests test + - 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 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 ca57a21..3f730a2 100644 --- a/pom.xml +++ b/pom.xml @@ -20,15 +20,24 @@ 11 + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M4 + + all + 10 + + + org.seleniumhq.selenium selenium-java 3.141.59 - test junit @@ -36,17 +45,10 @@ 4.13 test - - - io.github.bonigarcia - webdrivermanager - 4.0.0 - test - - org.apache.commons - commons-lang3 - 3.10 + com.saucelabs + sauce_bindings + 1.0.0 \ No newline at end of file diff --git a/resources/mac/chromedriver b/resources/mac/chromedriver deleted file mode 100755 index 13d2eb1..0000000 Binary files a/resources/mac/chromedriver and /dev/null differ diff --git a/resources/windows/chromedriver.exe b/resources/windows/chromedriver.exe deleted file mode 100644 index 4f88879..0000000 Binary files a/resources/windows/chromedriver.exe 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/BasePage.java b/src/main/java/pages/BasePage.java similarity index 52% rename from src/test/java/atda/BasePage.java rename to src/main/java/pages/BasePage.java index eef3e5b..a4fc1a8 100644 --- a/src/test/java/atda/BasePage.java +++ b/src/main/java/pages/BasePage.java @@ -1,15 +1,19 @@ -package atda; +package pages; import org.openqa.selenium.WebDriver; import org.openqa.selenium.support.ui.WebDriverWait; public class BasePage { public final WebDriver driver; - WebDriverWait wait; + protected WebDriverWait wait; public BasePage(WebDriver driver) { this.driver = driver; - wait = new WebDriverWait(driver, 10); + wait = new WebDriverWait(driver, 5); + } + + public void open(String urlPart){ + driver.navigate().to("https://www.saucedemo.com/" + urlPart); } } diff --git a/src/main/java/pages/InventoryComponent.java b/src/main/java/pages/InventoryComponent.java new file mode 100644 index 0000000..3a1a829 --- /dev/null +++ b/src/main/java/pages/InventoryComponent.java @@ -0,0 +1,13 @@ +package pages; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +public class InventoryComponent extends BasePage { + public InventoryComponent(WebDriver driver) { + super(driver); + } + public void addRandomItemToCart() { + driver.findElement(By.cssSelector("button.btn_primary.btn_inventory")).click(); + } +} diff --git a/src/test/java/atda/LoginPage.java b/src/main/java/pages/LoginPage.java similarity index 91% rename from src/test/java/atda/LoginPage.java rename to src/main/java/pages/LoginPage.java index 3018565..13742ab 100644 --- a/src/test/java/atda/LoginPage.java +++ b/src/main/java/pages/LoginPage.java @@ -1,4 +1,4 @@ -package atda; +package pages; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; @@ -10,10 +10,6 @@ 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(); } @@ -23,4 +19,8 @@ public void login(String userName, String password) { driver.findElement(By.id("password")).sendKeys(password); driver.findElement(By.className("btn_action")).submit(); } + + public void open() { + open(""); + } } diff --git a/src/test/java/atda/ProductsPage.java b/src/main/java/pages/ProductsPage.java similarity index 60% rename from src/test/java/atda/ProductsPage.java rename to src/main/java/pages/ProductsPage.java index b8152a6..f43c4ea 100644 --- a/src/test/java/atda/ProductsPage.java +++ b/src/main/java/pages/ProductsPage.java @@ -1,17 +1,25 @@ -package atda; +package pages; 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 ShoppingCartComponent ShoppingCart; + public InventoryComponent Inventory; + public ProductsPage(WebDriver driver) { super(driver); + ShoppingCart = new ShoppingCartComponent(driver); + Inventory = new InventoryComponent(driver); } public boolean isLoaded() { return wait.until( ExpectedConditions.presenceOfElementLocated(By.id("inventory_filter_container"))).isDisplayed(); } + + public void open() { + open("inventory.html"); + } } diff --git a/src/main/java/pages/ShoppingCartComponent.java b/src/main/java/pages/ShoppingCartComponent.java new file mode 100644 index 0000000..53246af --- /dev/null +++ b/src/main/java/pages/ShoppingCartComponent.java @@ -0,0 +1,15 @@ +package pages; + +import org.openqa.selenium.By; +import org.openqa.selenium.WebDriver; + +public class ShoppingCartComponent extends BasePage { + public ShoppingCartComponent(WebDriver driver) { + super(driver); + } + + public boolean hasItems(int numberOfItems) { + String numOfItemsInCart = driver.findElement(By.xpath("//*[@class='fa-layers-counter shopping_cart_badge']")).getText(); + return Integer.parseInt(numOfItemsInCart) == numberOfItems; + } +} diff --git a/src/main/java/pages/ShoppingCartPage.java b/src/main/java/pages/ShoppingCartPage.java new file mode 100644 index 0000000..51f3936 --- /dev/null +++ b/src/main/java/pages/ShoppingCartPage.java @@ -0,0 +1,37 @@ +package pages; + +import org.openqa.selenium.*; +import org.openqa.selenium.support.ui.ExpectedConditions; + +import java.util.List; + +public class ShoppingCartPage extends BasePage { + public ShoppingCartPage(WebDriver driver) { + super(driver); + } + + public int getItemCount() { + List cartItems; + try + { + cartItems = + wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.className("cart_item"))); + } + catch (TimeoutException e) + { + return 0; + } + return cartItems.size(); + } + + public void open() { + open("cart.html"); + } + + public void injectItemIntoCart() { + JavascriptExecutor jsExecutor = (JavascriptExecutor) driver; + jsExecutor.executeScript("window.sessionStorage.setItem('session-username', 'standard-user')"); + jsExecutor.executeScript("window.sessionStorage.setItem('cart-contents', '[1]')"); + driver.navigate().refresh(); + } +} diff --git a/src/test/java/HelloSelenium2Test.java b/src/test/java/HelloSelenium2Test.java deleted file mode 100644 index 0a56601..0000000 --- a/src/test/java/HelloSelenium2Test.java +++ /dev/null @@ -1,21 +0,0 @@ -import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - - -public class HelloSelenium2Test { - //This method will run once before all of the tests in our class - @BeforeClass - public static void setupClass() { - WebDriverManager.chromedriver().setup(); - } - @Test - public void smarterTest() - { - WebDriver driver = new ChromeDriver(); - driver.get("https://www.saucedemo.com/"); - driver.quit(); - } -} diff --git a/src/test/java/HelloSeleniumTest.java b/src/test/java/HelloSeleniumTest.java deleted file mode 100644 index d4b1849..0000000 --- a/src/test/java/HelloSeleniumTest.java +++ /dev/null @@ -1,18 +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 Mac. - //System.setProperty("webdriver.chrome.driver", "resources/chromedriver"); - //Here's how to do it on Windows - System.setProperty("webdriver.chrome.driver", "resources/windows/chromedriver.exe"); - - WebDriver driver = new ChromeDriver(); - driver.get("https://www.saucedemo.com/"); - driver.quit(); - } -} diff --git a/src/test/java/SeleniumTest.java b/src/test/java/SeleniumTest.java deleted file mode 100644 index 1141647..0000000 --- a/src/test/java/SeleniumTest.java +++ /dev/null @@ -1,41 +0,0 @@ -import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.safari.SafariDriver; - - -public class SeleniumTest { - - // Navigate to this URL using another browser https://the-internet.herokuapp.com/ - // Navigate to this URL https://example.cypress.io/ - // Navigate to https://react-shopping-cart-67954.firebaseapp.com/ - // Using WebDriverManager - - //This method will run once before all of the tests in our class -// @BeforeClass -// public static void setupClass() { -// WebDriverManager.edgedriver().setup(); -// } - @Test - public void safariTest() { - WebDriver driver = new SafariDriver(); - driver.get("https://the-internet.herokuapp.com/"); - driver.quit(); - } - @Test - public void cypressTest() throws InterruptedException { - WebDriver driver = new SafariDriver(); - driver.get("https://example.cypress.io/"); - Thread.sleep(3000); - driver.quit(); - } - @Test - public void shoppingCartTest() throws InterruptedException { - WebDriver driver = new SafariDriver(); - driver.get("https://react-shopping-cart-67954.firebaseapp.com/"); - Thread.sleep(3000); - 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 aff5f38..0000000 --- a/src/test/java/advanced/tips/PageLoadTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package advanced.tips; - -import io.github.bonigarcia.wdm.WebDriverManager; -import org.apache.commons.lang3.SystemUtils; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; - -public class PageLoadTest { - private WebDriver driver; - - //This method will run once before all of the tests in our class - @BeforeClass - public static void setupClass() { - WebDriverManager.chromedriver().setup(); - } - - @Test - public void checkPageLoad() { - driver = getDriver(); - driver.navigate().to("https://www.saucedemo.com/"); - } - - @After - public void tearDown() { - driver.quit(); - } - - private WebDriver getDriver() { -<<<<<<< HEAD - //Using WebDriverManager package, we are able to not worry about -======= - //Using WebDriverManager package, we dopn't have to not worry about ->>>>>>> 6ae18a2eefa234b185ef64cf3b105766315609ab - //where the ChromeDriver comes from and if it's the latest - return new ChromeDriver(); - } -} diff --git a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java b/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java deleted file mode 100644 index a2ef3a8..0000000 --- a/src/test/java/atda/AcceptanceTestDrivenAutomationTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package atda; - -import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -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; - //This method will run once before all of the tests in our class - @BeforeClass - public static void setupClass() { - WebDriverManager.chromedriver().setup(); - } - @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() { - //Using WebDriverManager package, we dopn't have to not worry about - //where the ChromeDriver comes from and if it's the latest - return new ChromeDriver(); - } -} diff --git a/src/test/java/atda/BaseTest.java b/src/test/java/atda/BaseTest.java new file mode 100644 index 0000000..6fb1cb3 --- /dev/null +++ b/src/test/java/atda/BaseTest.java @@ -0,0 +1,23 @@ +package atda; + +import com.saucelabs.saucebindings.SauceSession; +import org.junit.After; +import org.junit.Before; +import org.openqa.selenium.WebDriver; + +public class BaseTest { + WebDriver driver; + @Before + public void setup() + { + driver = getDriver(); + } + @After + public void cleanup() + { + driver.quit(); + } + private WebDriver getDriver() { + return new SauceSession().start(); + } +} diff --git a/src/test/java/atda/LoginFeatureTest.java b/src/test/java/atda/LoginFeatureTest.java new file mode 100644 index 0000000..9f57c9b --- /dev/null +++ b/src/test/java/atda/LoginFeatureTest.java @@ -0,0 +1,28 @@ +package atda; + +import org.junit.Test; +import pages.LoginPage; +import pages.ProductsPage; + +import static org.junit.Assert.assertTrue; + +public class LoginFeatureTest extends BaseTest { + @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()); + } +} diff --git a/src/test/java/atda/ShoppingCartFeatureTest.java b/src/test/java/atda/ShoppingCartFeatureTest.java new file mode 100644 index 0000000..429a836 --- /dev/null +++ b/src/test/java/atda/ShoppingCartFeatureTest.java @@ -0,0 +1,29 @@ +package atda; + +import org.junit.Test; +import pages.ProductsPage; +import pages.ShoppingCartPage; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class ShoppingCartFeatureTest extends BaseTest { + @Test + public void shouldHaveItemAppearOnCartPage() { + ShoppingCartPage cartPage = new ShoppingCartPage(driver); + cartPage.open(); + + cartPage.injectItemIntoCart(); + assertEquals("Added one item to the cart and expected to have 1 item on cart page", + 1, new ShoppingCartPage(driver).getItemCount()); + } + + @Test + public void shouldBeAbleToAddItemToCart() { + ProductsPage productsPage = new ProductsPage(driver); + productsPage.open(); + productsPage.Inventory.addRandomItemToCart(); + assertTrue("We added a single item to the cart and expected the cart to have 1 item", + productsPage.ShoppingCart.hasItems(1)); + } +} 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/com/integration/IntegrationTests.java b/src/test/java/com/integration/IntegrationTests.java new file mode 100644 index 0000000..7a81488 --- /dev/null +++ b/src/test/java/com/integration/IntegrationTests.java @@ -0,0 +1,12 @@ +package com.integration; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class IntegrationTests { + @Test + public void integrationTestShouldPass() { + assertTrue(true); + } +} diff --git a/src/test/java/com/unit/UnitTests.java b/src/test/java/com/unit/UnitTests.java new file mode 100644 index 0000000..c0748ad --- /dev/null +++ b/src/test/java/com/unit/UnitTests.java @@ -0,0 +1,12 @@ +package com.unit; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class UnitTests { + @Test + public void shouldPass() { + assertTrue(true); + } +} diff --git a/src/test/java/locating/elements/LocatingElementsTest.java b/src/test/java/locating/elements/LocatingElementsTest.java deleted file mode 100644 index 76cc346..0000000 --- a/src/test/java/locating/elements/LocatingElementsTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package locating.elements; - -import io.github.bonigarcia.wdm.WebDriverManager; -import org.junit.BeforeClass; -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 { - @BeforeClass - public static void setupClass() { - WebDriverManager.chromedriver().setup(); - } - - @Test - public void elementsQuiz1() - { - //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() - { - //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(); - - //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(); - } -}