forked from fruitime/deliverable3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearchTest.java
55 lines (42 loc) · 1.52 KB
/
SearchTest.java
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
43
44
45
46
47
48
49
50
51
52
53
54
package deliverable3;
import static org.junit.Assert.*;
import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.By.ById;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class SearchTest {
static WebDriver driver = new FirefoxDriver();
@Before
public void setUp() throws Exception{
driver.get("http://www.amazon.com/");
}
@Test
public void testValidSearch(){
driver.findElement(By.name("field-keywords")).sendKeys("cat food");
WebElement searchDiv1= driver.findElement(By.id("nav-search"));
WebElement searchDiv2 = searchDiv1.findElement(By.className("nav-right"));
WebElement submit = searchDiv2.findElement(By.className("nav-input"));
submit.click();
try {
WebElement message = driver.findElement(By.id("s-result-count"));
assertTrue(message.isDisplayed());
} catch (NoSuchElementException nseex) {
fail();
}
}
@Test
public void testInValidSearch(){
driver.findElement(By.name("field-keywords")).sendKeys("nnknlnnfnsadlnfaengvdlngartee");
WebElement searchDiv1= driver.findElement(By.id("nav-search"));
WebElement searchDiv2 = searchDiv1.findElement(By.className("nav-right"));
WebElement submit = searchDiv2.findElement(By.className("nav-input"));
submit.click();
try {
WebElement noResultsTitle= driver.findElement(By.id("noResultsTitle"));
assertTrue(noResultsTitle.isDisplayed());
} catch (NoSuchElementException nseex) {
fail();
}
}
}