|
1 | 1 | import org.openqa.selenium.By;
|
2 | 2 | import org.openqa.selenium.WebDriver;
|
3 | 3 | import org.openqa.selenium.WebElement;
|
4 |
| -import org.openqa.selenium.firefox.FirefoxDriver; |
5 |
| -import org.openqa.selenium.support.ui.ExpectedCondition; |
6 |
| -import org.openqa.selenium.support.ui.WebDriverWait; |
| 4 | +import org.openqa.selenium.chrome.ChromeDriver; |
| 5 | +import org.openqa.selenium.support.ui.*; |
7 | 6 | import org.testng.annotations.Test;
|
8 | 7 |
|
| 8 | +import static org.testng.AssertJUnit.assertEquals; |
| 9 | + |
9 | 10 | public class CoverosIT {
|
10 | 11 |
|
11 | 12 | @Test
|
12 | 13 | public void seleniumSearch() {
|
13 | 14 | //for linux/mac installations
|
14 |
| -// System.setProperty("webdriver.gecko.driver", "lib/geckodriver"); |
| 15 | +// System.setProperty("webdriver.chrome.driver", "lib/chromedriver"); |
15 | 16 | //for windows installations
|
16 |
| -// System.setProperty("webdriver.gecko.driver", "lib/geckodriver.exe"); |
17 |
| - // Create a new instance of the Firefox driver |
| 17 | +// System.setProperty("webdriver.gecko.driver", "lib/chromedriver.exe"); |
| 18 | + // Create a new instance of the Chrome driver |
18 | 19 | // Notice that the remainder of the code relies on the interface,
|
19 | 20 | // not the implementation.
|
20 |
| - WebDriver driver = new FirefoxDriver(); |
| 21 | + WebDriver driver = new ChromeDriver(); |
21 | 22 |
|
22 | 23 | // And now use this to visit Google
|
23 | 24 | driver.get("https://www.coveros.com");
|
24 | 25 | // Alternatively the same thing can be done like this
|
25 | 26 | // driver.navigate().to("https://www.coveros.com");
|
26 | 27 |
|
27 | 28 | // Find the text input element by its name
|
28 |
| - WebElement element = driver.findElement(By.id("s")); |
| 29 | + WebElement searchBox = driver.findElement(By.id("s")); |
29 | 30 |
|
30 | 31 | // Enter something to search for
|
31 |
| - element.sendKeys("selenium"); |
| 32 | + searchBox.sendKeys("selenium"); |
32 | 33 |
|
33 | 34 | // Now submit the form. WebDriver will find the form for us from the element
|
34 |
| - element.submit(); |
35 |
| - |
36 |
| - // Check the title of the page |
37 |
| - System.out.println("Page title is: " + driver.getTitle()); |
| 35 | + searchBox.submit(); |
38 | 36 |
|
39 | 37 | // Coveros's search is rendered dynamically with JavaScript.
|
40 | 38 | // Wait for the page to load, timeout after 10 seconds
|
41 |
| - (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() { |
42 |
| - public Boolean apply(WebDriver d) { |
43 |
| - return d.getTitle().startsWith("You searched for"); |
44 |
| - } |
45 |
| - }); |
46 |
| - |
47 |
| - // Should see: "cheese! - Google Search" |
48 |
| - System.out.println("Page title is: " + driver.getTitle()); |
| 39 | + new WebDriverWait(driver, 10) |
| 40 | + .until(ExpectedConditions.visibilityOfElementLocated(By.className("header-blog"))); |
49 | 41 |
|
| 42 | + // Should see: "You searched for selenified - Coveros" |
| 43 | + assertEquals(driver.getTitle(), "You searched for selenium - Coveros"); |
50 | 44 |
|
51 | 45 | //Close the browser
|
52 | 46 | driver.quit();
|
|
0 commit comments