Changing webdriver tests to remotewebdriver

Project: http://git-wip-us.apache.org/repos/asf/archiva/repo
Commit: http://git-wip-us.apache.org/repos/asf/archiva/commit/c29a3426
Tree: http://git-wip-us.apache.org/repos/asf/archiva/tree/c29a3426
Diff: http://git-wip-us.apache.org/repos/asf/archiva/diff/c29a3426

Branch: refs/heads/master
Commit: c29a3426db4dbc9ec504042058f0ed8409f7ed81
Parents: f7b57a9
Author: Martin Stockhammer <marti...@apache.org>
Authored: Sun Apr 16 20:34:21 2017 +0200
Committer: Martin Stockhammer <marti...@apache.org>
Committed: Sun Apr 16 20:34:21 2017 +0200

----------------------------------------------------------------------
 .../archiva-web/archiva-webapp-test/pom.xml     |  15 +++
 .../archiva/web/test/WebDriverBrowseTest.java   |  52 +++++----
 .../apache/archiva/web/test/WebDriverTest.java  | 113 ++++++++++---------
 3 files changed, 107 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/archiva/blob/c29a3426/archiva-modules/archiva-web/archiva-webapp-test/pom.xml
----------------------------------------------------------------------
diff --git a/archiva-modules/archiva-web/archiva-webapp-test/pom.xml 
b/archiva-modules/archiva-web/archiva-webapp-test/pom.xml
index cca4768..cd01dc4 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>

http://git-wip-us.apache.org/repos/asf/archiva/blob/c29a3426/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java
----------------------------------------------------------------------
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 4813012..4ed311d 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();
 
     }
 }

http://git-wip-us.apache.org/repos/asf/archiva/blob/c29a3426/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java
----------------------------------------------------------------------
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 0a4c1ad..deec6c0 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");
+        }
 
     }
 }

Reply via email to