aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2017-04-16 20:34:21 +0200
committerMartin Stockhammer <martin_s@apache.org>2017-04-16 20:34:21 +0200
commitc29a3426db4dbc9ec504042058f0ed8409f7ed81 (patch)
treed32dfb5bc23ceaf6b93c580cb3afcd2b47880e89
parentf7b57a974d1c68878c562ef365dd947b7407c496 (diff)
downloadarchiva-c29a3426db4dbc9ec504042058f0ed8409f7ed81.tar.gz
archiva-c29a3426db4dbc9ec504042058f0ed8409f7ed81.zip
Changing webdriver tests to remotewebdriver
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test/pom.xml15
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java52
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java113
3 files changed, 107 insertions, 73 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp-test/pom.xml b/archiva-modules/archiva-web/archiva-webapp-test/pom.xml
index cca476801..cd01dc44f 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test/pom.xml
+++ b/archiva-modules/archiva-web/archiva-webapp-test/pom.xml
@@ -83,6 +83,21 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>selenium-remote-driver</artifactId>
+ <version>${selenium-server.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-exec</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.seleniumhq.selenium</groupId>
+ <artifactId>htmlunit-driver</artifactId>
+ <version>2.24</version>
+ </dependency>
<dependency>
diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java
index 481301229..4ed311db2 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java
@@ -30,11 +30,15 @@ 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.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.apache.commons.io.FileUtils;
@@ -136,26 +140,36 @@ public class WebDriverBrowseTest
}
@Override
- public WebDriver getDefaultDriver()
- {
- String seleniumBrowser = System.getProperty( "selenium.browser" );
-
- if ( StringUtils.contains( seleniumBrowser, "chrome" ) )
- {
- return new ChromeDriver();
- }
-
- if ( StringUtils.contains( seleniumBrowser, "safari" ) )
- {
- return new SafariDriver();
- }
-
- if ( StringUtils.contains( seleniumBrowser, "iexplore" ) )
- {
- return new InternetExplorerDriver();
+ public WebDriver getDefaultDriver() {
+ String seleniumBrowser = System.getProperty("selenium.browser");
+ String seleniumHost = System.getProperty("seleniumHost", "localhost");
+ int seleniumPort = Integer.getInteger("seleniumPort", 4444);
+ try {
+
+ if (StringUtils.contains(seleniumBrowser, "chrome")) {
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.chrome()
+ );
+ }
+
+ if (StringUtils.contains(seleniumBrowser, "safari")) {
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.safari()
+ );
+ }
+
+ if (StringUtils.contains(seleniumBrowser, "iexplore")) {
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.internetExplorer()
+ );
+ }
+
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.firefox()
+ );
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Initializion of remote driver failed");
}
-
- return new FirefoxDriver();
}
}
diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java
index 0a4c1adb3..deec6c0e2 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java
@@ -29,13 +29,18 @@ 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.remote.DesiredCapabilities;
+import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.safari.SafariDriver;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
+
import org.apache.commons.io.FileUtils;
import org.fluentlenium.core.Fluent;
import org.junit.Before;
@@ -44,86 +49,86 @@ import org.junit.Before;
* @author Olivier Lamy
*/
public class WebDriverTest
- extends FluentTest
-{
+ extends FluentTest {
@Override
- public Fluent takeScreenShot( String fileName )
- {
- try
- {
+ public Fluent takeScreenShot(String fileName) {
+ try {
// save html to have a minimum feedback if jenkins firefox not up
- File fileNameHTML = new File( fileName + ".html" );
- FileUtils.writeStringToFile( fileNameHTML, getDriver().getPageSource() );
- }
- catch ( IOException e )
- {
- System.out.print( e.getMessage() );
+ File fileNameHTML = new File(fileName + ".html");
+ FileUtils.writeStringToFile(fileNameHTML, getDriver().getPageSource());
+ } catch (IOException e) {
+ System.out.print(e.getMessage());
e.printStackTrace();
}
- return super.takeScreenShot( fileName );
+ return super.takeScreenShot(fileName);
}
-
+
@Before
- public void init()
- {
- setSnapshotMode( Mode.TAKE_SNAPSHOT_ON_FAIL );
- setSnapshotPath( new File( "target", "errorshtmlsnap" ).getAbsolutePath() );
+ public void init() {
+ setSnapshotMode(Mode.TAKE_SNAPSHOT_ON_FAIL);
+ setSnapshotPath(new File("target", "errorshtmlsnap").getAbsolutePath());
}
-
+
@Test
public void simpletest()
- throws Exception
- {
-
+ throws Exception {
+
Properties tomcatPortProperties = new Properties();
tomcatPortProperties.load(
- new FileInputStream( new File( System.getProperty( "tomcat.propertiesPortFilePath" ) ) ) );
+ new FileInputStream(new File(System.getProperty("tomcat.propertiesPortFilePath"))));
+
+ int tomcatPort = Integer.parseInt(tomcatPortProperties.getProperty("tomcat.maven.http.port"));
- int tomcatPort = Integer.parseInt( tomcatPortProperties.getProperty( "tomcat.maven.http.port" ) );
+ goTo("http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en");
- goTo( "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en" );
-
// wait until topbar-menu-container is feeded
await().atMost(5, TimeUnit.SECONDS).until("#topbar-menu").isPresent();
-
- FluentList<FluentWebElement> elements = find( "#create-admin-link-a" );
- if ( !elements.isEmpty() && elements.get( 0 ).isDisplayed() )
- {
- WebElement webElement = elements.get( 0 ).getElement();
- Assert.assertEquals( "Create Admin User", webElement.getText() );
- }
- else
- {
- elements = find( "#login-link-a" );
- WebElement webElement = elements.get( 0 ).getElement();
- Assert.assertEquals( "LOGIN", webElement.getText() );
+ FluentList<FluentWebElement> elements = find("#create-admin-link-a");
+
+ if (!elements.isEmpty() && elements.get(0).isDisplayed()) {
+ WebElement webElement = elements.get(0).getElement();
+ Assert.assertEquals("Create Admin User", webElement.getText());
+ } else {
+ elements = find("#login-link-a");
+ WebElement webElement = elements.get(0).getElement();
+ Assert.assertEquals("LOGIN", webElement.getText());
}
}
@Override
- public WebDriver getDefaultDriver()
- {
- String seleniumBrowser = System.getProperty( "selenium.browser" );
+ public WebDriver getDefaultDriver() {
+ String seleniumBrowser = System.getProperty("selenium.browser");
+ String seleniumHost = System.getProperty("seleniumHost", "localhost");
+ int seleniumPort = Integer.getInteger("seleniumPort", 4444);
+ try {
- if ( StringUtils.contains( seleniumBrowser, "chrome" ) )
- {
- return new ChromeDriver();
- }
+ if (StringUtils.contains(seleniumBrowser, "chrome")) {
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.chrome()
+ );
+ }
- if ( StringUtils.contains( seleniumBrowser, "safari" ) )
- {
- return new SafariDriver();
- }
+ if (StringUtils.contains(seleniumBrowser, "safari")) {
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.safari()
+ );
+ }
- if ( StringUtils.contains( seleniumBrowser, "iexplore" ) )
- {
- return new InternetExplorerDriver();
- }
+ if (StringUtils.contains(seleniumBrowser, "iexplore")) {
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.internetExplorer()
+ );
+ }
- return new FirefoxDriver();
+ return new RemoteWebDriver(new URL("http://" + seleniumHost + ":" + seleniumPort + "/wd/hub"),
+ DesiredCapabilities.firefox()
+ );
+ } catch (MalformedURLException e) {
+ throw new RuntimeException("Initializion of remote driver failed");
+ }
}
}