Sfoglia il codice sorgente

Updating tests for WebDriver and jetty backend

citest
Martin Stockhammer 7 anni fa
parent
commit
69c6b594b1

+ 210
- 57
archiva-modules/archiva-web/archiva-webapp-test/pom.xml Vedi File

@@ -30,14 +30,14 @@
<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>
@@ -67,6 +67,8 @@
</exclusion>
</exclusions>
</dependency>

<!-- Selenium dependencies -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
@@ -81,39 +83,29 @@
<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>
@@ -124,22 +116,38 @@
<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>
@@ -155,6 +163,26 @@
<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>

@@ -179,6 +207,8 @@
<scope>test</scope>
</dependency>

<!-- End of Selenium dependencies -->

<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
@@ -233,9 +263,36 @@
<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>
@@ -264,6 +321,27 @@
</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>
@@ -288,17 +366,19 @@

<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>
@@ -308,11 +388,19 @@
<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>
@@ -402,7 +490,82 @@
</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>
@@ -426,7 +589,7 @@
<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>
@@ -439,7 +602,7 @@
<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>
@@ -451,7 +614,7 @@
<phase>post-integration-test</phase>
</execution>
</executions>
</plugin>
</plugin>-->
</plugins>
</build>
</profile>
@@ -463,20 +626,10 @@
</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>

+ 32
- 40
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java Vedi File

@@ -18,10 +18,11 @@ package org.apache.archiva.web.test;
* 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;
@@ -29,11 +30,16 @@ import org.junit.Before;
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;

@@ -42,90 +48,75 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* @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
{
@@ -137,7 +128,8 @@ public class WebDriverBrowseTest
}

@Override
public WebDriver newWebDriver() {
return WebdriverInitializer.newWebDriver();
public WebDriver newWebDriver()
{
return WebdriverUtility.newWebDriver();
}
}

+ 17
- 35
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java Vedi File

@@ -18,53 +18,41 @@ package org.apache.archiva.web.test;
* 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 ) );
}


@@ -79,18 +67,12 @@ public class WebDriverTest
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()) {
@@ -106,6 +88,6 @@ public class WebDriverTest

@Override
public WebDriver newWebDriver() {
return WebdriverInitializer.newWebDriver();
return WebdriverUtility.newWebDriver();
}
}

+ 6
- 12
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java Vedi File

@@ -19,12 +19,11 @@ package org.apache.archiva.web.test.parent;
* 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;

@@ -84,13 +83,7 @@ public abstract class AbstractSeleniumTest
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;
@@ -118,8 +111,9 @@ public abstract class AbstractSeleniumTest
{
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 ) );
}

archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverInitializer.java → archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java Vedi File

@@ -18,8 +18,10 @@ package org.apache.archiva.web.test.tools;
* 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;
@@ -28,16 +30,30 @@ 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 WebdriverInitializer
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");
@@ -115,4 +131,74 @@ public class WebdriverInitializer
}

}

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() );
}
}
}

+ 0
- 41
archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j.xml Vedi File

@@ -1,41 +0,0 @@
<?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>

+ 1
- 2
archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j2-test.xml Vedi File

@@ -19,7 +19,7 @@
-->


<configuration status="debug">
<configuration status="info">
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5p %c %x - %m%n"/>
@@ -30,7 +30,6 @@
<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"/>

+ 0
- 70
archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/logging/log4j.xml Vedi File

@@ -1,70 +0,0 @@
<?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>

+ 3
- 1
archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/logging/log4j2-test.xml Vedi File

@@ -19,7 +19,7 @@
-->


<configuration status="debug">
<configuration status="info">
<appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%t] %-5p %c %x - %m%n"/>
@@ -39,6 +39,8 @@

<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"/>

Loading…
Annulla
Salva