diff options
10 files changed, 374 insertions, 178 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp-test/pom.xml b/archiva-modules/archiva-web/archiva-webapp-test/pom.xml index 1ba04f187..ad2b77fed 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp-test/pom.xml @@ -35,9 +35,9 @@ <tomcat.propertiesPortFilePath>${project.build.directory}/tomcat-port.properties</tomcat.propertiesPortFilePath> <maxWaitTimeInMs>10000</maxWaitTimeInMs> - <seleniumPluginVersion>2.3</seleniumPluginVersion> - <selenium-server.version>2.53.1</selenium-server.version> - <fluentlenium.version>0.10.2</fluentlenium.version> + <selenium-server.version>3.4.0</selenium-server.version> + <fluentlenium.version>3.2.0</fluentlenium.version> + <fluentlenium.festassert.version>0.13.2</fluentlenium.festassert.version> <browserPath></browserPath> </properties> @@ -70,7 +70,18 @@ <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> + <scope>test</scope> <version>${selenium-server.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.seleniumhq.selenium.client-drivers</groupId> @@ -81,12 +92,43 @@ <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> </exclusions> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-remote-driver</artifactId> + <scope>test</scope> + <version>${selenium-server.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-leg-rc</artifactId> + <scope>test</scope> <version>${selenium-server.version}</version> + <exclusions> + <exclusion> + <groupId>org.testng</groupId> + <artifactId>testng</artifactId> + </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.commons</groupId> @@ -96,29 +138,52 @@ <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>htmlunit-driver</artifactId> - <version>2.24</version> + <version>2.26</version> </dependency> + <dependency> + <groupId>org.seleniumhq.selenium</groupId> + <artifactId>selenium-server</artifactId> + <scope>test</scope> + <version>${selenium-server.version}</version> + <exclusions> + <exclusion> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </exclusion> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + </exclusions> + </dependency> <dependency> <groupId>org.fluentlenium</groupId> - <artifactId>fluentlenium-festassert</artifactId> + <artifactId>fluentlenium-core</artifactId> <version>${fluentlenium.version}</version> <scope>test</scope> </dependency> <dependency> - <groupId>xerces</groupId> - <artifactId>xercesImpl</artifactId> + <groupId>org.fluentlenium</groupId> + <artifactId>fluentlenium-festassert</artifactId> + <version>${fluentlenium.festassert.version}</version> + <scope>test</scope> </dependency> <dependency> <groupId>org.fluentlenium</groupId> - <artifactId>fluentlenium-core</artifactId> + <artifactId>fluentlenium-junit</artifactId> <version>${fluentlenium.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>xerces</groupId> + <artifactId>xercesImpl</artifactId> + </dependency> + <!-- Dependency for MavenConnectionTest --> <dependency> <groupId>jdom</groupId> @@ -183,37 +248,6 @@ <pluginManagement> <plugins> <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>selenium-maven-plugin</artifactId> - <dependencies> - <dependency> - <groupId>org.seleniumhq.selenium</groupId> - <artifactId>selenium-server</artifactId> - <version>${selenium-server.version}</version> - </dependency> - <dependency> - <groupId>org.seleniumhq.selenium</groupId> - <artifactId>selenium-remote-driver</artifactId> - <version>${selenium-server.version}</version> - </dependency> - <dependency> - <groupId>org.seleniumhq.selenium</groupId> - <artifactId>selenium-api</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> - </dependencies> - </plugin> - <plugin> <groupId>org.apache.rat</groupId> <artifactId>apache-rat-plugin</artifactId> <configuration> @@ -274,6 +308,7 @@ <maxWaitTimeInMs>${maxWaitTimeInMs}</maxWaitTimeInMs> <seleniumHost>${seleniumHost}</seleniumHost> <seleniumPort>${seleniumPort}</seleniumPort> + <seleniumRemote>${seleniumRemote}</seleniumRemote> <tomcat.propertiesPortFilePath>${tomcat.propertiesPortFilePath}</tomcat.propertiesPortFilePath> </systemPropertyVariables> </configuration> @@ -439,39 +474,30 @@ </property> </activation> <properties> - <seleniumHost>localhost</seleniumHost> - <seleniumPort>4444</seleniumPort> + <seleniumRemote>false</seleniumRemote> </properties> - <build> - <plugins> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>selenium-maven-plugin</artifactId> - <executions> - <execution> - <phase>pre-integration-test</phase> - <goals> - <goal>start-server</goal> - </goals> - <configuration> - <background>true</background> - <port>${seleniumPort}</port> - <logOutput>true</logOutput> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> </profile> <profile> - <id>firefox</id> + <id>htmlunit</id> <activation> <property> <name>!browser</name> </property> </activation> <properties> + <selenium.browser>*htmlunit</selenium.browser> + <excluded.groups/> + </properties> + </profile> + <profile> + <id>firefox</id> + <activation> + <property> + <name>browser</name> + <value>firefox</value> + </property> + </activation> + <properties> <selenium.browser>*firefox</selenium.browser> <excluded.groups/> </properties> 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 4ed311db2..7f83b3464 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 @@ -19,31 +19,25 @@ package org.apache.archiva.web.test; */ import junit.framework.Assert; +import org.apache.archiva.web.test.tools.WebdriverInitializer; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.fluentlenium.adapter.FluentTest; +import org.fluentlenium.adapter.junit.FluentTest; import org.fluentlenium.core.domain.FluentList; import org.fluentlenium.core.domain.FluentWebElement; -import static org.assertj.core.api.Assertions.assertThat; +import org.junit.Before; import org.junit.Test; 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.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; + +import static org.assertj.core.api.Assertions.assertThat; /** * @author Olivier Lamy @@ -53,7 +47,7 @@ public class WebDriverBrowseTest { @Override - public Fluent takeScreenShot( String fileName ) + public void takeScreenShot( String fileName ) { File fileNameHTML = new File( "target", "errorshtmlsnap" ); try @@ -67,14 +61,17 @@ public class WebDriverBrowseTest { e.printStackTrace(); } - return super.takeScreenShot( fileNameHTML.getAbsolutePath() ); + super.takeScreenShot( fileNameHTML.getAbsolutePath() ); } @Before public void init() { - setSnapshotMode( Mode.TAKE_SNAPSHOT_ON_FAIL ); + + setScreenshotMode( TriggerMode.AUTOMATIC_ON_FAIL); + setDriverLifecycle( DriverLifecycle.CLASS ); + } @Test @@ -93,34 +90,34 @@ public class WebDriverBrowseTest 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(); + await().atMost( 5, TimeUnit.SECONDS ).until( $("#topbar-menu" )).present(); FluentList<FluentWebElement> elements = find( "#create-admin-link-a" ); - if ( !elements.isEmpty() && elements.get( 0 ).isDisplayed() ) + if ( !elements.isEmpty() && elements.get( 0 ).displayed() ) { WebElement webElement = elements.get( 0 ).getElement(); Assert.assertEquals( "Create Admin User", webElement.getText() ); webElement.click(); - await().atMost( 2, TimeUnit.SECONDS ).until( "#user-create" ).isPresent(); - assertThat( find( "#username" ).getValue().equals( "admin" ) ); - assertThat( find( "#password" ).getValue().isEmpty() ); - assertThat( find( "#confirmPassword" ).getValue().isEmpty() ); - assertThat( find( "#email" ).getValue().isEmpty() ); - - fill( "#fullname" ).with( p.getProperty( "ADMIN_FULLNAME" ) ); - fill( "#email" ).with( p.getProperty( "ADMIN_EMAIL" ) ); - fill( "#password" ).with( p.getProperty( "ADMIN_PASSWORD" ) ); - fill( "#confirmPassword" ).with( p.getProperty( "ADMIN_PASSWORD" ) ); + await().atMost( 2, TimeUnit.SECONDS ).until($( "#user-create" )).present(); + assertThat( find( "#username" ).value().equals( "admin" ) ); + assertThat( find( "#password" ).value().isEmpty() ); + assertThat( find( "#confirmPassword" ).value().isEmpty() ); + assertThat( find( "#email" ).value().isEmpty() ); + + $("#fullname").fill().with( p.getProperty( "ADMIN_FULLNAME" ) ); + $("#email").fill().with( p.getProperty( "ADMIN_EMAIL" ) ); + $("#password").fill().with( p.getProperty( "ADMIN_PASSWORD" ) ); + $("#confirmPassword").fill().with( p.getProperty( "ADMIN_PASSWORD" ) ); find( "#user-create-form-register-button" ).click(); - await().atMost( 2, TimeUnit.SECONDS ).until( "#logout-link" ).isPresent(); + await().atMost( 2, TimeUnit.SECONDS ).until($("#logout-link" )).present(); FluentList<FluentWebElement> elementss = find( "#menu-find-browse-a" ); WebElement webElsement = elementss.get( 0 ).getElement(); webElsement.click(); - await().atMost( 2, TimeUnit.SECONDS ).until( "#main_browse_result" ).isPresent(); + await().atMost( 2, TimeUnit.SECONDS ).until($("#main_browse_result" )).present(); // give me search page :( not browse page takeScreenShot( "search.png" ); @@ -140,36 +137,7 @@ public class WebDriverBrowseTest } @Override - 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"); - } - + public WebDriver newWebDriver() { + return WebdriverInitializer.newWebDriver(); } } 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 deec6c0e2..5a020e265 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 @@ -19,10 +19,13 @@ package org.apache.archiva.web.test; */ import junit.framework.Assert; +import org.apache.archiva.web.test.tools.WebdriverInitializer; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; -import org.fluentlenium.adapter.FluentTest; +import org.fluentlenium.adapter.junit.FluentTest; import org.fluentlenium.core.domain.FluentList; import org.fluentlenium.core.domain.FluentWebElement; +import org.junit.Before; import org.junit.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; @@ -38,21 +41,21 @@ import java.io.FileInputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.nio.file.Paths; import java.util.Properties; import java.util.concurrent.TimeUnit; -import org.apache.commons.io.FileUtils; -import org.fluentlenium.core.Fluent; -import org.junit.Before; - /** * @author Olivier Lamy */ public class WebDriverTest - extends FluentTest { + extends FluentTest +{ + + @Override - public Fluent takeScreenShot(String fileName) { + public void takeScreenShot(String fileName) { try { // save html to have a minimum feedback if jenkins firefox not up File fileNameHTML = new File(fileName + ".html"); @@ -61,13 +64,15 @@ public class WebDriverTest System.out.print(e.getMessage()); e.printStackTrace(); } - return super.takeScreenShot(fileName); + super.takeScreenShot(fileName); } + @Before public void init() { - setSnapshotMode(Mode.TAKE_SNAPSHOT_ON_FAIL); - setSnapshotPath(new File("target", "errorshtmlsnap").getAbsolutePath()); + setScreenshotMode(TriggerMode.AUTOMATIC_ON_FAIL); + setScreenshotPath( Paths.get("target", "errorshtmlsnap").toAbsolutePath().toString()); + setDriverLifecycle( DriverLifecycle.CLASS ); } @Test @@ -79,15 +84,16 @@ public class WebDriverTest new FileInputStream(new File(System.getProperty("tomcat.propertiesPortFilePath")))); int tomcatPort = Integer.parseInt(tomcatPortProperties.getProperty("tomcat.maven.http.port")); - - goTo("http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en"); + String url = "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en"; + System.err.println("URL: "+url); + goTo(url); // wait until topbar-menu-container is feeded - await().atMost(5, TimeUnit.SECONDS).until("#topbar-menu").isPresent(); + await().atMost(10, TimeUnit.SECONDS).until($("#topbar-menu")).present(); FluentList<FluentWebElement> elements = find("#create-admin-link-a"); - if (!elements.isEmpty() && elements.get(0).isDisplayed()) { + if (!elements.isEmpty() && elements.get(0).displayed()) { WebElement webElement = elements.get(0).getElement(); Assert.assertEquals("Create Admin User", webElement.getText()); } else { @@ -99,36 +105,7 @@ public class WebDriverTest } @Override - 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"); - } - + public WebDriver newWebDriver() { + return WebdriverInitializer.newWebDriver(); } } diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java index 3a886c7c4..a8403cd58 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java @@ -21,7 +21,10 @@ package org.apache.archiva.web.test.parent; import com.thoughtworks.selenium.DefaultSelenium; import com.thoughtworks.selenium.Selenium; +import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; import org.apache.archiva.web.test.tools.ArchivaSeleniumExecutionRule; +import org.apache.archiva.web.test.tools.WebdriverInitializer; +import org.apache.xpath.operations.Bool; import org.junit.Assert; import org.junit.Rule; @@ -37,6 +40,9 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import org.apache.commons.io.FileUtils; +import org.openqa.selenium.WebDriver; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a> @@ -45,6 +51,7 @@ import org.apache.commons.io.FileUtils; public abstract class AbstractSeleniumTest { + private final Logger logger = LoggerFactory.getLogger( getClass() ); @Rule public ArchivaSeleniumExecutionRule archivaSeleniumExecutionRule = new ArchivaSeleniumExecutionRule(); @@ -60,6 +67,8 @@ public abstract class AbstractSeleniumTest public int seleniumPort = Integer.getInteger( "seleniumPort", 4444 ); + public boolean remoteSelenium = Boolean.parseBoolean( System.getProperty( "remoteSelenium", "false" ) ); + private Selenium selenium = null; public Properties p; @@ -83,7 +92,7 @@ public abstract class AbstractSeleniumTest baseUrl = "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en"; - open( baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs ); + open( baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs, remoteSelenium ); archivaSeleniumExecutionRule.selenium = selenium; assertAdminCreated(); } @@ -102,14 +111,15 @@ public abstract class AbstractSeleniumTest /** * Initialize selenium */ - public void open( String baseUrl, String browser, String seleniumHost, int seleniumPort, int maxWaitTimeInMs ) + public void open( String baseUrl, String browser, String seleniumHost, int seleniumPort, int maxWaitTimeInMs, boolean remoteSelenium) throws Exception { try { if ( getSelenium() == null ) { - selenium = new DefaultSelenium( seleniumHost, seleniumPort, browser, baseUrl ); + WebDriver driver = WebdriverInitializer.newWebDriver(browser, seleniumHost, seleniumPort, remoteSelenium); + selenium = new WebDriverBackedSelenium(driver, baseUrl); selenium.start(); selenium.setTimeout( Integer.toString( maxWaitTimeInMs ) ); } @@ -125,15 +135,15 @@ public abstract class AbstractSeleniumTest public void assertAdminCreated() throws Exception { - initializeArchiva( baseUrl, browser, maxWaitTimeInMs, seleniumHost, seleniumPort ); + initializeArchiva( baseUrl, browser, maxWaitTimeInMs, seleniumHost, seleniumPort, remoteSelenium ); } public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs, String seleniumHost, - int seleniumPort ) + int seleniumPort, boolean remoteSelenium) throws Exception { - open( baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs ); + open( baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs, remoteSelenium); getSelenium().open( baseUrl ); @@ -701,8 +711,12 @@ public abstract class AbstractSeleniumTest File fileName = new File( targetPath, fileBaseName + ".png" ); - selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "background=#FFFFFF" ); - + try + { + selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "background=#FFFFFF" ); + } catch (UnsupportedOperationException ex) { + logger.warn("Could not create screenshot. Not supported by this webdriver. "+selenium.getClass().getName()); + } return fileName.getAbsolutePath(); } diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverInitializer.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverInitializer.java new file mode 100644 index 000000000..c3ddc1a64 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverInitializer.java @@ -0,0 +1,118 @@ +package org.apache.archiva.web.test.tools; +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import org.apache.commons.lang3.StringUtils; +import org.openqa.selenium.Capabilities; +import org.openqa.selenium.WebDriver; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.firefox.FirefoxDriver; +import org.openqa.selenium.htmlunit.HtmlUnitDriver; +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.net.MalformedURLException; +import java.net.URL; + +/** + * Created by martin_s on 04.06.17. + */ +public class WebdriverInitializer +{ + + public static WebDriver newWebDriver() { + String seleniumBrowser = System.getProperty("selenium.browser"); + String seleniumHost = System.getProperty("seleniumHost", "localhost"); + int seleniumPort = Integer.getInteger("seleniumPort", 4444); + boolean seleniumRemote = Boolean.parseBoolean(System.getProperty("seleniumRemote","false")); + return newWebDriver(seleniumBrowser,seleniumHost, seleniumPort,seleniumRemote); + } + + public static WebDriver newWebDriver(String seleniumBrowser, String seleniumHost, int seleniumPort, boolean seleniumRemote) { + try { + + if ( StringUtils.contains(seleniumBrowser, "chrome")) { + if (seleniumRemote) + { + return new RemoteWebDriver( new URL( "http://" + seleniumHost + ":" + seleniumPort + "/wd/hub" ), + DesiredCapabilities.chrome() + ); + } else { + return new ChromeDriver( ); + } + } + + if (StringUtils.contains(seleniumBrowser, "safari")) { + if (seleniumRemote) + { + return new RemoteWebDriver( new URL( "http://" + seleniumHost + ":" + seleniumPort + "/wd/hub" ), + DesiredCapabilities.safari() + ); + } else { + return new SafariDriver(); + } + } + + if (StringUtils.contains(seleniumBrowser, "iexplore")) { + if (seleniumRemote) + { + return new RemoteWebDriver( new URL( "http://" + seleniumHost + ":" + seleniumPort + "/wd/hub" ), + DesiredCapabilities.internetExplorer() + ); + } else { + new InternetExplorerDriver( ); + } + } + + if (StringUtils.contains( seleniumBrowser, "firefox" )) + { + if ( seleniumRemote ) + { + return new RemoteWebDriver( new URL( "http://" + seleniumHost + ":" + seleniumPort + "/wd/hub" ), + DesiredCapabilities.firefox() + ); + } + else + { + return new FirefoxDriver(); + } + } + + if ( seleniumRemote ) + { + return new RemoteWebDriver( new URL( "http://" + seleniumHost + ":" + seleniumPort + "/wd/hub" ), + DesiredCapabilities.htmlUnit() + ); + } + else + { + DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit(); + capabilities.setJavascriptEnabled( true ); + capabilities.setVersion( "firefox-51" ); + return new HtmlUnitDriver( capabilities ); + } + + } catch (MalformedURLException e) { + throw new RuntimeException("Initializion of remote driver failed"); + } + + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/jetty/jetty-env.xml b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/jetty/jetty-env.xml new file mode 100644 index 000000000..bed63bfa3 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/jetty/jetty-env.xml @@ -0,0 +1,48 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + ~ Licensed to the Apache Software Foundation (ASF) under one + ~ or more contributor license agreements. See the NOTICE file + ~ distributed with this work for additional information + ~ regarding copyright ownership. The ASF licenses this file + ~ to you under the Apache License, Version 2.0 (the + ~ "License"); you may not use this file except in compliance + ~ with the License. You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, + ~ software distributed under the License is distributed on an + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + ~ KIND, either express or implied. See the License for the + ~ specific language governing permissions and limitations + ~ under the License. + --> +<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> + +<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"> + <New id="derbyDs" class="org.eclipse.jetty.plus.jndi.Resource"> + <Arg></Arg> + <Arg>jdbc/users</Arg> + <Arg> + <New class="org.apache.derby.jdbc.EmbeddedDataSource"> + <Set name="databaseName">database/users;create=true</Set> + <Set name="user">sa</Set> + <Set name="password"></Set> + </New> + </Arg> + </New> + + + <New id="mail" class="org.eclipse.jetty.plus.jndi.Resource"> + <Arg>mail/Session</Arg> + <Arg> + <New class="org.eclipse.jetty.jndi.factories.MailSessionReference"> + <Set name="properties"> + <New class="java.util.Properties"> + <Put name="mail.smtp.host">localhost</Put> + </New> + </Set> + </New> + </Arg> + </New> +</Configure>
\ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j2-test.xml b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j2-test.xml index 9294964db..dec6d75a8 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j2-test.xml +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j2-test.xml @@ -28,6 +28,9 @@ <loggers> <logger name="org.springframework" level="error"/> + <logger name="com.gargoylesoftware.htmlunit.DefaultCssErrorHandler" level="error" /> + <logger name="com.gargoylesoftware.htmlunit.html.HtmlScript" level="error" /> + <logger name="org.apache.http.wire" level="debug" /> <root level="info"> <appender-ref ref="console"/> diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml index 6d101a4a5..b88e7ba6e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/pom.xml +++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml @@ -717,6 +717,12 @@ <dependency> <groupId>org.apache.archiva.redback</groupId> <artifactId>redback-rest-services</artifactId> + <exclusions> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.apache.archiva.redback</groupId> @@ -801,6 +807,12 @@ <artifactId>redback-rest-services</artifactId> <classifier>tests</classifier> <scope>test</scope> + <exclusions> + <exclusion> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/jetty/jetty-env.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/jetty/jetty-env.xml new file mode 100644 index 000000000..1668649ca --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/jetty/jetty-env.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd"> + +<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext"> + <New id="derbyDs" class="org.eclipse.jetty.plus.jndi.Resource"> + <Arg></Arg> + <Arg>jdbc/users</Arg> + <Arg> + <New class="org.apache.derby.jdbc.EmbeddedDataSource"> + <Set name="databaseName">database/users;create=true</Set> + <Set name="user">sa</Set> + <Set name="password"></Set> + </New> + </Arg> + </New> + + + <New id="mail" class="org.eclipse.jetty.plus.jndi.Resource"> + <Arg>mail/Session</Arg> + <Arg> + <New class="org.eclipse.jetty.jndi.factories.MailSessionReference"> + <Set name="properties"> + <New class="java.util.Properties"> + <Put name="mail.smtp.host">localhost</Put> + </New> + </Set> + </New> + </Arg> + </New> +</Configure>
\ No newline at end of file @@ -87,7 +87,7 @@ <httpclient.core.version>4.4.4</httpclient.core.version> <javaxMailVersion>1.4</javaxMailVersion> <jettyVersion>9.4.5.v20170502</jettyVersion> - <guava.version>16.0.1</guava.version> + <guava.version>22.0</guava.version> <openjpaVersion>2.4.1</openjpaVersion> <!-- restore when we will be able to use a derby in memory database --> |