Skip to content

Commit

Permalink
add maven/gradle tasks for running tests in all possible browsers
Browse files Browse the repository at this point in the history
  • Loading branch information
asolntsev committed Jul 13, 2018
1 parent 45cf2ea commit 3feb5bb
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 12 deletions.
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ repositories {
dependencies {
testCompile 'junit:junit:4.12'
testCompile 'org.hamcrest:hamcrest-all:1.3'
testCompile 'com.codeborne:selenide:4.10.01'
testCompile 'org.seleniumhq.selenium:selenium-safari-driver:3.8.1'
testCompile 'com.codeborne:selenide:4.12.2'
testCompile('org.seleniumhq.selenium:selenium-safari-driver:3.13.0') { transitive = false }
testCompile('org.seleniumhq.selenium:selenium-htmlunit-driver:2.52.0') { transitive = false }
testCompile('com.codeborne:phantomjsdriver:1.4.4') { transitive = false }
}

task libs(type: Sync) {
Expand All @@ -48,10 +50,12 @@ tasks.withType(Test).all { testTask ->

task chrome(type: Test) {
systemProperties['selenide.browser'] = 'chrome'
systemProperties['selenide.headless'] = 'true'
}

task firefox(type: Test) {
systemProperties['selenide.browser'] = 'firefox'
systemProperties['selenide.headless'] = 'true'
}

task ie(type: Test) {
Expand Down
3 changes: 1 addition & 2 deletions google.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/.gradle/4.4.1" />
<excludeFolder url="file://$MODULE_DIR$/.gradle/buildOutputCleanup" />
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
<excludeFolder url="file://$MODULE_DIR$/build" />
<excludeFolder url="file://$MODULE_DIR$/target" />
</content>
Expand Down
20 changes: 17 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.20.1</version>
<version>2.22.0</version>
</plugin>
</plugins>
</build>
Expand All @@ -29,13 +29,25 @@
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>4.10</version>
<version>4.12.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>phantomjsdriver</artifactId>
<version>1.4.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-safari-driver</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-htmlunit-driver</artifactId>
<version>2.52.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -54,6 +66,7 @@
</excludes>
<systemPropertyVariables>
<selenide.browser>chrome</selenide.browser>
<selenide.headless>true</selenide.headless>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down Expand Up @@ -125,6 +138,7 @@
</excludes>
<systemPropertyVariables>
<selenide.browser>firefox</selenide.browser>
<selenide.headless>true</selenide.headless>
</systemPropertyVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,48 @@
package org.selenide.examples.google.classic_page_object;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.phantomjs.PhantomJSDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.support.PageFactory;

import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.junit.Assert.assertThat;

public class GoogleTest {
WebDriver driver;

@Before
public void setUp() {
driver = "chrome".equals(System.getProperty("selenide.browser")) ?
new ChromeDriver() : new FirefoxDriver();
String currentBrowser = System.getProperty("selenide.browser", "firefox");
if ("chrome".equals(currentBrowser)) {
WebDriverManager.chromedriver().setup();
driver = new ChromeDriver();
} else if ("firefox".equals(currentBrowser)) {
WebDriverManager.firefoxdriver().setup();
driver = new FirefoxDriver();
} else if ("phantomjs".equals(currentBrowser)) {
WebDriverManager.phantomjs().setup();
driver = new PhantomJSDriver();
} else if ("safari".equals(currentBrowser)) {
driver = new SafariDriver();
} else if ("edge".equals(currentBrowser)) {
WebDriverManager.edgedriver().setup();
driver = new EdgeDriver();
} else if ("ie".equals(currentBrowser)) {
WebDriverManager.iedriver().setup();
driver = new InternetExplorerDriver();
} else if ("htmlunit".equals(currentBrowser)) {
driver = new HtmlUnitDriver();
}
}

@After
Expand All @@ -28,9 +54,9 @@ public void tearDown() {

@Test
public void userCanSearch() {
driver.get("http://www.google.com/");
driver.get("https://www.google.com/ncr");
GooglePage page = PageFactory.initElements(driver, GooglePage.class);
SearchResultsPage results = page.searchFor("Selenide");
assertTrue(results.getResults().get(0).getText().startsWith("Selenide: concise UI tests in Java"));
assertThat(results.getResults().get(0).getText(), startsWith("Selenide: concise UI tests in Java"));
}
}

0 comments on commit 3feb5bb

Please sign in to comment.