Last active
March 17, 2016 22:09
-
-
Save andidev/6c5dc8033c019e4c069d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.companyname</groupId> | |
<artifactId>projectname</artifactId> | |
<version>1.0.0-SNAPSHOT</version> | |
<dependencies> | |
<dependency> | |
<groupId>org.seleniumhq.selenium</groupId> | |
<artifactId>selenium-java</artifactId> | |
<version>2.53.0</version> | |
</dependency> | |
</dependencies> | |
</project> |
This file contains hidden or 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
import java.util.Arrays; | |
import java.util.Collection; | |
import static java.util.concurrent.TimeUnit.*; | |
import org.junit.After; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.junit.runners.Parameterized; | |
import org.junit.runners.Parameterized.Parameters; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.ie.InternetExplorerDriver; | |
import org.openqa.selenium.support.FindBy; | |
import org.openqa.selenium.support.PageFactory; | |
@RunWith(Parameterized.class) | |
public class WebDriverExampleTest { | |
WebDriver driver; | |
@Parameters | |
public static Collection<Object[]> data() { | |
return Arrays.asList(new Object[][]{ | |
{"Firefox"}, {"Chrome"}, {"InternetExplorer"} | |
}); | |
} | |
public WebDriverExampleTest(String browserName) { | |
if (browserName.equals("Firefox")) { | |
driver = new FirefoxDriver(); | |
} else if (browserName.equals("Chrome")) { | |
driver = new ChromeDriver(); | |
} else if (browserName.equals("InternetExplorer")) { | |
driver = new InternetExplorerDriver(); | |
} | |
PageFactory.initElements(driver, this); | |
} | |
@After | |
public void tearDown() { | |
driver.quit(); | |
} | |
@FindBy(name = "q") | |
WebElement queryInput; | |
@FindBy(name = "btnG") | |
WebElement searchButton; | |
@FindBy(id = "search") | |
WebElement searchResult; | |
@Test | |
public void searchGoogleForHelloWorldTest() throws InterruptedException { | |
driver.get("http://www.google.com"); | |
assert driver.getCurrentUrl().contains("google"); | |
queryInput.sendKeys("Hello World"); | |
searchButton.click(); | |
SECONDS.sleep(3); | |
assert searchResult.getText().contains("Hello World"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
mvn test -Dwebdriver.chrome.driver=path/to/chromedriver -Dwebdriver.ie.driver=path/to/iedriver
The test preforms a Google search for "Hello World" and then asserts that the search result contains the text "Hello World"