forked from saucelabs-training/elemental-selenium-tips
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
10 - retry test actions 12 - opt out ab tests 16 - screenshot on failure 22 - locator strategy 23 - dynamic pages 25 - tables 40 - disabled elements
- Loading branch information
1 parent
5281dd0
commit 24a39e4
Showing
12 changed files
with
723 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
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.firefox.FirefoxDriver; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.ui.ExpectedCondition; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
/** | ||
* Created by andrew on 8/22/15. | ||
*/ | ||
|
||
public class GoogleSearchTest { | ||
|
||
WebDriver driver; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
driver = new FirefoxDriver(); | ||
} | ||
|
||
@Test | ||
public void workWithBasicAuthTest() { | ||
GoogleSearch google = new GoogleSearch(driver); | ||
google.searchFor("elemental selenium tips"); | ||
boolean result = google.searchResultPresent("Recieve a Free, Weekly tip"); | ||
assert (result == true); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
driver.quit(); | ||
} | ||
} | ||
|
||
class GoogleSearch { | ||
|
||
private final String BASE_URL = "http://www.google.com"; | ||
WebDriver driver; | ||
|
||
By searchBox = By.id("gbqfq"); | ||
By searchBoxSubmit = By.id("gbqfb"); | ||
By topSearchResult = By.cssSelector("#rso .g"); | ||
|
||
public GoogleSearch(WebDriver _driver) { | ||
this.driver = _driver; | ||
visit(); | ||
assert (verifyPage() == true); | ||
} | ||
|
||
public void visit() { | ||
driver.get(this.BASE_URL); | ||
} | ||
|
||
public void searchFor(String searchTerm) { | ||
driver.findElement(searchBox).clear(); | ||
driver.findElement(searchBox).sendKeys(searchTerm); | ||
driver.findElement(searchBoxSubmit).click(); | ||
} | ||
|
||
public boolean searchResultPresent(String searchResult) { | ||
waitFor(topSearchResult); | ||
return driver.findElement(topSearchResult).getText().contains(searchResult); | ||
} | ||
|
||
public void waitFor(By locator) { | ||
new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(locator)); | ||
} | ||
|
||
public boolean verifyPage() { | ||
return driver.getCurrentUrl().contains("Google"); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
09-use-a-base-page-object/java/multipleFileExample/Base.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package num9; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
import org.openqa.selenium.WebElement; | ||
import org.openqa.selenium.support.ui.ExpectedCondition; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
public class Base { | ||
|
||
private String BASE_URL; | ||
private final WebDriver driver; | ||
|
||
public Base(WebDriver _driver, String baseUrl) { | ||
this.driver = _driver; | ||
this.BASE_URL = baseUrl; | ||
} | ||
|
||
public void visit() { | ||
driver.get(BASE_URL); | ||
} | ||
|
||
public void visit(String url) { | ||
driver.get(BASE_URL + url); | ||
} | ||
|
||
public WebElement find(By locator) { | ||
return driver.findElement(locator); | ||
} | ||
|
||
public void clear(By locator) { | ||
find(locator).clear(); | ||
} | ||
|
||
public void type(By locator, String input) { | ||
find(locator).sendKeys(input); | ||
} | ||
|
||
public void clickOn(By locator) { | ||
find(locator).click(); | ||
} | ||
|
||
public ExpectedCondition displayed(By locator) { | ||
return ExpectedConditions.presenceOfElementLocated(locator); | ||
} | ||
|
||
public String textOf(By locator) { | ||
return find(locator).getText(); | ||
} | ||
|
||
public String title() { | ||
return driver.getCurrentUrl(); | ||
} | ||
|
||
public WebDriverWait waitFor() { | ||
return new WebDriverWait(driver, 5); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
09-use-a-base-page-object/java/multipleFileExample/GoogleSearch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package num9; | ||
|
||
import org.openqa.selenium.By; | ||
import org.openqa.selenium.WebDriver; | ||
|
||
public class GoogleSearch extends Base { | ||
|
||
By searchBox = By.id("gbqfq"); | ||
By searchBoxSubmit = By.id("gbqfb"); | ||
By topSearchResult = By.cssSelector("#rso .g"); | ||
|
||
public GoogleSearch(WebDriver _driver) { | ||
super(_driver, "http://www.google.com"); | ||
visit(); | ||
verifyPage(); | ||
} | ||
|
||
|
||
public void searchFor(String searchTerm) { | ||
clear(searchBox); | ||
type(searchBox, searchTerm); | ||
clickOn(searchBoxSubmit); | ||
} | ||
|
||
public boolean searchResultPresent(String searchResult) { | ||
waitFor().until(displayed(topSearchResult)); | ||
return textOf(topSearchResult).contains(searchResult); | ||
} | ||
|
||
|
||
public void verifyPage() { | ||
assert (title().contains("Google")); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
09-use-a-base-page-object/java/multipleFileExample/GoogleSearchTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package num9; | ||
|
||
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.firefox.FirefoxDriver; | ||
import org.openqa.selenium.support.ui.ExpectedCondition; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
/** | ||
* Created by andrew on 8/22/15. | ||
*/ | ||
|
||
public class GoogleSearchTest { | ||
|
||
WebDriver driver; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
driver = new FirefoxDriver(); | ||
} | ||
|
||
@Test | ||
public void workWithBasicAuthTest() { | ||
GoogleSearch google = new GoogleSearch(driver); | ||
google.searchFor("elemental selenium tips"); | ||
boolean result = google.searchResultPresent("Recieve a Free, Weekly tip"); | ||
assert (result); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
driver.quit(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
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.firefox.FirefoxDriver; | ||
import org.openqa.selenium.support.FindBy; | ||
import org.openqa.selenium.support.ui.ExpectedCondition; | ||
import org.openqa.selenium.support.ui.ExpectedConditions; | ||
import org.openqa.selenium.support.ui.WebDriverWait; | ||
|
||
import java.util.NoSuchElementException; | ||
|
||
/** | ||
* Created by andrew on 8/22/15. | ||
*/ | ||
|
||
public class GoogleSearchTest { | ||
|
||
WebDriver driver; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
driver = new FirefoxDriver(); | ||
} | ||
|
||
@Test | ||
public void workWithBasicAuthTest() { | ||
GoogleSearch google = new GoogleSearch(driver); | ||
google.searchFor("elemental selenium tips"); | ||
boolean result = google.searchResultPresent("Recieve a Free, Weekly tip"); | ||
assert (result); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
driver.quit(); | ||
} | ||
} | ||
|
||
public class GoogleSearch extends Base { | ||
|
||
WebDriver driver; | ||
|
||
By searchBox = By.id("gbqfq"); | ||
By searchBoxSubmit = By.id("gbqfb"); | ||
By topSearchResult = By.cssSelector("#rso .g"); | ||
|
||
public GoogleSearch(WebDriver _driver) { | ||
super(_driver, "http://www.google.com"); | ||
visit(); | ||
verifyPage(); | ||
} | ||
|
||
|
||
public void searchFor(String searchTerm) { | ||
clear(searchBox); | ||
type(searchBox, searchTerm); | ||
clickOn(searchBoxSubmit); | ||
} | ||
|
||
public boolean searchResultPresent(String searchResult) { | ||
waitFor().until(displayed(topSearchResult)); | ||
return textOf(topSearchResult).contains(searchResult); | ||
} | ||
|
||
|
||
public void verifyPage() { | ||
assert (title().contains("Google")); | ||
} | ||
} | ||
|
||
class Base { | ||
|
||
private String BASE_URL; | ||
private final WebDriver driver; | ||
|
||
public Base(WebDriver _driver, String baseUrl) { | ||
this.driver = _driver; | ||
this.BASE_URL = baseUrl; | ||
} | ||
|
||
public void visit() { | ||
driver.get(BASE_URL); | ||
} | ||
|
||
public void visit(String url) { | ||
driver.get(BASE_URL + url); | ||
} | ||
|
||
public WebElement find(By locator) { | ||
return driver.findElement(locator); | ||
} | ||
|
||
public void clear(By locator) { | ||
find(locator).clear(); | ||
} | ||
|
||
public void type(By locator, String input) { | ||
find(locator).sendKeys(input); | ||
} | ||
|
||
public void clickOn(By locator) { | ||
find(locator).click(); | ||
} | ||
|
||
public ExpectedCondition displayed(By locator) { | ||
return ExpectedConditions.presenceOfElementLocated(locator); | ||
} | ||
|
||
public String textOf(By locator) { | ||
return find(locator).getText(); | ||
} | ||
|
||
public String title() { | ||
return driver.getCurrentUrl(); | ||
} | ||
|
||
public WebDriverWait waitFor() { | ||
return new WebDriverWait(driver, 5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package num10; | ||
|
||
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.firefox.FirefoxDriver; | ||
|
||
/** | ||
* Created by andrew on 8/22/15. | ||
*/ | ||
public class example { | ||
public class WorkWithBasicAuth { | ||
WebDriver driver; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
driver = new FirefoxDriver(); | ||
} | ||
|
||
@Test | ||
public void RetryTestActions() { | ||
driver.get("http://the-internet.herokuapp.com/notification_message"); | ||
assert retryIfNotificationMessageContains("please try again"); | ||
} | ||
|
||
@After | ||
public void tearDown() throws Exception { | ||
driver.quit(); | ||
} | ||
|
||
|
||
public String getNotificationMessage() { | ||
return driver.findElement(By.id("flash")).getText(); | ||
} | ||
|
||
public boolean retryIfNotificationMessageContains(String message) { | ||
for (int count = 0; count < 3; count++) { | ||
if (getNotificationMessage().contains(message)) | ||
driver.navigate().refresh(); | ||
else | ||
return true; | ||
} | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.