Advertisement
darfoo

Untitled

Nov 16th, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import org.junit.AfterClass;
  2. import org.junit.Assert;
  3. import org.junit.Before;
  4. import org.junit.BeforeClass;
  5. import org.junit.Test;
  6. import org.openqa.selenium.By;
  7. import org.openqa.selenium.WebElement;
  8. import org.openqa.selenium.chrome.ChromeDriver;
  9. import org.openqa.selenium.support.ui.ExpectedConditions;
  10. import org.openqa.selenium.support.ui.WebDriverWait;
  11. /**
  12. * @author Niranjan
  13. *
  14. */
  15. public class AmazonTestCase {
  16. static ChromeDriver driver = null;
  17. static WebDriverWait wait = null;
  18.  
  19. /**
  20. * @throws java.lang.Exception
  21. */
  22. @BeforeClass
  23. public static void setUpBeforeClass() throws Exception {
  24. // Replace the path of chrome driver according to your setup
  25. System.setProperty("webdriver.chrome.driver", "/home/mtrue/personalworkspace/Selenium/lib/webdriver/chromedriver");
  26.  
  27. driver = new ChromeDriver();
  28. }
  29. /**
  30. * @throws java.lang.Exception
  31. */
  32. @Before
  33. public void setUp() throws Exception {
  34. driver.get("http://wwww.amazon.com");
  35. }
  36. @Test
  37. public void testAddToCart() {
  38. driver.get("http://wwww.amazon.com");
  39. driver.findElementById("nav-your-amazon").click();
  40.  
  41.  
  42. //Find user name
  43. //wait.until(ExpectedConditions.invisibilityOfElementLocated(driver.findElementById("app-email")));
  44. WebElement userName = driver.findElementById("app-email");
  45.  
  46. //Fill user name
  47. userName.sendKeys("darfoo@weirfish.net");
  48. //Find password
  49. WebElement password = driver.findElementById("app-password");
  50. //Fill password
  51. password.sendKeys("password");
  52.  
  53. driver.findElementByLinkText("Black Friday Deals").click();
  54. wait = new WebDriverWait(driver, 2);
  55.  
  56. driver.findElementById("a-autoid-1-announce").click();
  57. wait = new WebDriverWait(driver, 2);
  58. wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("nav-cart")));
  59.  
  60.  
  61.  
  62.  
  63. driver.findElementById("nav-cart").click();
  64. wait = new WebDriverWait(driver, 2);
  65. wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("sc-active-cart")));
  66.  
  67.  
  68.  
  69.  
  70. }
  71.  
  72. @AfterClass
  73. public static void CleanUp(){
  74. driver.quit();
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement