-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0edd38b
commit 32a59fc
Showing
7 changed files
with
311 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
selenium-examples/src/test/java/com/saucedemo/selenium/demo/AuthenticationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.saucedemo.selenium.demo; | ||
|
||
import com.saucedemo.selenium.TestBase; | ||
import org.junit.jupiter.api.*; | ||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebElement; | ||
|
||
public class AuthenticationTest extends TestBase { | ||
|
||
@BeforeEach | ||
public void setup(TestInfo testInfo) { | ||
startFirefoxSession(testInfo); | ||
} | ||
|
||
@Test | ||
public void signInUnsuccessful() { | ||
driver.get("https://www.saucedemo.com/"); | ||
|
||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("locked_out_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
|
||
WebElement errorElement = driver.findElement(By.cssSelector("[data-test='error']")); | ||
Assertions.assertTrue(errorElement.getText().contains("Sorry, this user has been locked out"), | ||
"Error Not Found"); | ||
} | ||
|
||
@Test | ||
public void signInSuccessful() { | ||
driver.get("https://www.saucedemo.com/"); | ||
|
||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/inventory.html", | ||
driver.getCurrentUrl(), | ||
"Login Not Successful"); | ||
} | ||
|
||
@Test | ||
public void logout() throws InterruptedException { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.id("react-burger-menu-btn")).click(); | ||
Thread.sleep(1000); | ||
|
||
driver.findElement(By.id("logout_sidebar_link")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/", | ||
driver.getCurrentUrl(), | ||
"Logout Not Successful"); | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
selenium-examples/src/test/java/com/saucedemo/selenium/demo/CartTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.saucedemo.selenium.demo; | ||
|
||
import com.saucedemo.selenium.TestBase; | ||
import org.junit.jupiter.api.*; | ||
import org.openqa.selenium.By; | ||
|
||
public class CartTest extends TestBase { | ||
|
||
@BeforeEach | ||
public void setup(TestInfo testInfo) { | ||
startFirefoxSession(testInfo); | ||
} | ||
|
||
@Test | ||
public void addFromProductPage() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
|
||
driver.findElement(By.id("item_1_title_link")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-bolt-t-shirt']")).click(); | ||
|
||
Assertions.assertEquals("1", | ||
driver.findElement(By.className("shopping_cart_badge")).getText(), | ||
"Item not correctly added to cart"); | ||
} | ||
|
||
@Test | ||
public void removeFromProductPage() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.id("item_1_title_link")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-bolt-t-shirt']")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='remove-sauce-labs-bolt-t-shirt']")).click(); | ||
|
||
Assertions.assertTrue(driver.findElements(By.className("shopping_cart_badge")).isEmpty(), | ||
"Item not correctly removed from cart"); | ||
} | ||
|
||
@Test | ||
public void addFromInventoryPage() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-onesie']")).click(); | ||
|
||
Assertions.assertEquals("1", | ||
driver.findElement(By.className("shopping_cart_badge")).getText()); | ||
} | ||
|
||
@Test | ||
public void removeFromInventoryPage() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-bike-light']")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='remove-sauce-labs-bike-light']")).click(); | ||
|
||
Assertions.assertTrue(driver.findElements(By.className("shopping_cart_badge")).isEmpty(), | ||
"Shopping Cart is not empty"); | ||
} | ||
|
||
@Test | ||
public void removeFromCartPage() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-backpack']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='remove-sauce-labs-backpack']")).click(); | ||
|
||
Assertions.assertTrue(driver.findElements(By.className("shopping_cart_badge")).isEmpty(), | ||
"Shopping Cart is not empty"); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
selenium-examples/src/test/java/com/saucedemo/selenium/demo/CheckoutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.saucedemo.selenium.demo; | ||
|
||
import com.saucedemo.selenium.TestBase; | ||
import org.junit.jupiter.api.*; | ||
import org.openqa.selenium.By; | ||
|
||
public class CheckoutTest extends TestBase { | ||
|
||
@BeforeEach | ||
public void setup(TestInfo testInfo) { | ||
startFirefoxSession(testInfo); | ||
} | ||
|
||
|
||
@Test | ||
public void badInfo() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-onesie']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='checkout']")).click(); | ||
|
||
driver.findElement(By.cssSelector("input[data-test='continue']")).click(); | ||
|
||
Assertions.assertTrue(driver.findElement(By.cssSelector("input[data-test='firstName']")).getAttribute("class").contains("error"), | ||
"Expected error not found on page"); | ||
} | ||
|
||
@Test | ||
public void goodInfo() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-onesie']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='checkout']")).click(); | ||
|
||
driver.findElement(By.cssSelector("input[data-test='firstName']")).sendKeys("Luke"); | ||
driver.findElement(By.cssSelector("input[data-test='lastName']")).sendKeys("Perry"); | ||
driver.findElement(By.cssSelector("input[data-test='postalCode']")).sendKeys("90210"); | ||
|
||
driver.findElement(By.cssSelector("input[data-test='continue']")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/checkout-step-two.html", | ||
driver.getCurrentUrl(), | ||
"Information Submission Unsuccessful"); | ||
} | ||
|
||
@Test | ||
public void completeCheckout() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-onesie']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='checkout']")).click(); | ||
driver.findElement(By.cssSelector("input[data-test='firstName']")).sendKeys("Luke"); | ||
driver.findElement(By.cssSelector("input[data-test='lastName']")).sendKeys("Perry"); | ||
driver.findElement(By.cssSelector("input[data-test='postalCode']")).sendKeys("90210"); | ||
driver.findElement(By.cssSelector("input[data-test='continue']")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='finish']")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/checkout-complete.html", driver.getCurrentUrl()); | ||
|
||
Assertions.assertTrue(driver.findElement(By.className("complete-text")).isDisplayed()); | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
selenium-examples/src/test/java/com/saucedemo/selenium/demo/LoginTest.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
selenium-examples/src/test/java/com/saucedemo/selenium/demo/NavigationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package com.saucedemo.selenium.demo; | ||
|
||
import com.saucedemo.selenium.TestBase; | ||
import org.junit.jupiter.api.*; | ||
import org.openqa.selenium.By; | ||
|
||
public class NavigationTest extends TestBase { | ||
|
||
@BeforeEach | ||
public void setup(TestInfo testInfo) { | ||
startFirefoxSession(testInfo); | ||
} | ||
|
||
@Test | ||
public void cancelFromCart() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='continue-shopping']")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/inventory.html", driver.getCurrentUrl()); | ||
} | ||
|
||
@Test | ||
public void cancelFromInfoPage() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-onesie']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='checkout']")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='cancel']")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/cart.html", driver.getCurrentUrl()); | ||
} | ||
|
||
@Test | ||
public void cancelFromCheckoutPage() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-onesie']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='checkout']")).click(); | ||
driver.findElement(By.cssSelector("input[data-test='firstName']")).sendKeys("Luke"); | ||
driver.findElement(By.cssSelector("input[data-test='lastName']")).sendKeys("Perry"); | ||
driver.findElement(By.cssSelector("input[data-test='postalCode']")).sendKeys("90210"); | ||
driver.findElement(By.cssSelector("input[data-test='continue']")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='cancel']")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/inventory.html", driver.getCurrentUrl()); | ||
} | ||
|
||
@Test | ||
public void startCheckout() { | ||
driver.get("https://www.saucedemo.com/"); | ||
driver.findElement(By.cssSelector("input[data-test='username']")).sendKeys("standard_user"); | ||
driver.findElement(By.cssSelector("input[data-test='password']")).sendKeys("secret_sauce"); | ||
driver.findElement(By.cssSelector("input[data-test='login-button']")).click(); | ||
driver.findElement(By.cssSelector("button[data-test='add-to-cart-sauce-labs-onesie']")).click(); | ||
driver.findElement(By.className("shopping_cart_link")).click(); | ||
|
||
driver.findElement(By.cssSelector("button[data-test='checkout']")).click(); | ||
|
||
Assertions.assertEquals("https://www.saucedemo.com/checkout-step-one.html", driver.getCurrentUrl()); | ||
} | ||
} |