EChebanenko

Untitled

Nov 10th, 2020 (edited)
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. import org.openqa.selenium.By;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.WebElement;
  4. import org.openqa.selenium.chrome.ChromeDriver;
  5. import org.openqa.selenium.support.ui.WebDriverWait;
  6. import org.testng.annotations.AfterMethod;
  7. import org.testng.annotations.BeforeMethod;
  8. import org.testng.annotations.Test;
  9.  
  10. import java.util.List;
  11. import java.util.concurrent.TimeUnit;
  12.  
  13. public class RozetkaHW31 {
  14.     WebDriver driver;
  15.     WebDriverWait wait;
  16.  
  17.     @BeforeMethod
  18.     public void start() {
  19.         driver = new ChromeDriver();
  20.         wait = (new WebDriverWait(driver, 5));
  21.         driver.manage().window().maximize();
  22.         driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
  23.         driver.get("https://rozetka.com.ua");
  24.  
  25.     }
  26.  
  27.  
  28.     @Test
  29.     public void RozetkaNoteBook() {
  30.  
  31.         WebElement noteBooksAndComps = driver.findElement(By.xpath("//a[@class='menu-categories__link']"));
  32.         noteBooksAndComps.click();
  33.         WebElement noteBooks = driver.findElement(By.xpath("//a[@class='menu__link menu__link_background_gray']"));
  34.         noteBooks.click();
  35.         WebElement addToBasket = driver.findElement(By.xpath("//button[@class='buy-button goods-tile__buy-button']"));
  36.         addToBasket.click();
  37.  
  38.         List<WebElement> basket = driver.findElements(By.xpath("//div[@class='js-rz-cart']//span[@class='header-actions__button-counter']"));
  39.  
  40.         WebElement inBasket = driver.findElement(By.xpath("//div[@class='js-rz-cart']"));
  41.         inBasket.click();
  42.  
  43.         if (basket.size() == 1) {
  44.             System.out.println("В корзину добавился товар");
  45.         } else {
  46.             System.out.println("В корзине ничего нет");
  47.         }
  48.  
  49.         WebElement title = driver.findElement(By.xpath("//a[@class='cart-product__title']"));
  50.         String titleText = title.getAttribute("title");
  51.         if (titleText.equals("Ноутбук Acer Swift 3 SF314-58-52DU (NX.HPMEU.00L) Sparkly Silver Суперцена!!! ")) {
  52.             System.out.println("Нужный товар в корзине");
  53.         } else {
  54.             System.out.println("В корзине не тот товар");
  55.         }
  56.  
  57.     }
  58.  
  59.  
  60.     @AfterMethod
  61.     public void after() {
  62.         driver.quit();
  63.     }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment