Advertisement
darfoo

Untitled

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