<name>Archiva Web :: Javascript Application Tests</name>
<properties>
- <webappDirectory>${project.build.directory}/tomcat7x/webapps/archiva</webappDirectory>
- <container.test.port>0</container.test.port>
- <tomcat.propertiesPortFilePath>${project.build.directory}/tomcat-port.properties</tomcat.propertiesPortFilePath>
+ <webappDirectory>${project.build.directory}/container/webapps/archiva</webappDirectory>
+ <container.propertiesPortFilePath>${project.build.directory}/container-port.properties</container.propertiesPortFilePath>
<maxWaitTimeInMs>10000</maxWaitTimeInMs>
-
<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>
+ <seleniumHost></seleniumHost>
+ <seleniumPort></seleniumPort>
<browserPath></browserPath>
</properties>
</exclusion>
</exclusions>
</dependency>
+
+ <!-- Selenium dependencies -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
- </exclusions>
- </dependency>
- <dependency>
- <groupId>org.seleniumhq.selenium.client-drivers</groupId>
- <artifactId>selenium-java-client-driver</artifactId>
- <scope>test</scope>
- <exclusions>
<exclusion>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
</exclusion>
<exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-client</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>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
</exclusion>
<exclusion>
- <groupId>javax.servlet</groupId>
- <artifactId>javax.servlet-api</artifactId>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-common</artifactId>
</exclusion>
</exclusions>
</dependency>
+
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-leg-rc</artifactId>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </exclusion>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-client</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-common</artifactId>
+ </exclusion>
</exclusions>
</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.26</version>
- </dependency>
+
+
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-client</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-api</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-common</artifactId>
+ </exclusion>
</exclusions>
</dependency>
<scope>test</scope>
</dependency>
+ <!-- End of Selenium dependencies -->
+
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<artifactId>log4j-1.2-api</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-io</artifactId>
+ <version>${jettyVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-api</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.websocket</groupId>
+ <artifactId>websocket-client</artifactId>
+ <version>${jettyVersion}</version>
+ <scope>test</scope>
+ </dependency>
+
+
</dependencies>
<build>
+
<testResources>
<testResource>
<directory>src/test/resources</directory>
</plugins>
</pluginManagement>
<plugins>
+
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <configuration>
+ <portNames>
+ <portName>container.http.port</portName>
+ <portName>container.stop.port</portName>
+ </portNames>
+ </configuration>
+ <executions>
+ <execution>
+ <id>reserve-port</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>reserve-network-port</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
+ <artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<runOrder>alphabetical</runOrder>
+ <includes>
+ <include>**/*Test.java</include>
+ </includes>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
- <phase>integration-test</phase>
<goals>
- <goal>test</goal>
+ <goal>integration-test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<maxWaitTimeInMs>${maxWaitTimeInMs}</maxWaitTimeInMs>
<seleniumHost>${seleniumHost}</seleniumHost>
<seleniumPort>${seleniumPort}</seleniumPort>
- <seleniumRemote>${seleniumRemote}</seleniumRemote>
- <tomcat.propertiesPortFilePath>${tomcat.propertiesPortFilePath}</tomcat.propertiesPortFilePath>
+ <container.propertiesPortFilePath>${container.propertiesPortFilePath}</container.propertiesPortFilePath>
+ <container.http.port>${container.http.port}</container.http.port>
</systemPropertyVariables>
</configuration>
+
</execution>
+ <execution>
+ <id>verify</id>
+ <goals>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+
</executions>
</plugin>
</plugins>
</execution>
</executions>
</plugin>
+
+
<plugin>
+ <groupId>org.eclipse.jetty</groupId>
+ <artifactId>jetty-maven-plugin</artifactId>
+ <version>9.4.5.v20170502</version>
+ <configuration>
+ <stopKey>archivastop</stopKey>
+ <stopPort>${container.stop.port}</stopPort>
+ <stopWait>30</stopWait>
+ <httpConnector>
+ <port>${container.http.port}</port>
+ </httpConnector>
+ </configuration>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.derby</groupId>
+ <artifactId>derby</artifactId>
+ <version>${derbyVersion}</version>
+ </dependency>
+ <dependency>
+ <groupId>javax.mail</groupId>
+ <artifactId>mail</artifactId>
+ <version>${javaxMailVersion}</version>
+ </dependency>
+
+ </dependencies>
+ <executions>
+ <execution>
+ <id>jetty-run</id>
+ <goals>
+ <goal>deploy-war</goal>
+ </goals>
+ <phase>pre-integration-test</phase>
+ <configuration>
+ <daemon>true</daemon>
+ <webApp>
+ <contextPath>/archiva</contextPath>
+ <jettyEnvXml>${project.build.testOutputDirectory}/jetty/jetty-env.xml</jettyEnvXml>
+ </webApp>
+ <war>${webappDirectory}</war>
+ <systemProperties>
+ <systemProperty>
+ <name>appserver.base</name>
+ <value>${project.build.directory}/appserver-base</value>
+ </systemProperty>
+ <systemProperty>
+ <name>appserver.home</name>
+ <value>${project.build.directory}/appserver-base</value>
+ </systemProperty>
+ <systemProperty>
+ <name>derby.system.home</name>
+ <value>${project.build.directory}</value>
+ </systemProperty>
+ <systemProperty>
+ <name>archiva.devMode</name>
+ <value>true</value>
+ </systemProperty>
+ <systemProperty>
+ <name>openjpa.Log</name>
+ <value>${openjpa.Log}</value>
+ </systemProperty>
+ </systemProperties>
+ </configuration>
+ </execution>
+ <execution>
+ <id>jetty-shutdown</id>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ <phase>post-integration-test</phase>
+ </execution>
+ </executions>
+ </plugin>
+
+<!-- <plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<dependencies>
<phase>pre-integration-test</phase>
<configuration>
<path>/archiva</path>
- <port>${container.test.port}</port>
+ <port>${container.http.port}</port>
<uriEncoding>UTF-8</uriEncoding>
<warDirectory>${webappDirectory}</warDirectory>
<fork>true</fork>
<openjpa.Log>${openjpa.Log}</openjpa.Log>
</systemProperties>
<contextFile>${project.build.testOutputDirectory}/archiva.xml</contextFile>
- <propertiesPortFilePath>${tomcat.propertiesPortFilePath}</propertiesPortFilePath>
+ <propertiesPortFilePath>${container.propertiesPortFilePath}</propertiesPortFilePath>
<useNaming>true</useNaming>
</configuration>
</execution>
<phase>post-integration-test</phase>
</execution>
</executions>
- </plugin>
+ </plugin>-->
</plugins>
</build>
</profile>
</property>
</activation>
<properties>
- <baseUrl>http://localhost:${container.test.port}/archiva/index.html?request_lang=en</baseUrl>
- </properties>
- </profile>
- <profile>
- <id>start-selenium</id>
- <activation>
- <property>
- <name>!seleniumHost</name>
- </property>
- </activation>
- <properties>
- <seleniumRemote>false</seleniumRemote>
+ <baseUrl>http://localhost:${container.http.port}/archiva</baseUrl>
</properties>
</profile>
+
<profile>
<id>htmlunit</id>
<activation>
* under the License.
*/
-import junit.framework.Assert;
-import org.apache.archiva.web.test.tools.WebdriverInitializer;
+import org.fluentlenium.configuration.ConfigurationProperties;
+import org.fluentlenium.configuration.FluentConfiguration;
+import org.junit.Assert;
+import org.apache.archiva.web.test.tools.WebdriverUtility;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
import org.fluentlenium.adapter.junit.FluentTest;
import org.fluentlenium.core.domain.FluentList;
import org.fluentlenium.core.domain.FluentWebElement;
import org.junit.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
/**
* @author Olivier Lamy
*/
+@FluentConfiguration(driverLifecycle = ConfigurationProperties.DriverLifecycle.CLASS)
public class WebDriverBrowseTest
- extends FluentTest
+ extends FluentTest
{
+ final Logger log = LoggerFactory.getLogger( WebDriverBrowseTest.class );
+
@Override
public void takeScreenShot( String fileName )
{
- File fileNameHTML = new File( "target", "errorshtmlsnap" );
- try
- {
- // save html to have a minimum feedback if jenkins firefox not up
- fileNameHTML = new File( fileNameHTML, fileName );
- FileUtils.writeStringToFile( new File ( new File( "target", "errorshtmlsnap" ) , fileName + ".html"), getDriver().getPageSource() );
-
- }
- catch ( IOException e )
- {
- e.printStackTrace();
- }
- super.takeScreenShot( fileNameHTML.getAbsolutePath() );
-
+ WebdriverUtility.takeScreenShot( fileName, getDriver(), (a)->super.takeScreenShot( a ) );
}
@Before
public void init()
{
- setScreenshotMode( TriggerMode.AUTOMATIC_ON_FAIL);
+ setScreenshotMode( TriggerMode.AUTOMATIC_ON_FAIL );
setDriverLifecycle( DriverLifecycle.CLASS );
}
@Test
public void simpletest()
- throws Exception
+ throws Exception
{
Properties p = new Properties();
p.load( this.getClass().getClassLoader().getResourceAsStream( "test.properties" ) );
- Properties tomcatPortProperties = new Properties();
- tomcatPortProperties.load(
- 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 baseUrl = WebdriverUtility.getBaseUrl();
+ String url = baseUrl + "/index.html?request_lang=en";
+ goTo( url );
// wait until topbar-menu-container is feeded
- await().atMost( 5, TimeUnit.SECONDS ).until( $("#topbar-menu" )).present();
+ await().atMost( 5, TimeUnit.SECONDS ).untilPredicate( ( fl ) -> $( "#topbar-menu" ).present() );
FluentList<FluentWebElement> elements = find( "#create-admin-link-a" );
-
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" )).present();
+ await().atMost( 2, TimeUnit.SECONDS ).untilPredicate( ( fl ) -> $( "#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" ) );
+ $( "#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" )).present();
+ await().atMost( 2, TimeUnit.SECONDS ).untilPredicate( ( fl ) -> $( "#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" )).present();
+ await().atMost( 5, TimeUnit.SECONDS ).untilPredicate( ( fl ) -> $( "#main_browse_result" ).present() );
// give me search page :( not browse page
takeScreenShot( "search.png" );
- goTo( "http://localhost:" + tomcatPort + "/archiva/index.html#browse?request_lang=en" );
+ goTo( baseUrl + "/index.html#browse?request_lang=en" );
takeScreenShot( "browse.png" );
// give me a browse page
-
+
}
else
{
}
@Override
- public WebDriver newWebDriver() {
- return WebdriverInitializer.newWebDriver();
+ public WebDriver newWebDriver()
+ {
+ return WebdriverUtility.newWebDriver();
}
}
* under the License.
*/
-import junit.framework.Assert;
-import org.apache.archiva.web.test.tools.WebdriverInitializer;
+import org.junit.Assert;
+import org.apache.archiva.web.test.tools.WebdriverUtility;
import org.apache.commons.io.FileUtils;
-import org.apache.commons.lang3.StringUtils;
import org.fluentlenium.adapter.junit.FluentTest;
+import org.fluentlenium.configuration.ConfigurationProperties;
+import org.fluentlenium.configuration.FluentConfiguration;
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;
-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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.Paths;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
/**
* @author Olivier Lamy
*/
+@FluentConfiguration(driverLifecycle = ConfigurationProperties.DriverLifecycle.CLASS)
public class WebDriverTest
extends FluentTest
{
-
+ final Logger log = LoggerFactory.getLogger( WebDriver.class );
@Override
- public void 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());
- e.printStackTrace();
- }
- super.takeScreenShot(fileName);
+ public void takeScreenShot( String fileName )
+ {
+ WebdriverUtility.takeScreenShot( fileName, getDriver(), (a)->super.takeScreenShot( a ) );
}
public void simpletest()
throws Exception {
- Properties tomcatPortProperties = new Properties();
- tomcatPortProperties.load(
- new FileInputStream(new File(System.getProperty("tomcat.propertiesPortFilePath"))));
-
- int tomcatPort = Integer.parseInt(tomcatPortProperties.getProperty("tomcat.maven.http.port"));
- String url = "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en";
- System.err.println("URL: "+url);
+ String url = WebdriverUtility.getBaseUrl()+ "/index.html?request_lang=en";
goTo(url);
// wait until topbar-menu-container is feeded
- await().atMost(10, TimeUnit.SECONDS).until($("#topbar-menu")).present();
-
+ //await().atMost(20, TimeUnit.SECONDS).until($("#topbar-menu")).present();
+ await().untilPredicate((fl) ->$("#topbar-menu").present());
FluentList<FluentWebElement> elements = find("#create-admin-link-a");
if (!elements.isEmpty() && elements.get(0).displayed()) {
@Override
public WebDriver newWebDriver() {
- return WebdriverInitializer.newWebDriver();
+ return WebdriverUtility.newWebDriver();
}
}
* under the License.
*/
-import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
+//import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
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.apache.archiva.web.test.tools.WebdriverUtility;
import org.junit.Assert;
import org.junit.Rule;
p = new Properties();
p.load( this.getClass().getClassLoader().getResourceAsStream( "test.properties" ) );
- Properties tomcatPortProperties = new Properties();
- tomcatPortProperties.load(
- new FileInputStream( new File( System.getProperty( "tomcat.propertiesPortFilePath" ) ) ) );
-
- int tomcatPort = Integer.parseInt( tomcatPortProperties.getProperty( "tomcat.maven.http.port" ) );
-
- baseUrl = "http://localhost:" + tomcatPort + "/archiva/index.html?request_lang=en";
+ baseUrl = WebdriverUtility.getBaseUrl()+"/index.html?request_lang=en";
open( baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs, remoteSelenium );
archivaSeleniumExecutionRule.selenium = selenium;
{
if ( getSelenium() == null )
{
- WebDriver driver = WebdriverInitializer.newWebDriver(browser, seleniumHost, seleniumPort, remoteSelenium);
- selenium = new WebDriverBackedSelenium(driver, baseUrl);
+ WebDriver driver = WebdriverUtility.newWebDriver(browser, seleniumHost, seleniumPort, remoteSelenium);
+ WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
+ selenium.getWrappedDriver();
selenium.start();
selenium.setTimeout( Integer.toString( maxWaitTimeInMs ) );
}
+++ /dev/null
-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");
- }
-
- }
-}
--- /dev/null
+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.io.FileUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.openqa.selenium.Capabilities;
+import org.openqa.selenium.JavascriptExecutor;
+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 org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Properties;
+import java.util.function.Consumer;
+import java.util.function.Function;
+
+/**
+ * Created by martin_s on 04.06.17.
+ */
+public class WebdriverUtility
+{
+
+ static final Logger log = LoggerFactory.getLogger( WebdriverUtility.class );
+
+ 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");
+ }
+
+ }
+
+ public static String getBaseUrl() {
+
+ if (System.getProperties().containsKey( "baseUrl" )) {
+ return System.getProperty("baseUrl");
+ }
+ int containerPort = 7777;
+ if (System.getProperties().containsKey("container.http.port")) {
+ containerPort = Integer.parseInt(System.getProperty("container.http.port"));
+ } else if (System.getProperties().containsKey("container.propertiesPortFilePath"))
+ {
+ Properties portProperties = new Properties();
+ try (InputStream inputStream = Files.newInputStream(Paths.get(System.getProperty("container.propertiesPortFilePath"))))
+ {
+ portProperties.load(inputStream);
+ }
+ catch ( IOException e )
+ {
+ log.error("Error during property loading with containger.propertiesPortFilePath");
+ }
+ if ( portProperties.containsKey( "tomcat.maven.http.port" ) )
+ {
+ containerPort = Integer.parseInt( portProperties.getProperty( "tomcat.maven.http.port" ) );
+ }
+ else
+ {
+ containerPort = Integer.parseInt( portProperties.getProperty( "container.http.port" ) );
+ }
+ }
+ return "http://localhost:" + containerPort+"/archiva";
+ }
+
+ public static void takeScreenShot( String fileName, WebDriver driver, Consumer<String> screenShotFunction) {
+ try
+ {
+ Path snapDir = Paths.get( "target", "errorshtmlsnap" );
+ if ( !Files.exists( snapDir ) )
+ {
+ Files.createDirectories( snapDir );
+ }
+ Path htmlFile = snapDir.resolve( fileName + ".html" );
+ Path screenShotFile = snapDir.resolve( fileName );
+ String pageSource=null;
+ String encoding="ISO-8859-1";
+ try
+ {
+ pageSource = ( (JavascriptExecutor) driver ).executeScript( "return document.documentElement.outerHTML;" ).toString();
+ } catch (Exception e) {
+ log.info("Could not create html source by javascript");
+ pageSource = driver.getPageSource();
+ }
+ if (pageSource.contains("encoding=\"")) {
+ encoding = pageSource.replaceFirst( ".*encoding=\"([^\"]+)\".*", "$1" );
+ }
+ FileUtils.writeStringToFile( htmlFile.toFile(), pageSource, encoding);
+ try
+ {
+ screenShotFunction.accept( screenShotFile.toAbsolutePath().toString() );
+ }
+ catch ( Exception e )
+ {
+ log.info( "Could not create screenshot: " + e.getMessage() );
+ }
+
+ }
+ catch ( IOException e )
+ {
+ log.info( "Creating screenshot failed " + e.getMessage() );
+ }
+ }
+}
+++ /dev/null
-<?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 log4j:configuration SYSTEM "log4j.dtd">
-
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
-
- <appender name="console" class="org.apache.log4j.ConsoleAppender">
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d [%t] %-5p %c %x - %m%n"/>
- </layout>
- </appender>
-
-
- <logger name="org.springframework">
- <level value="ERROR"/>
- </logger>
-
- <root>
- <priority value ="info" />
- <appender-ref ref="console" />
- </root>
-
-</log4j:configuration>
-->
-<configuration status="debug">
+<configuration status="info">
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5p %c %x - %m%n"/>
<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"/>
+++ /dev/null
-<?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 log4j:configuration SYSTEM "log4j.dtd">
-
-<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
-
- <appender name="console" class="org.apache.log4j.ConsoleAppender">
- <layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="%d [%t] %-5p %c %x - %m%n"/>
- </layout>
- </appender>
-
- <logger name="JPOX">
- <level value="error"/>
- </logger>
-
- <logger name="org.apache.commons.configuration.DefaultConfigurationBuilder">
- <level value="error"/>
- </logger>
-
-
- <logger name="org.springframework">
- <level value="ERROR"/>
- </logger>
-
- <logger name="org.codehaus.plexus">
- <level value="ERROR"/>
- </logger>
-
- <logger name="org.codehaus.redback">
- <level value="ERROR"/>
- </logger>
-
- <logger name="org.apache.cxf">
- <level value="ERROR"/>
- </logger>
-
- <logger name="org.quartz">
- <level value="ERROR"/>
- </logger>
-
- <logger name="org.apache.archiva">
- <level value="INFO"/>
- </logger>
-
-
- <root>
- <priority value="ERROR" />
- <appender-ref ref="console" />
- </root>
-
-</log4j:configuration>
-->
-<configuration status="debug">
+<configuration status="info">
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5p %c %x - %m%n"/>
<logger name="org.apache.archiva.redback" level="error"/>
+ <logger name="org.apache.jackrabbit" level="error" />
+
<logger name="org.apache.cxf" level="error"/>
<logger name="org.quartz" level="error"/>