Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TestLogin {
- WebDriver driver = new FirefoxDriver();
- WebDriverWait wait = new WebDriverWait(driver, 10);
- String url = "https://www.saucedemo.com/index.html";
- @Test
- public void signIn() {
- // 1. Go to url
- driver.get(url);
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user-name")));
- // 2. Entering account credentials
- WebElement usernameField = driver.findElement(By.id("user-name"));
- WebElement passwordField = driver.findElement(By.id("password"));
- usernameField.sendKeys("standard_user");
- passwordField.sendKeys("secret_sauce");
- // 3. Clicking login button
- driver.findElement(By.cssSelector("input.btn_action")).click();
- // 4. Verifying that user is logged in
- String productsHeader = driver.findElement(By.cssSelector("div.product_label")).getText();
- System.out.println(productsHeader);
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("product_label")));
- Assert.assertTrue("User should be signed in", productsHeader.contains("Products"));
- // 5. Logging out
- driver.findElement(By.className("bm-burger-button")).click();
- driver.findElement(By.id("logout_sidebar_link")).click();
- // 6. Verify that user is signed out
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password")));
- System.out.println(passwordField.isDisplayed());
- // String passwordId = "password";
- //Assert.assertTrue("User should be logged out", driver.findElement(By.id("password")).isPresent());
- }
- @Test
- public void addToCart() {
- // 1. Go to url
- driver.get(url);
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user-name")));
- // 2. Entering account credentials
- WebElement usernameField = driver.findElement(By.id("user-name"));
- WebElement passwordField = driver.findElement(By.id("password"));
- usernameField.sendKeys("standard_user");
- passwordField.sendKeys("secret_sauce");
- // 3. Clicking login button
- driver.findElement(By.cssSelector("input.btn_action")).click();
- // 4. Adding a product to cart
- driver.findElement(By.xpath("//div[@id='inventory_container']//button[@class='btn_primary btn_inventory']")).click();
- // 5. Navigating to cart
- driver.findElement(By.xpath("//div[@id='shopping_cart_container']//a[@class='shopping_cart_link fa-layers fa-fw']")).click();
- // 6. Verifying that cart has a product added
- String productCartQuantity = driver.findElement(By.xpath("//div[@class='cart_quantity']")).getText();
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='cart_quantity']")));
- Assert.assertTrue("There should be a quantity for a product via cart", productCartQuantity != "0");
- @After
- public void tearDown() {
- driver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement