Browse Source

Changing tests to WebDriver

citest
Martin Stockhammer 7 years ago
parent
commit
7b8d3bb380
15 changed files with 445 additions and 95 deletions
  1. 46
    0
      archiva-modules/archiva-web/archiva-webapp-test/pom.xml
  2. 5
    0
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/LoginTest.java
  3. 12
    6
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryAdminTest.java
  4. 33
    2
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java
  5. 31
    2
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java
  6. 2
    1
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
  7. 128
    80
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
  8. 7
    0
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/ArchivaSeleniumExecutionRule.java
  9. 13
    2
      archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java
  10. 4
    0
      archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j2-test.xml
  11. 137
    0
      archiva-modules/archiva-web/archiva-webapp/pom.xml
  12. 1
    1
      archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/menu.html
  13. 18
    0
      archiva-modules/archiva-web/archiva-webapp/src/test/jetty/jetty-env.xml
  14. 7
    1
      archiva-modules/archiva-web/archiva-webdav/pom.xml
  15. 1
    0
      pom.xml

+ 46
- 0
archiva-modules/archiva-web/archiva-webapp-test/pom.xml View File

@@ -103,6 +103,23 @@
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-common</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>neko-htmlunit</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit-core-js</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.cssparser</groupId>
<artifactId>cssparser</artifactId>
</exclusion>
<exclusion>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
</exclusion>

</exclusions>
</dependency>

@@ -183,6 +200,19 @@
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-common</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>neko-htmlunit</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit-core-js</artifactId>
</exclusion>
<exclusion>
<groupId>net.sourceforge.cssparser</groupId>
<artifactId>cssparser</artifactId>
</exclusion>

</exclusions>
</dependency>

@@ -289,6 +319,21 @@
</dependency>


<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>htmlunit-driver</artifactId>
<version>${htmlUnitVersion}</version>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>${htmlUnitVersion}</version>
<scope>test</scope>
</dependency>




</dependencies>

<build>
@@ -367,6 +412,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
<runOrder>alphabetical</runOrder>

+ 5
- 0
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/LoginTest.java View File

@@ -20,7 +20,9 @@ package org.apache.archiva.web.test;
*/

import org.apache.archiva.web.test.parent.AbstractArchivaTest;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.By;

/**
* Based on LoginTest of Emmanuel Venisse test.
@@ -59,6 +61,7 @@ public class LoginTest
{
goToLoginPage();
setFieldValue( "user-login-form-password", "password" );
waitPage();
clickLinkWithLocator( "modal-login-ok", true );
assertTextPresent( "This field is required." );
}
@@ -68,6 +71,8 @@ public class LoginTest
{
goToLoginPage();
setFieldValue( "user-login-form-username", getProperty( "ADMIN_USERNAME" ) );
Assert.assertTrue(getWebDriver().findElement( By.id("modal-login-ok") ).isDisplayed());
Assert.assertTrue(getWebDriver().findElement( By.id("modal-login-ok") ).isEnabled());
clickLinkWithLocator( "modal-login-ok", true );
assertTextPresent( "This field is required." );
}

+ 12
- 6
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/RepositoryAdminTest.java View File

@@ -22,6 +22,8 @@ package org.apache.archiva.web.test;
import org.apache.archiva.web.test.parent.AbstractArchivaTest;
import org.junit.Assert;
import org.junit.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;

/**
* Based on LoginTest of Emmanuel Venisse test.
@@ -40,9 +42,8 @@ public class RepositoryAdminTest
{
login( getAdminUsername(), getAdminPassword() );
clickLinkWithLocator( "menu-repositories-list-a", true );
// add custom repo
assertTextPresent( "Repositories Administration " );
assertTextPresent( "Repositories Administration" );
clickLinkWithXPath( "//a[@href='#remote-repositories-content']", true );
clickLinkWithXPath( "//a[@href='#remote-repository-edit']", true );
@@ -60,16 +61,21 @@ public class RepositoryAdminTest
assertTextPresent( "central" );
assertTextNotPresent( "myrepoid" );
clickButtonWithLocator( "proxy-connectors-view-tabs-a-edit", true );
getSelenium().select( "sourceRepoId", "internal" );
getSelenium().select( "targetRepoId", "myrepoid" );
selectValue( "sourceRepoId", "internal" );
// Workaround
// TODO: Check after upgrade of htmlunit, bootstrap or jquery
// TODO: Check whats wrong here
( (JavascriptExecutor) getWebDriver() ).executeScript( "$('#targetRepoId').show();" );
// End of Workaround
selectValue( "targetRepoId", "myrepoid" );
clickButtonWithLocator( "proxy-connector-btn-save", true);
assertTextPresent( "central" );
assertTextPresent( "myrepoid" );
clickLinkWithXPath( "//i[contains(concat(' ',normalize-space(@class),' '),' icon-resize-vertical ')]/../..", true );
assertTextPresent( "internal" );
// order test
Assert.assertTrue( "First repo is myrepo",getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" ).contains( "myrepoid" ));
Assert.assertTrue( "Second repo is central",getSelenium().getText("xpath=//div[@id='proxy-connector-edit-order-div']/div[2]" ).contains( "central" ));
Assert.assertTrue( "First repo is myrepo",findElement("//div[@id='proxy-connector-edit-order-div']/div[1]").getText().contains("myrepoid"));
Assert.assertTrue( "Second repo is central",findElement("//div[@id='proxy-connector-edit-order-div']/div[2]" ).getText().contains( "central" ));
// works until this point
/*getSelenium().mouseDown( "xpath=//div[@id='proxy-connector-edit-order-div']/div[1]" );

+ 33
- 2
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverBrowseTest.java View File

@@ -18,6 +18,8 @@ package org.apache.archiva.web.test;
* under the License.
*/

import com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutor;
import org.fluentlenium.adapter.junit.After;
import org.fluentlenium.configuration.ConfigurationProperties;
import org.fluentlenium.configuration.FluentConfiguration;
import org.junit.Assert;
@@ -28,8 +30,11 @@ import org.fluentlenium.core.domain.FluentList;
import org.fluentlenium.core.domain.FluentWebElement;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -58,9 +63,22 @@ public class WebDriverBrowseTest
@Override
public void takeScreenShot( String fileName )
{
log.info("Taking screenshot "+fileName);
WebdriverUtility.takeScreenShot( fileName, getDriver(), (a)->super.takeScreenShot( a ) );
}

@Override
protected void failed( String testName )
{
takeScreenShot( testName + ".png" );
}

@Override
public boolean canTakeScreenShot()
{
return true;
}

@Before
public void init()
{
@@ -68,6 +86,7 @@ public class WebDriverBrowseTest
setScreenshotMode( TriggerMode.AUTOMATIC_ON_FAIL );
setDriverLifecycle( DriverLifecycle.CLASS );


}

@Test
@@ -120,9 +139,21 @@ public class WebDriverBrowseTest
}
else
{
elements = find( "#login-link-a" );
elements = find( By.id("login-link-a"));
WebElement webElement = elements.get( 0 ).getElement();
Assert.assertEquals( "LOGIN", webElement.getText() );
for(FluentWebElement element : elements) {
log.info("Found login link: "+element.getElement().getTagName()+ " "+ element.getElement().getText());
}
log.info("innerText: "+webElement.getAttribute("innerText"));
log.info("value: "+webElement.getAttribute("value"));
log.info("innerHTML: "+webElement.getAttribute( "innerHTML" ));
log.info("JS: "+((( JavascriptExecutor)getDriver()).executeScript("return $(arguments[0]).text();", webElement)));
if (getDriver() instanceof HtmlUnitDriver) {
Assert.assertEquals( "LOGIN", webElement.getText().toUpperCase() );
} else
{
Assert.assertEquals( "LOGIN", webElement.getText() );
}
}

}

+ 31
- 2
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/WebDriverTest.java View File

@@ -18,6 +18,7 @@ package org.apache.archiva.web.test;
* under the License.
*/

import org.fluentlenium.adapter.junit.After;
import org.junit.Assert;
import org.apache.archiva.web.test.tools.WebdriverUtility;
import org.apache.commons.io.FileUtils;
@@ -28,8 +29,11 @@ import org.fluentlenium.core.domain.FluentList;
import org.fluentlenium.core.domain.FluentWebElement;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -52,9 +56,21 @@ public class WebDriverTest
@Override
public void takeScreenShot( String fileName )
{
log.info("Taking screenshot "+fileName);
WebdriverUtility.takeScreenShot( fileName, getDriver(), (a)->super.takeScreenShot( a ) );
}

@Override
protected void failed( String testName )
{
takeScreenShot( testName + ".png" );
}

@Override
public boolean canTakeScreenShot()
{
return true;
}

@Before
public void init() {
@@ -79,9 +95,22 @@ public class WebDriverTest
WebElement webElement = elements.get(0).getElement();
Assert.assertEquals("Create Admin User", webElement.getText());
} else {
elements = find("#login-link-a");
elements = find( By.id("login-link-a"));
for(FluentWebElement element : elements) {
log.info("Found login link: "+element.getElement().getTagName()+ " "+ element.getElement().getText());
}
WebElement webElement = elements.get(0).getElement();
Assert.assertEquals("LOGIN", webElement.getText());
log.info("innerText: "+webElement.getAttribute("innerText"));
log.info("value: "+webElement.getAttribute("value"));
log.info("innerHTML: "+webElement.getAttribute( "innerHTML" ));
log.info("JS: "+(((JavascriptExecutor)getDriver()).executeScript("return $(arguments[0]).text();", webElement)));
if (getDriver() instanceof HtmlUnitDriver ) {
Assert.assertEquals( "LOGIN", webElement.getText().toUpperCase() );
} else
{
Assert.assertEquals( "LOGIN", webElement.getText() );
}

}

}

+ 2
- 1
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java View File

@@ -174,7 +174,8 @@ public abstract class AbstractArchivaTest

protected void logout()
{
clickLinkWithText( "Logout" );
clickLinkWithLocator( "logout-link-a" );
waitPage();
assertTextNotPresent( "Current User:" );
assertLinkNotVisible( "Edit Details" );
assertLinkNotVisible( "Logout" );

+ 128
- 80
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java View File

@@ -20,7 +20,6 @@ package org.apache.archiva.web.test.parent;
*/

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.WebdriverUtility;
@@ -39,7 +38,13 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.support.ui.Select;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@@ -70,6 +75,8 @@ public abstract class AbstractSeleniumTest

private Selenium selenium = null;

WebDriver webDriver = null;

public Properties p;

/**
@@ -113,9 +120,10 @@ public abstract class AbstractSeleniumTest
{
WebDriver driver = WebdriverUtility.newWebDriver(browser, seleniumHost, seleniumPort, remoteSelenium);
WebDriverBackedSelenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
selenium.getWrappedDriver();
selenium.start();
// selenium.start();
selenium.setTimeout( Integer.toString( maxWaitTimeInMs ) );
this.selenium = selenium;
this.webDriver = driver;
}
}
catch ( Exception e )
@@ -146,8 +154,8 @@ public abstract class AbstractSeleniumTest
// if not admin user created create one
if ( isElementVisible( "create-admin-link" ) )
{
Assert.assertFalse( getSelenium().isVisible( "login-link-a" ) );
Assert.assertFalse( getSelenium().isVisible( "register-link-a" ) );
Assert.assertFalse( isElementVisible( "login-link-a" ) );
Assert.assertFalse( isElementVisible( "register-link-a" ) );
// skygo need to set to true for passing is that work as expected ?
clickLinkWithLocator( "create-admin-link-a", true );
assertCreateAdmin();
@@ -161,8 +169,14 @@ public abstract class AbstractSeleniumTest
}
else
{
Assert.assertTrue( getSelenium().isVisible( "login-link-a" ) );
Assert.assertTrue( getSelenium().isVisible( "register-link-a" ) );
try
{
Assert.assertNotNull( getWebDriver().findElement( By.id( "login-link-a" ) ) );
} catch (NoSuchElementException e) {
logger.info("ASSERT: login-link-a not found!");
}
Assert.assertTrue( isElementVisible( "login-link-a" ) );
Assert.assertTrue( isElementVisible( "register-link-a" ) );
login( getAdminUsername(), getAdminPassword() );
}

@@ -173,6 +187,10 @@ public abstract class AbstractSeleniumTest
return selenium;
}

public WebDriver getWebDriver() {
return this.webDriver;
}

protected String getProperty( String key )
{
return p.getProperty( key );
@@ -223,6 +241,7 @@ public abstract class AbstractSeleniumTest
{
getSelenium().open( baseUrl );
waitPage();
getWebDriver().manage().window().maximize();
// are we already logged in ?
if ( isElementVisible( "logout-link" ) ) //isElementPresent( "logoutLink" ) )
{
@@ -232,8 +251,17 @@ public abstract class AbstractSeleniumTest
}
else if ( isElementVisible( "login-link-a" ) )
{
clickLinkWithLocator( "login-link-a" );
clickLinkWithLocator( "login-link-a", true );
}
// This is a workaround for bug with HTMLUnit. The display attribute of the
// login dialog is not changed via the click.
// TODO: Check after changing jquery, bootstrap or htmlunit version
if (getWebDriver() instanceof HtmlUnitDriver)
{
( (JavascriptExecutor) getWebDriver() ).executeScript( "$('#modal-login').show();" );
}
// END OF WORKAROUND

assertLoginModal();
}

@@ -245,6 +273,7 @@ public abstract class AbstractSeleniumTest
assertElementPresent( "user-login-form-username" );
assertElementPresent( "user-login-form-password" );
assertButtonWithIdPresent( "modal-login-ok" );
Assert.assertTrue( isElementVisible( "modal-login-ok" ));
}


@@ -261,7 +290,10 @@ public abstract class AbstractSeleniumTest
public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword,
String assertReturnPage )
{
clickLinkWithLocator( "login-link-a", false );
clickLinkWithLocator( "login-link-a", true );
// TODO: Check whats wrong here
( (JavascriptExecutor) getWebDriver() ).executeScript( "$('#modal-login').show();" );

setFieldValue( "user-login-form-username", username );
setFieldValue( "user-login-form-password", password );
/*
@@ -314,7 +346,7 @@ public abstract class AbstractSeleniumTest
public void assertFieldValue( String fieldValue, String fieldName )
{
assertElementPresent( fieldName );
Assert.assertEquals( fieldValue, getSelenium().getValue( fieldName ) );
Assert.assertEquals( fieldValue, findElement(fieldName ).getAttribute( "value") );
}

public void assertPage( String title )
@@ -325,22 +357,22 @@ public abstract class AbstractSeleniumTest
public String getTitle()
{
// Collapse spaces
return getSelenium().getTitle().replaceAll( "[ \n\r]+", " " );
return getWebDriver().getTitle().replaceAll( "[ \n\r]+", " " );
}

public String getHtmlContent()
{
return getSelenium().getHtmlSource();
return getWebDriver().getPageSource();
}

public String getText( String locator )
{
return getSelenium().getText( locator );
return findElement(locator ).getText();
}

public void assertTextPresent( String text )
{
Assert.assertTrue( "'" + text + "' isn't present.", getSelenium().isTextPresent( text ) );
Assert.assertTrue( "'" + text + "' isn't present.", getWebDriver().getPageSource().contains( text ) );
}

/**
@@ -377,22 +409,22 @@ public abstract class AbstractSeleniumTest

public void assertLinkPresent( String text )
{
Assert.assertTrue( "The link '" + text + "' isn't present.", isElementPresent( "link=" + text ) );
Assert.assertTrue( "The link '" + text + "' isn't present.", isElementPresent( "//*[text()='" + text+"']//ancestor::a" ) );
}

public void assertLinkNotPresent( String text )
{
Assert.assertFalse( "The link('" + text + "' is present.", isElementPresent( "link=" + text ) );
Assert.assertFalse( "The link('" + text + "' is present.", isElementPresent( "//*[text()='" + text+"']//ancestor::a" ) );
}

public void assertLinkNotVisible( String text )
{
Assert.assertFalse( "The link('" + text + "' is visible.", isElementVisible( "link=" + text ) );
Assert.assertFalse( "The link('" + text + "' is visible.", isElementVisible( "//*[text()='" + text+"']//ancestor::a" ) );
}

public void assertLinkVisible( String text )
{
Assert.assertTrue( "The link('" + text + "' is not visible.", isElementVisible( "link=" + text ) );
Assert.assertTrue( "The link('" + text + "' is not visible.", isElementVisible( "//*[text()='" + text+"']//ancestor::a" ) );
}

public void assertImgWithAlt( String alt )
@@ -426,17 +458,26 @@ public abstract class AbstractSeleniumTest

public boolean isLinkPresent( String text )
{
return isElementPresent( "link=" + text );
return isElementPresent( "//*[text()='" + text +"']//ancestor::a" );
}

public boolean isElementPresent( String locator )
{
return getSelenium().isElementPresent( locator );
try
{
return findElement(locator ) != null;
} catch (Exception e) {
return false;
}
}

public boolean isElementVisible( String locator )
public boolean isElementVisible(String locator )
{
return getSelenium().isVisible( locator );
try {
return findElement(locator).isDisplayed();
} catch (Exception e) {
return false;
}
}


@@ -465,7 +506,7 @@ public abstract class AbstractSeleniumTest

public String getFieldValue( String fieldName )
{
return getSelenium().getValue( fieldName );
return findElement(fieldName ).getAttribute( "value" );
}

public String getCellValueFromTable( String tableElement, int row, int column )
@@ -475,25 +516,19 @@ public abstract class AbstractSeleniumTest

public void selectValue( String locator, String value )
{
getSelenium().select( locator, "label=" + value );
WebElement element = findElement(locator );
Select select = new Select(element);
select.selectByValue( value );
}


public void assertOptionPresent( String selectField, String[] options )
{
assertElementPresent( selectField );
String[] optionsPresent = getSelenium().getSelectOptions( selectField );
List<String> expected = Arrays.asList( options );
List<String> present = Arrays.asList( optionsPresent );
Assert.assertTrue( "Options expected are not included in present options", present.containsAll( expected ) );
public WebElement findElement(String locator) {
if (locator.startsWith("/")) {
return getWebDriver().findElement( By.xpath( locator ) );
} else {
return getWebDriver().findElement( By.id(locator) );
}
}

public void assertSelectedValue( String value, String fieldName )
{
assertElementPresent( fieldName );
String optionsPresent = getSelenium().getSelectedLabel( value );
Assert.assertEquals( optionsPresent, value );
}

public void submit()
{
@@ -572,7 +607,7 @@ public abstract class AbstractSeleniumTest

public void clickLinkWithText( String text, boolean wait )
{
clickLinkWithLocator( "link=" + text, wait );
clickLinkWithLocator( "//*[text()='" + text +"']//ancestor::a", wait );
}

public void clickLinkWithXPath( String xpath )
@@ -582,7 +617,7 @@ public abstract class AbstractSeleniumTest

public void clickLinkWithXPath( String xpath, boolean wait )
{
clickLinkWithLocator( "xpath=" + xpath, wait );
clickLinkWithLocator( xpath, wait );
}

public void clickLinkWithLocator( String locator )
@@ -593,7 +628,7 @@ public abstract class AbstractSeleniumTest
public void clickLinkWithLocator( String locator, boolean wait )
{
assertElementPresent( locator );
getSelenium().click( locator );
findElement(locator).click();
if ( wait )
{
waitPage();
@@ -608,7 +643,7 @@ public abstract class AbstractSeleniumTest
public void clickButtonWithLocator( String locator, boolean wait )
{
assertElementPresent( locator );
getSelenium().click( locator );
findElement(locator ).click();
if ( wait )
{
waitPage();
@@ -623,50 +658,49 @@ public abstract class AbstractSeleniumTest
{
entry = entries.next();

getSelenium().type( entry.getKey(), entry.getValue() );
setFieldValue( entry.getKey(), entry.getValue() );
}
}

public void setFieldValue( String fieldName, String value )
{
getSelenium().type( fieldName, value );
findElement(fieldName ).sendKeys( value );
}

public void checkField( String locator )
{
getSelenium().check( locator );
WebElement element = findElement(locator );
if (!element.isSelected()) {
element.click();
}
}

public void uncheckField( String locator )
{
getSelenium().uncheck( locator );
WebElement element = findElement(locator );
if (element.isSelected()) {
element.click();
}
}

public boolean isChecked( String locator )
{
return getSelenium().isChecked( locator );
return findElement(locator ).isSelected();
}

public void assertIsChecked( String locator )
{
Assert.assertTrue( getSelenium().isChecked( locator ) );

Assert.assertTrue( isChecked( locator ));
}

public void assertIsNotChecked( String locator )
{
Assert.assertFalse( getSelenium().isChecked( locator ) );
}

public void assertXpathCount( String locator, int expectedCount )
{
int count = getSelenium().getXpathCount( locator ).intValue();
Assert.assertEquals( count, expectedCount );
Assert.assertFalse( isChecked( locator ) );
}

public void assertElementValue( String locator, String expectedValue )
{
Assert.assertEquals( getSelenium().getValue( locator ), expectedValue );
}


public String captureScreenShotOnFailure( Throwable failure, String methodName, String className )
{
@@ -687,31 +721,45 @@ public abstract class AbstractSeleniumTest

targetPath.mkdirs();
Selenium selenium = getSelenium();
String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;

selenium.windowMaximize();
try
{
// save html to have a minimum feedback if jenkins firefox not up
File fileNameHTML = new File( new File( "target", "errorshtmlsnap" ) , fileBaseName + ".html" );
FileUtils.writeStringToFile( fileNameHTML, selenium.getHtmlSource() );
}
catch ( IOException e )
if (selenium!=null)
{
System.out.print( e.getMessage() );
e.printStackTrace();
}
File fileName = new File( targetPath, fileBaseName + ".png" );
String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;
File fileName = new File( targetPath, fileBaseName + ".png" );
selenium.windowMaximize();

try
{
selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "background=#FFFFFF" );
} catch (UnsupportedOperationException ex) {
logger.warn("Could not create screenshot. Not supported by this webdriver. "+selenium.getClass().getName());
if (selenium instanceof WebDriverBackedSelenium)
{
WebdriverUtility.takeScreenShot( fileName.getName(), ( (WebDriverBackedSelenium) selenium ).getWrappedDriver(),
(a)->selenium.captureEntirePageScreenshot( a, "background=#FFFFFF" )
);
} else
{

try
{
// save html to have a minimum feedback if jenkins firefox not up
File fileNameHTML = new File( new File( "target", "errorshtmlsnap" ), fileBaseName + ".html" );
FileUtils.writeStringToFile( fileNameHTML, selenium.getHtmlSource() );
}
catch ( IOException e )
{
System.out.print( e.getMessage() );
e.printStackTrace();
}


try
{
}
catch ( UnsupportedOperationException ex )
{
logger.warn( "Could not create screenshot. Not supported by this webdriver. " + selenium.getClass().getName() );
}
}
return fileName.getAbsolutePath();
} else {
return "";
}
return fileName.getAbsolutePath();
}

}

+ 7
- 0
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/ArchivaSeleniumExecutionRule.java View File

@@ -24,6 +24,8 @@ import org.junit.rules.MethodRule;
import org.junit.runner.Description;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author Olivier Lamy
@@ -31,6 +33,9 @@ import org.junit.runners.model.Statement;
public class ArchivaSeleniumExecutionRule
implements MethodRule //TestRule
{

final Logger log = LoggerFactory.getLogger( ArchivaSeleniumExecutionRule.class );

// FIXME cerate a separate TestRule for open and close calls ?
public Selenium selenium;

@@ -43,6 +48,7 @@ public class ArchivaSeleniumExecutionRule
}
catch ( Throwable e )
{
log.info("Exception thrown in Selenium test: "+e.getClass().getName()+" - "+e.getMessage());
String fileName =
( (AbstractSeleniumTest) target ).captureScreenShotOnFailure( e, method.getMethod().getName(),
target.getClass().getName() );
@@ -52,6 +58,7 @@ public class ArchivaSeleniumExecutionRule
finally
{
( (AbstractSeleniumTest) target ).close();

}
return new Statement()
{

+ 13
- 2
archiva-modules/archiva-web/archiva-webapp-test/src/test/java/org/apache/archiva/web/test/tools/WebdriverUtility.java View File

@@ -18,6 +18,7 @@ package org.apache.archiva.web.test.tools;
* under the License.
*/

import com.gargoylesoftware.htmlunit.WebClient;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.openqa.selenium.Capabilities;
@@ -122,8 +123,18 @@ public class WebdriverUtility
{
DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit();
capabilities.setJavascriptEnabled( true );
capabilities.setVersion( "firefox-51" );
return new HtmlUnitDriver( capabilities );
capabilities.setVersion( "firefox-52" );
HtmlUnitDriver driver = new HtmlUnitDriver( capabilities ) {
@Override
protected WebClient modifyWebClient( WebClient client )
{
client.getOptions().setThrowExceptionOnFailingStatusCode( false );
client.getOptions().setThrowExceptionOnScriptError( false );
client.getOptions().setCssEnabled( true );
return client;
}
};
return driver;
}

} catch (MalformedURLException e) {

+ 4
- 0
archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/log4j2-test.xml View File

@@ -30,6 +30,10 @@
<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="com.gargoylesoftware.htmlunit.javascript" level="error" />
<logger name="com.gargoylesoftware.htmlunit" level="error" />
<logger name="com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter" level="off" />


<root level="info">
<appender-ref ref="console"/>

+ 137
- 0
archiva-modules/archiva-web/archiva-webapp/pom.xml View File

@@ -962,6 +962,143 @@
</executions>
</plugin>
-->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.5.v20170502</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/archiva</contextPath>
</webApp>
<jettyXml>${basedir}/src/test/jetty/jetty-env.xml</jettyXml>

<systemProperties>
<systemProperty>
<name>plexus.home</name>
<value>${archivaAppServerBase}</value>
</systemProperty>
<systemProperty>
<name>appserver.base</name>
<value>${archivaAppServerBase}</value>
</systemProperty>
<systemProperty>
<name>appserver.home</name>
<value>${archivaAppServerBase}</value>
</systemProperty>
<systemProperty>
<name>derby.system.home</name>
<value>${archivaAppServerBase}/logs</value>
</systemProperty>
<systemProperty>
<name>java.io.tmpdir</name>
<value>${project.build.directory}</value>
</systemProperty>
<systemProperty>
<name>archiva.user.configFileName</name>
<value>${archivaAppServerBase}/conf/archiva.xml</value>
</systemProperty>
<systemProperty>
<name>archiva.devMode</name>
<value>${archiva.devMode}</value>
</systemProperty>
<systemProperty>
<name>archiva.javascriptLog</name>
<value>${archiva.javascriptLog}</value>
</systemProperty>
<systemProperty>
<name>archiva.logMissingI18n</name>
<value>${archiva.logMissingI18n}</value>
</systemProperty>
<systemProperty>
<name>cassandra.host</name>
<value>${cassandra.host}</value>
</systemProperty>
<systemProperty>
<name>cassandra.port</name>
<value>${cassandra.port}</value>
</systemProperty>
<systemProperty>
<name>archiva.repositorySessionFactory.id</name>
<value>${archiva.repositorySessionFactory.id}</value>
</systemProperty>
<systemProperty>
<name>org.apache.sirona.configuration.sirona.properties</name>
<value>${archiva.sirona.configuration}</value>
</systemProperty>
<systemProperty>
<name>AsyncLoggerConfig.WaitStrategy</name>
<value>Block</value>
</systemProperty>
<systemProperty>
<name>AsyncLogger.WaitStrategy</name>
<value>Block</value>
</systemProperty>
<systemProperty>
<name>openjpa.Log</name>
<value>${openjpa.Log}</value>
</systemProperty>
</systemProperties>

</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>
<dependency>
<groupId>org.apache.openjpa</groupId>
<artifactId>openjpa</artifactId>
<version>${openjpaVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jpa_2.0_spec</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.1_spec</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>net.sourceforge.serp</groupId>
<artifactId>serp</artifactId>
<version>1.15.1</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-io</artifactId>
<version>9.4.5.v20170502</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-util</artifactId>
<version>9.4.5.v20170502</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.4.5.v20170502</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.websocket</groupId>
<artifactId>websocket-client</artifactId>
<version>9.4.5.v20170502</version>
</dependency>

</dependencies>

</plugin>


<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>

+ 1
- 1
archiva-modules/archiva-web/archiva-webapp/src/main/webapp/js/templates/archiva/menu.html View File

@@ -88,7 +88,7 @@
</a>
</li>
<li id="login-link" style="display: none">
<a onclick="loginBox();" id="login-link-a">
<a onclick="loginBox(); return false;" id="login-link-a">
<span class="btn btn-success label force-upper-case">${$.i18n.prop('login')}</span>
</a>
</li>

+ 18
- 0
archiva-modules/archiva-web/archiva-webapp/src/test/jetty/jetty-env.xml View File

@@ -1,4 +1,22 @@
<?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">

+ 7
- 1
archiva-modules/archiva-web/archiva-webdav/pom.xml View File

@@ -193,8 +193,14 @@
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.13</version>
<version>${htmlUnitVersion}</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-websocket</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>

+ 1
- 0
pom.xml View File

@@ -99,6 +99,7 @@
<plexus-utils.version>3.0.15</plexus-utils.version>
<asfTomcatMavenPluginVersion>2.2</asfTomcatMavenPluginVersion>
<tomcat7Version>7.0.54</tomcat7Version>
<htmlUnitVersion>2.27</htmlUnitVersion>

<release.preparationGoals>clean install</release.preparationGoals>
<springockito.version>1.0.9</springockito.version>

Loading…
Cancel
Save