Skip to content

Commit 8a7922b

Browse files
author
Max Saperstone
committed
Updating to use better locators and variable names
1 parent c43bad6 commit 8a7922b

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

selenified/src/test/java/CoverosIT.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ public void seleniumSearch() {
1919
// use this object to manipulate the app
2020
App app = this.apps.get();
2121
// identify our elements
22-
Element search = app.newElement(Locator.ID, "s");
22+
Element searchBox = app.newElement(Locator.ID, "s");
2323
// perform the search
24-
search.type("selenium");
25-
search.submit();
26-
// wait for the search to run
27-
app.waitFor().titleEquals("You searched for selenium - Coveros");
28-
app.azzert().titleEquals("You searched for selenium - Coveros");
24+
searchBox.type("selenified");
25+
searchBox.submit();
26+
// wait for some search results to come back
27+
app.newElement(Locator.CLASSNAME, "header-blog").waitForState().displayed();
28+
// ensure the title shows what we expect
29+
app.azzert().titleEquals("You searched for selenified - Coveros");
2930
// close out the test
3031
finish();
3132
}

selenium/src/test/java/CoverosIT.java

+15-21
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,46 @@
11
import org.openqa.selenium.By;
22
import org.openqa.selenium.WebDriver;
33
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.*;
76
import org.testng.annotations.Test;
87

8+
import static org.testng.AssertJUnit.assertEquals;
9+
910
public class CoverosIT {
1011

1112
@Test
1213
public void seleniumSearch() {
1314
//for linux/mac installations
14-
// System.setProperty("webdriver.gecko.driver", "lib/geckodriver");
15+
// System.setProperty("webdriver.chrome.driver", "lib/chromedriver");
1516
//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
1819
// Notice that the remainder of the code relies on the interface,
1920
// not the implementation.
20-
WebDriver driver = new FirefoxDriver();
21+
WebDriver driver = new ChromeDriver();
2122

2223
// And now use this to visit Google
2324
driver.get("https://www.coveros.com");
2425
// Alternatively the same thing can be done like this
2526
// driver.navigate().to("https://www.coveros.com");
2627

2728
// Find the text input element by its name
28-
WebElement element = driver.findElement(By.id("s"));
29+
WebElement searchBox = driver.findElement(By.id("s"));
2930

3031
// Enter something to search for
31-
element.sendKeys("selenium");
32+
searchBox.sendKeys("selenium");
3233

3334
// 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();
3836

3937
// Coveros's search is rendered dynamically with JavaScript.
4038
// 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")));
4941

42+
// Should see: "You searched for selenified - Coveros"
43+
assertEquals(driver.getTitle(), "You searched for selenium - Coveros");
5044

5145
//Close the browser
5246
driver.quit();

0 commit comments

Comments
 (0)