Advertisement
Raizekas

Untitled

Apr 8th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.18 KB | None | 0 0
  1. package pirmi.testai;
  2.  
  3. import config.SeleniumValdymas;
  4. import nuorodos.SeleniumNuorodos;
  5. import org.junit.Before;
  6. import org.junit.jupiter.api.BeforeEach;
  7. import org.junit.jupiter.api.DisplayName;
  8. import org.junit.jupiter.api.Test;
  9. import org.openqa.selenium.By;
  10. import org.openqa.selenium.WebDriver;
  11. import org.openqa.selenium.WebElement;
  12. import org.openqa.selenium.support.ui.ExpectedConditions;
  13. import org.openqa.selenium.support.ui.WebDriverWait;
  14.  
  15. import static org.junit.jupiter.api.Assertions.assertEquals;
  16.  
  17. public class SeleniumFormosIvedimasTest
  18. {
  19. WebDriver driver;
  20. WebDriverWait wait;
  21.  
  22. @BeforeEach
  23. public void init()
  24. {
  25. SeleniumValdymas seleniumValdymas = new SeleniumValdymas();
  26. driver = seleniumValdymas.initChromeDriver();
  27. wait = seleniumValdymas.initDesimtSekundziu();
  28. }
  29.  
  30. @Test
  31. @DisplayName("Pradinio tinklalapio nurodos tikrinimas")
  32. public void testuotiTitulinioImgNuoroda()
  33. {
  34. driver.get(SeleniumNuorodos.getPirmoPuslapioHome());
  35. WebElement logo = driver.findElement(By.cssSelector("#header_logo a"));
  36. String logoNuoroda = logo.getAttribute("href");
  37.  
  38. assertEquals(SeleniumNuorodos.getPirmoPuslapioBase(), logoNuoroda, "Logotipo nuoroda nėra į pradinį puslapį");
  39. }
  40.  
  41.  
  42. @Test
  43. @DisplayName("Prekių įdėjimo į krepšelį tikrinimas")
  44. public void testuotiPrekiuIdejima()
  45. {
  46. driver.get(SeleniumNuorodos.getPirmoPuslapioHome());
  47. // driver.manage().window().maximize();
  48. WebElement pirmosPrekesAddToCartMygtukas = driver.findElement(By.cssSelector("#homefeatured > .ajax_block_product:nth-child(2) .button:nth-child(1) > span"));
  49.  
  50. WebElement pirmosPrekesContinueShopping;
  51.  
  52. WebElement antrosPrekesAddToCart;
  53. WebElement antrosPrekesCheckout;
  54.  
  55. WebElement pirmosPrekesCheckoutName;
  56. WebElement pirmosPrekesCheckoutSku;
  57. WebElement pirmosPrekesCheckoutPrice;
  58.  
  59. pirmosPrekesAddToCartMygtukas.click();
  60.  
  61. pirmosPrekesContinueShopping = driver.findElement(By.cssSelector(".continue > span"));
  62.  
  63. wait.until(ExpectedConditions.elementToBeClickable(pirmosPrekesContinueShopping));
  64. pirmosPrekesContinueShopping.click();
  65.  
  66. // Po pirmos prekės įdėjimo paspaudžiamas "Coninue shopping" mygtukas ir grįžtama į home puslapį, iš jo įdedame antrą prekę
  67. antrosPrekesAddToCart = driver.findElement(By.cssSelector("#homefeatured > .ajax_block_product:nth-child(6) .button:nth-child(1) > span"));
  68. antrosPrekesAddToCart.click();
  69.  
  70. antrosPrekesCheckout = driver.findElement(By.cssSelector(".button-container a"));
  71. wait.until(ExpectedConditions.elementToBeClickable(antrosPrekesCheckout));
  72. System.out.println(antrosPrekesCheckout.getAttribute("href"));
  73. antrosPrekesCheckout.click();
  74.  
  75. // Po antros prekės įdėjimo paspaudžiamas "Proceed to checkout" mygtukas ir nukeliama į prekių krepšelį, kuriame tikrinsime ar įdėtos teisingos prekės
  76. pirmosPrekesCheckoutName = driver.findElement(By.cssSelector(".product-name a"));
  77. System.out.println(pirmosPrekesCheckoutName.getText());
  78.  
  79. }
  80. }
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement