-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmazonTest.java
More file actions
42 lines (34 loc) · 1.17 KB
/
AmazonTest.java
File metadata and controls
42 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class AmazonTest {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "./drivers/chromedriver");
driver = new ChromeDriver();
driver.get("http://www.amazon.com/");
}
@After
public void tearDown() {
driver.quit();
}
@Test
public void testSearch() {
// I am in the amazon home page
WebElement input = driver.findElement(By.id("twotabsearchtextbox"));
input.sendKeys("Harry Potter");
WebElement searchIcon = driver.findElement(By.id("nav-search-submit-button"));
searchIcon.click();
// I am in a different page, which is the search result page
WebElement status = driver.findElement(By.cssSelector(
"#search > span > div > span > h1 > div > div.sg-col-14-of-20.sg-col.s-breadcrumb.sg-col-10-of-16.sg-col-6-of-12 > div > div > span:nth-child(1)"
));
assertTrue(status.getText().startsWith("1-16"));
}
}