Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. public class TestLogin {
  2. WebDriver driver = new FirefoxDriver();
  3. WebDriverWait wait = new WebDriverWait(driver, 10);
  4. String url = "https://www.saucedemo.com/index.html";
  5.  
  6. @Test
  7. public void signIn() {
  8. // 1. Go to url
  9. driver.get(url);
  10. wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user-name")));
  11.  
  12. // 2. Entering account credentials
  13. WebElement usernameField = driver.findElement(By.id("user-name"));
  14. WebElement passwordField = driver.findElement(By.id("password"));
  15. usernameField.sendKeys("standard_user");
  16. passwordField.sendKeys("secret_sauce");
  17.  
  18. // 3. Clicking login button
  19. driver.findElement(By.cssSelector("input.btn_action")).click();
  20.  
  21. // 4. Verifying that user is logged in
  22. String productsHeader = driver.findElement(By.cssSelector("div.product_label")).getText();
  23. System.out.println(productsHeader);
  24. wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("product_label")));
  25. Assert.assertTrue("User should be signed in", productsHeader.contains("Products"));
  26.  
  27. // 5. Logging out
  28. driver.findElement(By.className("bm-burger-button")).click();
  29. driver.findElement(By.id("logout_sidebar_link")).click();
  30.  
  31. // 6. Verify that user is signed out
  32. wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("password")));
  33. System.out.println(passwordField.isDisplayed());
  34. // String passwordId = "password";
  35. //Assert.assertTrue("User should be logged out", driver.findElement(By.id("password")).isPresent());
  36. }
  37.  
  38. @Test
  39. public void addToCart() {
  40. // 1. Go to url
  41. driver.get(url);
  42. wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user-name")));
  43.  
  44. // 2. Entering account credentials
  45. WebElement usernameField = driver.findElement(By.id("user-name"));
  46. WebElement passwordField = driver.findElement(By.id("password"));
  47. usernameField.sendKeys("standard_user");
  48. passwordField.sendKeys("secret_sauce");
  49.  
  50. // 3. Clicking login button
  51. driver.findElement(By.cssSelector("input.btn_action")).click();
  52.  
  53. // 4. Adding a product to cart
  54. driver.findElement(By.xpath("//div[@id='inventory_container']//button[@class='btn_primary btn_inventory']")).click();
  55.  
  56. // 5. Navigating to cart
  57. driver.findElement(By.xpath("//div[@id='shopping_cart_container']//a[@class='shopping_cart_link fa-layers fa-fw']")).click();
  58.  
  59. // 6. Verifying that cart has a product added
  60. String productCartQuantity = driver.findElement(By.xpath("//div[@class='cart_quantity']")).getText();
  61. wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='cart_quantity']")));
  62.  
  63. Assert.assertTrue("There should be a quantity for a product via cart", productCartQuantity != "0");
  64.  
  65. @After
  66. public void tearDown() {
  67. driver.quit();
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement