Skip to content

Commit

Permalink
09 - multiple files
Browse files Browse the repository at this point in the history
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
andrewmkrug committed Oct 27, 2015
1 parent 5281dd0 commit 24a39e4
Show file tree
Hide file tree
Showing 12 changed files with 723 additions and 0 deletions.
76 changes: 76 additions & 0 deletions 07-use-a-page-object/java/example.java
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 09-use-a-base-page-object/java/multipleFileExample/Base.java
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);
}
}
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"));
}
}
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();
}
}

123 changes: 123 additions & 0 deletions 09-use-a-base-page-object/java/onePageExample.java
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);
}
}
48 changes: 48 additions & 0 deletions 10-retry-test-actions/java/example.java
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;
}
}
}
Loading

0 comments on commit 24a39e4

Please sign in to comment.