Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.junit.AfterClass;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import org.junit.Test;
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.chrome.ChromeDriver;
- import org.openqa.selenium.support.ui.ExpectedConditions;
- import org.openqa.selenium.support.ui.WebDriverWait;
- /**
- * @author Niranjan
- *
- */
- public class AmazonTestCase {
- static ChromeDriver driver = null;
- static WebDriverWait wait = null;
- /**
- * @throws java.lang.Exception
- */
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- // Replace the path of chrome driver according to your setup
- System.setProperty("webdriver.chrome.driver", "/home/mtrue/personalworkspace/Selenium/lib/webdriver/chromedriver");
- driver = new ChromeDriver();
- }
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- driver.get("http://wwww.amazon.com");
- }
- @Test
- public void testAddToCart() {
- driver.get("http://wwww.amazon.com");
- driver.findElementById("nav-your-amazon").click();
- //Find user name
- //wait.until(ExpectedConditions.invisibilityOfElementLocated(driver.findElementById("app-email")));
- WebElement userName = driver.findElementById("app-email");
- //Fill user name
- userName.sendKeys("darfoo@weirfish.net");
- //Find password
- WebElement password = driver.findElementById("app-password");
- //Fill password
- password.sendKeys("password");
- driver.findElementByLinkText("Black Friday Deals").click();
- wait = new WebDriverWait(driver, 2);
- driver.findElementById("a-autoid-1-announce").click();
- wait = new WebDriverWait(driver, 2);
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("nav-cart")));
- driver.findElementById("nav-cart").click();
- wait = new WebDriverWait(driver, 2);
- wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("sc-active-cart")));
- }
- @AfterClass
- public static void CleanUp(){
- driver.quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement