You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ev...@apache.org on 2006/11/06 17:04:10 UTC
svn commit: r471773 - in /maven/shared/trunk: ./ maven-web-ui-tests/
maven-web-ui-tests/src/ maven-web-ui-tests/src/main/
maven-web-ui-tests/src/main/java/ maven-web-ui-tests/src/main/java/org/
maven-web-ui-tests/src/main/java/org/apache/ maven-web-ui-...
Author: evenisse
Date: Mon Nov 6 08:04:08 2006
New Revision: 471773
URL: http://svn.apache.org/viewvc?view=rev&rev=471773
Log:
Add web-ui-tests. This module will be used by Archiva and Continuum for web UI tests
Added:
maven/shared/trunk/maven-web-ui-tests/ (with props)
maven/shared/trunk/maven-web-ui-tests/pom.xml (with props)
maven/shared/trunk/maven-web-ui-tests/src/
maven/shared/trunk/maven-web-ui-tests/src/main/
maven/shared/trunk/maven-web-ui-tests/src/main/java/
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/AbstractSeleniumTestCase.java (with props)
maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/XPathExpressionUtil.java (with props)
Modified:
maven/shared/trunk/pom.xml
Propchange: maven/shared/trunk/maven-web-ui-tests/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Nov 6 08:04:08 2006
@@ -0,0 +1,4 @@
+*.iml
+*.ipr
+*.iws
+target
Added: maven/shared/trunk/maven-web-ui-tests/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-web-ui-tests/pom.xml?view=auto&rev=471773
==============================================================================
--- maven/shared/trunk/maven-web-ui-tests/pom.xml (added)
+++ maven/shared/trunk/maven-web-ui-tests/pom.xml Mon Nov 6 08:04:08 2006
@@ -0,0 +1,68 @@
+<!--
+ ~ Copyright 2005-2006 The Apache Software Foundation.
+ ~
+ ~ Licensed 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.
+ -->
+
+<project>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.maven.shared</groupId>
+ <artifactId>maven-shared-components</artifactId>
+ <version>4-SNAPSHOT</version>
+ </parent>
+ <artifactId>maven-web-ui-tests</artifactId>
+ <name>Maven Shared Web UI tests</name>
+ <version>1.0-SNAPSHOT</version>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.plexus</groupId>
+ <artifactId>plexus-utils</artifactId>
+ <version>1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openqa.selenium.client-drivers</groupId>
+ <artifactId>selenium-java-client-driver</artifactId>
+ <version>0.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openqa.selenium.client-drivers</groupId>
+ <artifactId>selenium-java-client-driver</artifactId>
+ <version>0.8.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.openqa.selenium.server</groupId>
+ <artifactId>selenium-server</artifactId>
+ <version>0.8.1</version>
+ </dependency>
+ </dependencies>
+ <repositories>
+ <repository>
+ <id>openqa</id>
+ <name>OpenQA Repository</name>
+ <url>http://maven.openqa.org</url>
+ <layout>default</layout>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ </repository>
+ </repositories>
+</project>
\ No newline at end of file
Propchange: maven/shared/trunk/maven-web-ui-tests/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-web-ui-tests/pom.xml
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/AbstractSeleniumTestCase.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/AbstractSeleniumTestCase.java?view=auto&rev=471773
==============================================================================
--- maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/AbstractSeleniumTestCase.java (added)
+++ maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/AbstractSeleniumTestCase.java Mon Nov 6 08:04:08 2006
@@ -0,0 +1,294 @@
+package org.apache.maven.shared.web.test;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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 com.thoughtworks.selenium.DefaultSelenium;
+import com.thoughtworks.selenium.Selenium;
+import junit.framework.TestCase;
+import org.codehaus.plexus.util.StringUtils;
+import org.openqa.selenium.server.SeleniumServer;
+
+import java.util.Calendar;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id$
+ */
+public abstract class AbstractSeleniumTestCase
+ extends TestCase
+{
+ final public static String CHECKBOX_CHECK = "on";
+
+ final public static String CHECKBOX_UNCHECK = "off";
+
+ private Selenium sel;
+
+ public void setUp()
+ throws Exception
+ {
+ super.setUp();
+ String browser = System.getProperty( "browser" );
+ if ( StringUtils.isEmpty( browser ) )
+ {
+ browser = "*firefox";
+ }
+
+ sel = new DefaultSelenium( "localhost", SeleniumServer.DEFAULT_PORT, browser, getBaseUrl() );
+ sel.start();
+ initialize();
+ }
+
+ public void tearDown()
+ {
+ sel.stop();
+ }
+
+ public Selenium getSelenium()
+ {
+ return sel;
+ }
+
+ public abstract String getBaseUrl();
+
+ protected abstract void initialize();
+
+ protected abstract String getApplicationName();
+
+ protected abstract String getInceptionYear();
+
+ public void open( String url )
+ {
+ sel.open( url );
+ }
+
+ public String getTitle()
+ {
+ return sel.getTitle();
+ }
+
+ public String getHtmlContent()
+ {
+ return getSelenium().getHtmlSource();
+ }
+
+ public void assertTextPresent( String text )
+ {
+ assertTrue( "'" + text + "' isn't present.", sel.isTextPresent( text ) );
+ }
+
+ public void assertTextNotPresent( String text )
+ {
+ assertFalse( "'" + text + "' is present.", sel.isTextPresent( text ) );
+ }
+
+ public void assertElementPresent( String elementLocator )
+ {
+ assertTrue( "'" + elementLocator + "' isn't present.", sel.isElementPresent( elementLocator ) );
+ }
+
+ public void assertElementNotPresent( String elementLocator )
+ {
+ assertFalse( "'" + elementLocator + "' is present.", sel.isElementPresent( elementLocator ) );
+ }
+
+ public void assertLinkPresent( String text )
+ {
+ assertTrue( "The link '" + text + "' isn't present.", sel.isElementPresent( "link=" + text ) );
+ }
+
+ public void assertLinkNotPresent( String text )
+ {
+ assertFalse( "The link '" + text + "' is present.", sel.isElementPresent( "link=" + text ) );
+ }
+
+ public boolean isTextPresent( String text )
+ {
+ return sel.isTextPresent( text );
+ }
+
+ public boolean isLinkPresent( String text )
+ {
+ return sel.isElementPresent( "link=" + text );
+ }
+
+ public void waitPage()
+ {
+ waitPage( 30000 );
+ }
+
+ public void waitPage( int nbMillisecond )
+ {
+ sel.waitForPageToLoad( String.valueOf( nbMillisecond ) );
+ }
+
+ public void assertPage( String title )
+ {
+ System.out.println( title + "=>" + getTitle() );
+ assertEquals( title, getTitle() );
+ assertHeader();
+ assertFooter();
+ }
+
+ public abstract void assertHeader();
+
+ public void assertFooter()
+ {
+ assertTrue( sel.getText( "xpath=//div[@id='footer']/table/tbody/tr/td" ).startsWith( getApplicationName() + " " ) );
+ int currentYear = Calendar.getInstance().get( Calendar.YEAR );
+ assertTrue( sel.getText( "xpath=//div[@id='footer']/table/tbody/tr/td" ).endsWith(
+ " " + getInceptionYear() + "-" + currentYear + " Apache Software Foundation" ) );
+ }
+
+ public void submit()
+ {
+ clickLinkWithXPath( "//input[@type='submit']" );
+ }
+
+ public void clickButtonWithValue( String text )
+ {
+ clickButtonWithValue( text, true );
+ }
+
+ public void clickButtonWithValue( String text, boolean wait )
+ {
+ clickLinkWithXPath( "//input[@value='" + text + "']", wait );
+ }
+
+ public void clickLinkWithText( String text )
+ {
+ clickLinkWithText( text, true );
+ }
+
+ public void clickLinkWithText( String text, boolean wait )
+ {
+ clickLinkWithLocator( "link=" + text, wait );
+ }
+
+ public void clickLinkWithXPath( String xpath )
+ {
+ clickLinkWithXPath( xpath, true );
+ }
+
+ public void clickLinkWithXPath( String xpath, boolean wait )
+ {
+ clickLinkWithLocator( "xpath=" + xpath, wait );
+ }
+
+ public void clickLinkWithLocator( String locator )
+ {
+ clickLinkWithLocator( locator, true );
+ }
+
+ public void clickLinkWithLocator( String locator, boolean wait )
+ {
+ sel.click( locator );
+ if ( wait )
+ {
+ waitPage();
+ }
+ }
+
+ public void setFieldValue( String fieldName, String value )
+ {
+ sel.type( fieldName, value );
+ }
+
+ public void check( String locator )
+ {
+ sel.check( locator );
+ }
+
+ public void uncheck( String locator )
+ {
+ sel.uncheck( locator );
+ }
+
+ public boolean isChecked( String locator )
+ {
+ return sel.isChecked( locator );
+ }
+
+ //////////////////////////////////////
+ // Login
+ //////////////////////////////////////
+ public void login( String username, String password )
+ {
+ clickLinkWithText( "Login" );
+
+ assertLoginPage();
+
+ submitLoginPage( username, password );
+ }
+
+ public void assertLoginPage()
+ {
+ assertPage( "Login Page" );
+ assertTextPresent( "Login" );
+ assertTextPresent( "Username" );
+ assertTextPresent( "Password" );
+ assertTextPresent( "Remember Me" );
+ assertFalse( isChecked( "rememberMe" ) );
+ }
+
+ public void submitLoginPage( String username, String password )
+ {
+ submitLoginPage( username, password, false, true );
+ }
+
+ public void submitLoginPage( String username, String password, boolean validUsernamePassword )
+ {
+ submitLoginPage( username, password, false, validUsernamePassword );
+ }
+
+ public void submitLoginPage( String username, String password, boolean rememberMe, boolean validUsernamePassword )
+ {
+ assertLoginPage();
+ setFieldValue( "username", username );
+ setFieldValue( "password", password );
+ if ( rememberMe )
+ {
+ check( "rememberMe" );
+ }
+ clickButtonWithValue( "Login" );
+ waitPage();
+ if ( validUsernamePassword )
+ {
+ assertTextPresent( "Welcome, " + username + " - Logout" );
+ assertLinkPresent( username );
+ assertLinkPresent( "Logout" );
+ }
+ else
+ {
+ assertLoginPage();
+ }
+ }
+
+ public boolean isAuthenticated()
+ {
+ return !( isLinkPresent( "Login" ) && isLinkPresent( "Register" ) );
+ }
+
+ //////////////////////////////////////
+ // Logout
+ //////////////////////////////////////
+ public void logout()
+ {
+ assertTrue( "User wasn't authenticated.", isAuthenticated() );
+ clickLinkWithText( "Logout" );
+ assertFalse( "The user is always authenticated after a logout.", isAuthenticated() );
+ }
+}
Propchange: maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/AbstractSeleniumTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/AbstractSeleniumTestCase.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/XPathExpressionUtil.java
URL: http://svn.apache.org/viewvc/maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/XPathExpressionUtil.java?view=auto&rev=471773
==============================================================================
--- maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/XPathExpressionUtil.java (added)
+++ maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/XPathExpressionUtil.java Mon Nov 6 08:04:08 2006
@@ -0,0 +1,162 @@
+package org.apache.maven.shared.web.test;
+
+/*
+ * Copyright 2005-2006 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * Utility class for creating xpath expressions
+ */
+public class XPathExpressionUtil
+{
+ public static final String CONTAINS = "contains";
+
+ public static final String AND = " and ";
+
+ public static final String CURRENT_NODE = "./";
+
+ public static final String PARENT_NODE = "../";
+
+ public static final String GRANDPARENT_NODE = "../../";
+
+ public static final String ELEMENT_ANY_LEVEL = "//";
+
+ public static final String TABLE_COLUMN = "td";
+
+ public static final String TABLE_ROW = "tr";
+
+ public static final String START_NODE_TEST = "[";
+
+ public static final String END_NODE_TEST = "]";
+
+ public static final String ANCHOR = "a";
+
+ /**
+ * expression for acquiring an element in one of the table columns
+ *
+ * @param element the node element
+ * @param elementIndex column index of the element, used for skipping
+ * @param columnValues the values to be matched in each column, element column is included
+ * @return
+ */
+ public static String columnElementWithSiblingColumnValues( String element, int elementIndex, String[] columnValues )
+ {
+ return columnElementWithSiblingColumnValues( element, elementIndex, null, columnValues );
+ }
+
+ /**
+ * expression for acquiring an element in one of the table columns
+ *
+ * @param element the node element
+ * @param elementIndex column index of the element, used for skipping
+ * @param elementValue the matched element value
+ * @param columnValues the values to be matched in each column, element column is included
+ * @return
+ */
+ public static String columnElementWithSiblingColumnValues( String element, int elementIndex, String elementValue, String[] columnValues )
+ {
+ String xpathExpression = null;
+
+ if ( ( columnValues != null ) && ( columnValues.length > 0 ) )
+ {
+ xpathExpression = ELEMENT_ANY_LEVEL + element;
+ xpathExpression += START_NODE_TEST;
+
+ if ( elementValue != null)
+ {
+ xpathExpression += contains( elementValue );
+ xpathExpression += (columnValues.length > 0 ) ? AND : "";
+ }
+
+ // we are two levels below the table row element ( tr/td/<element> )
+ xpathExpression += matchColumns( GRANDPARENT_NODE, columnValues, elementIndex );
+
+ xpathExpression += END_NODE_TEST;
+ }
+
+ return xpathExpression;
+ }
+
+ /**
+ * expression for acquiring the table row that matches all column values with the same order
+ * as the list
+ *
+ * @param columnValues the matched list of columnValues
+ * @return
+ */
+ public static String matchTableRowOrderedValues( String[] columnValues )
+ {
+ String xpathExpression = null;
+
+ if ( ( columnValues != null ) && ( columnValues.length > 0 ) )
+ {
+ xpathExpression = new String( ELEMENT_ANY_LEVEL + TABLE_ROW + START_NODE_TEST );
+ xpathExpression += matchColumns( columnValues );
+ xpathExpression += END_NODE_TEST;
+ }
+
+ return xpathExpression;
+ }
+
+ private static String matchColumns( String[] columnValues )
+ {
+ return matchColumns( columnValues, -1 );
+ }
+
+ private static String matchColumns( String[] columnValues, int skipIndex )
+ {
+ return matchColumns( null, columnValues, skipIndex );
+ }
+
+ private static String matchColumns( String parent, String[] columnValues, int skipIndex )
+ {
+ String xpathExpression = "";
+
+ for (int nIndex = 0; nIndex < columnValues.length; nIndex++ )
+ {
+ if ( ( skipIndex != nIndex ) || (skipIndex == -1 ) )
+ {
+ // prepend "and" if index > 0
+ xpathExpression += ( ( nIndex > 0 ) ? AND : "" );
+ xpathExpression += contains( parent, columnPosition( nIndex + 1 ), columnValues[ nIndex ] );
+ }
+ }
+
+ return xpathExpression;
+ }
+
+ private static String columnPosition( int nIndex )
+ {
+ return new String( TABLE_COLUMN + "[" + nIndex + "]" );
+ }
+
+ private static String contains( String parent, String element, String matchedString )
+ {
+ String finalElement = ( parent != null ) ? parent : "";
+ finalElement += element;
+
+ return contains( finalElement, matchedString );
+ }
+
+ private static String contains( String matchedString )
+ {
+ return contains( ".", matchedString );
+ }
+
+ private static String contains( String axis, String matchedString )
+ {
+ return new String( CONTAINS + "(" + axis + "," + "'" + matchedString + "')" );
+ }
+}
Propchange: maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/XPathExpressionUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/shared/trunk/maven-web-ui-tests/src/main/java/org/apache/maven/shared/web/test/XPathExpressionUtil.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/shared/trunk/pom.xml
URL: http://svn.apache.org/viewvc/maven/shared/trunk/pom.xml?view=diff&rev=471773&r1=471772&r2=471773
==============================================================================
--- maven/shared/trunk/pom.xml (original)
+++ maven/shared/trunk/pom.xml Mon Nov 6 08:04:08 2006
@@ -37,6 +37,7 @@
<module>maven-plugin-testing-harness</module>
<module>maven-verifier</module>
<module>maven-release-manager</module>
+ <module>maven-web-ui-tests</module>
</modules>
<scm>
<connection>scm:svn:http://svn.apache.org/repos/asf/maven/shared/trunk/</connection>