aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-webapp-test-js
diff options
context:
space:
mode:
Diffstat (limited to 'archiva-modules/archiva-web/archiva-webapp-test-js')
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml20
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java4
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java22
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java7
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java5
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/listener/CaptureScreenShotsListener.java109
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java27
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java2
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java32
-rw-r--r--archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java74
10 files changed, 111 insertions, 191 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml b/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml
index d0f8faf7c..b58d589fa 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml
@@ -34,11 +34,7 @@
</properties>
<dependencies>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <scope>test</scope>
- </dependency>
+
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
@@ -202,20 +198,6 @@
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<redirectTestOutputToFile>false</redirectTestOutputToFile>
- <properties>
- <!--
- Use this instead of suiteXmlFiles so that we can add the exclusion, as it is only accepted without suiteXmlFiles
- -->
- <property>
- <name>listener</name>
- <value>org.apache.archiva.web.test.listener.CaptureScreenShotsListener</value>
- </property>
- <property>
- <name>excludegroups</name>
- <!-- Exclude on all browsers but Firefox, as it is the only one that Selenium supports file uploads on -->
- <value>${excluded.groups}</value>
- </property>
- </properties>
<runOrder>alphabetical</runOrder>
<!-- see https://jira.codehaus.org/browse/SUREFIRE-828 -->
<excludedGroups>foonotatestsurefireissue</excludedGroups>
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
index 721d8ba39..8be57aa14 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
@@ -20,13 +20,13 @@ package org.apache.archiva.web.test;
*/
import org.apache.archiva.web.test.parent.AbstractArchivaTest;
-import org.testng.annotations.Test;
+import org.junit.Test;
public class ArchivaAdminTest
extends AbstractArchivaTest
{
- @Test( groups = { "about" }, alwaysRun = true )
+ @Test
public void testHome()
{
getSelenium().open( baseUrl );
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
index 29ba5ef0c..0c888e03c 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
@@ -20,9 +20,7 @@ package org.apache.archiva.web.test;
*/
import org.apache.archiva.web.test.parent.AbstractArchivaTest;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Test;
+import org.junit.Test;
/**
* Based on LoginTest of Emmanuel Venisse test.
@@ -31,10 +29,11 @@ import org.testng.annotations.Test;
* @version $Id$
*/
-@Test( groups = { "login" }, dependsOnGroups = { "about" } )
+
public class LoginTest
extends AbstractArchivaTest
{
+
@Test
public void testWithBadUsername()
{
@@ -64,7 +63,7 @@ public class LoginTest
assertTextPresent( "This field is required." );
}
- @Test( alwaysRun = true )
+ @Test
public void testWithEmptyPassword()
{
goToLoginPage();
@@ -84,18 +83,5 @@ public class LoginTest
assertUserLoggedIn( getProperty( "ADMIN_USERNAME" ) );
}
- @BeforeTest
- public void open()
- throws Exception
- {
- super.open();
- }
- @Override
- @AfterTest
- public void close()
- throws Exception
- {
- super.close();
- }
} \ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
index 388eb5f37..1a13488a0 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
@@ -20,16 +20,17 @@ package org.apache.archiva.web.test;
import org.apache.archiva.web.test.parent.AbstractArchivaTest;
import org.apache.commons.lang.StringUtils;
-import org.testng.Assert;
-import org.testng.annotations.Test;
+import org.junit.Assert;
+import org.junit.Test;
+
/**
* @author Olivier Lamy
*/
-@Test( groups = { "usermanagement" }, dependsOnGroups = "about" )
public class RolesManagementTest
extends AbstractArchivaTest
{
+
@Test
public void testReadRolesAndUpdateDescription()
throws Exception
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
index 3478c1365..720e9ba19 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
@@ -19,15 +19,16 @@ package org.apache.archiva.web.test;
*/
import org.apache.archiva.web.test.parent.AbstractArchivaTest;
-import org.testng.annotations.Test;
+import org.junit.Test;
/**
* @author Olivier Lamy
*/
-@Test( groups = { "usermanagement" }, dependsOnGroups = { "about" } )
+
public class UserManagementTest
extends AbstractArchivaTest
{
+ @Test
public void testBasicAddDeleteUser()
{
username = getProperty( "GUEST_USERNAME" );
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/listener/CaptureScreenShotsListener.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/listener/CaptureScreenShotsListener.java
deleted file mode 100644
index 1cc89ed76..000000000
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/listener/CaptureScreenShotsListener.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package org.apache.archiva.web.test.listener;
-
-/*
- * 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 com.thoughtworks.selenium.Selenium;
-import org.apache.archiva.web.test.parent.AbstractSeleniumTest;
-import org.apache.commons.io.FileUtils;
-import org.testng.ITestResult;
-import org.testng.TestListenerAdapter;
-
-import java.io.File;
-import java.io.IOException;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.regex.Pattern;
-
-public class CaptureScreenShotsListener
- extends TestListenerAdapter
-{
- @Override
- public void onTestSkipped( ITestResult tr )
- {
- System.out.println( "Test " + tr.getName() + " -> Skipped" );
- super.onTestSkipped( tr );
- }
-
- @Override
- public void onTestFailure( ITestResult tr )
- {
- captureError( tr );
- System.out.println( "Test " + tr.getName() + " -> Failed" );
- super.onTestFailure( tr );
- }
-
- @Override
- public void onTestSuccess( ITestResult tr )
- {
- System.out.println( "Test " + tr.getName() + " -> Success" );
- super.onTestFailure( tr );
- }
-
- private void captureError( ITestResult tr )
- {
- SimpleDateFormat sdf = new SimpleDateFormat( "yyyy.MM.dd-HH_mm_ss" );
- String time = sdf.format( new Date() );
- File targetPath = new File( "target", "screenshots" );
- StackTraceElement stackTrace[] = tr.getThrowable().getStackTrace();
- String cName = tr.getTestClass().getName();
- int index = getStackTraceIndexOfCallingClass( cName, stackTrace );
- String methodName = stackTrace[index].getMethodName();
- int lNumber = stackTrace[index].getLineNumber();
- String lineNumber = Integer.toString( lNumber );
- String className = cName.substring( cName.lastIndexOf( '.' ) + 1 );
- targetPath.mkdirs();
- Selenium selenium = AbstractSeleniumTest.getSelenium();
- String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;
- try
- {
- selenium.windowMaximize();
- File fileName = new File( targetPath, fileBaseName + ".png" );
- selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "background=#FFFFFF" );
- }
- catch ( RuntimeException e )
- {
- System.out.println( "Error when take screenshot for test " + tr.getName() + ": " + e.getMessage() );
- }
- try
- {
- File fileName = new File( targetPath, fileBaseName + ".html" );
- FileUtils.writeStringToFile( fileName, selenium.getHtmlSource() );
- }
- catch ( IOException ioe )
- {
- System.out.println( ioe.getMessage() );
- }
- }
-
- private int getStackTraceIndexOfCallingClass( String nameOfClass, StackTraceElement stackTrace[] )
- {
- boolean match = false;
- int i = 0;
- do
- {
- String className = stackTrace[i].getClassName();
- match = Pattern.matches( nameOfClass, className );
- i++;
- }
- while ( match == false );
- i--;
- return i;
- }
-} \ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
index 5cfc89a12..18419c3ad 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
@@ -1,11 +1,10 @@
package org.apache.archiva.web.test.parent;
-import org.testng.Assert;
-import org.testng.annotations.AfterTest;
-import org.testng.annotations.BeforeSuite;
-import org.testng.annotations.BeforeTest;
-import org.testng.annotations.Optional;
-import org.testng.annotations.Parameters;
+import org.apache.archiva.web.test.tools.ArchivaSeleniumRunner;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.runner.RunWith;
import java.io.File;
import java.io.IOException;
@@ -29,6 +28,7 @@ import java.io.IOException;
* under the License.
*/
+@RunWith( ArchivaSeleniumRunner.class )
public abstract class AbstractArchivaTest
extends AbstractSeleniumTest
{
@@ -37,7 +37,7 @@ public abstract class AbstractArchivaTest
protected String fullname;
@Override
- @AfterTest
+ @After
public void close()
throws Exception
{
@@ -45,25 +45,24 @@ public abstract class AbstractArchivaTest
}
@Override
- @BeforeSuite
+ @Before
public void open()
throws Exception
{
super.open();
+ assertAdminCreated();
}
public void assertAdminCreated()
throws Exception
{
initializeArchiva( System.getProperty( "baseUrl" ), System.getProperty( "browser" ),
- Integer.getInteger( "maxWaitTimeInMs" ), System.getProperty( "seleniumHost" ),
- Integer.getInteger( "seleniumPort" ) );
+ Integer.getInteger( "maxWaitTimeInMs" ), System.getProperty( "seleniumHost", "localhost" ),
+ Integer.getInteger( "seleniumPort", 4444 ) );
}
- @BeforeTest
- @Parameters( { "baseUrl", "browser", "maxWaitTimeInMs", "seleniumHost", "seleniumPort" } )
- public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs,
- @Optional( "localhost" ) String seleniumHost, @Optional( "4444" ) int seleniumPort )
+ public void initializeArchiva( String baseUrl, String browser, int maxWaitTimeInMs, String seleniumHost,
+ int seleniumPort )
throws Exception
{
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
index 91af2cf60..c134a06e3 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
@@ -21,7 +21,7 @@ package org.apache.archiva.web.test.parent;
import java.io.File;
-public class AbstractMergingRepositoriesTest
+public abstract class AbstractMergingRepositoriesTest
extends AbstractArchivaTest
{
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
index a1214acfb..a90e6ac2b 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
@@ -19,8 +19,9 @@ package org.apache.archiva.web.test.parent;
* under the License.
*/
+import org.junit.Assert;
+
import java.io.File;
-import org.testng.Assert;
public abstract class AbstractRepositoryTest
extends AbstractArchivaTest
@@ -145,7 +146,9 @@ public abstract class AbstractRepositoryTest
"Network Proxy*:,Managed Repository*:,Remote Repository*:,Policies:,Return error when:,On remote error:,Releases:,Snapshots:,Checksum:,Cache failures:,Properties:,No properties have been set.,Black List:,No black list patterns have been set.,White List:,No white list patterns have been set.";
String[] arrayProxy = proxy.split( "," );
for ( String arrayproxy : arrayProxy )
+ {
assertTextPresent( arrayproxy );
+ }
/*
* String proxyElements =
* "addProxyConnector_connector_proxyId,addProxyConnector_connector_sourceRepoId,addProxyConnector_connector_targetRepoId,policy_propagate-errors-on-update,policy_propagate-errors,policy_releases,policy_snapshots,policy_checksum,policy_cache-failures,propertiesEntry,propertiesValue,blackListEntry,whiteListEntry"
@@ -206,12 +209,16 @@ public abstract class AbstractRepositoryTest
String remote = "Identifier*:,Name*:,URL*:,Username:,Password:,Timeout in seconds:,Type:";
String[] arrayRemote = remote.split( "," );
for ( String arrayremote : arrayRemote )
+ {
assertTextPresent( arrayremote );
+ }
String remoteElements =
"addRemoteRepository_repository_id,addRemoteRepository_repository_name,addRemoteRepository_repository_url,addRemoteRepository_repository_userName,addRemoteRepository_repository_password,addRemoteRepository_repository_timeout,addRemoteRepository_repository_layout";
String[] arrayRemoteElements = remoteElements.split( "," );
for ( String arrayremotelement : arrayRemoteElements )
+ {
assertElementPresent( arrayremotelement );
+ }
}
public void assertDeleteRemoteRepositoryPage()
@@ -264,18 +271,19 @@ public abstract class AbstractRepositoryTest
clickButtonWithValue( "Update Repository" );
}
- public void editManagedRepository(String name, String directory, String indexDirectory, String type, String cron, String daysOlder, String retentionCount)
+ public void editManagedRepository( String name, String directory, String indexDirectory, String type, String cron,
+ String daysOlder, String retentionCount )
{
goToRepositoriesPage();
clickLinkWithXPath( "//div[@id='contentArea']/div/div[5]/div[1]/a[1]/img" );
assertPage( "Apache Archiva \\ Admin: Edit Managed Repository" );
- setFieldValue( "repository.name" , name );
- setFieldValue( "repository.location" , directory );
- setFieldValue( "repository.indexDirectory" , indexDirectory );
+ setFieldValue( "repository.name", name );
+ setFieldValue( "repository.location", directory );
+ setFieldValue( "repository.indexDirectory", indexDirectory );
selectValue( "repository.layout", type );
- setFieldValue( "repository.cronExpression" , cron );
- setFieldValue( "repository.daysOlder" , daysOlder );
- setFieldValue( "repository.retentionCount" , retentionCount );
+ setFieldValue( "repository.cronExpression", cron );
+ setFieldValue( "repository.daysOlder", daysOlder );
+ setFieldValue( "repository.retentionCount", retentionCount );
clickButtonWithValue( "Update Repository" );
}
@@ -311,27 +319,35 @@ public abstract class AbstractRepositoryTest
"**/*.pom,**/*.jar,**/*.ear,**/*.war,**/*.car,**/*.sar,**/*.mar,**/*.rar,**/*.dtd,**/*.tld,**/*.tar.gz,**/*.tar.bz2,**/*.zip";
String[] arrayArtifactTypes = artifactsTypes.split( "," );
for ( int i = 0; i < arrayArtifactTypes.length; i++ )
+ {
Assert.assertEquals( getSelenium().getTable( "//div[@id='contentArea']/div/div[1]/table." + i + ".0" ),
arrayArtifactTypes[i] );
+ }
String autoremove = "**/*.bak,**/*~,**/*-";
String[] arrayAutoremove = autoremove.split( "," );
for ( int i = 0; i < arrayAutoremove.length; i++ )
+ {
Assert.assertEquals( getSelenium().getTable( "//div[@id='contentArea']/div/div[2]/table." + i + ".0" ),
arrayAutoremove[i] );
+ }
String ignored = "**/.htaccess,**/KEYS,**/*.rb,**/*.sh,**/.svn/**,**/.DAV/**";
String[] arrayIgnored = ignored.split( "," );
for ( int i = 0; i < arrayIgnored.length; i++ )
+ {
Assert.assertEquals( getSelenium().getTable( "//div[@id='contentArea']/div/div[3]/table." + i + ".0" ),
arrayIgnored[i] );
+ }
String indexableContent =
"**/*.txt,**/*.TXT,**/*.block,**/*.config,**/*.pom,**/*.xml,**/*.xsd,**/*.dtd,**/*.tld";
String[] arrayIndexableContent = indexableContent.split( "," );
for ( int i = 0; i < arrayIndexableContent.length; i++ )
+ {
Assert.assertEquals( getSelenium().getTable( "//div[@id='contentArea']/div/div[4]/table." + i + ".0" ),
arrayIndexableContent[i] );
+ }
}
// ///////////////////////////////////////////
diff --git a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
index a394b5923..8afd1bedb 100644
--- a/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
+++ b/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
@@ -21,18 +21,23 @@ package org.apache.archiva.web.test.parent;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
+import org.apache.archiva.web.test.tools.AfterSeleniumFailure;
import org.apache.commons.io.IOUtils;
-import org.testng.Assert;
+import org.junit.Assert;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
+import java.util.regex.Pattern;
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -123,7 +128,7 @@ public abstract class AbstractSeleniumTest
}
/**
- * Close selenium session. Called from AfterSuite method of sub-class
+ * Close selenium session.
*/
public void close()
throws Exception
@@ -168,7 +173,7 @@ public abstract class AbstractSeleniumTest
public void assertTextPresent( String text )
{
- Assert.assertTrue( getSelenium().isTextPresent( text ), "'" + text + "' isn't present." );
+ Assert.assertTrue( "'" + text + "' isn't present.", getSelenium().isTextPresent( text ) );
}
/**
@@ -185,42 +190,42 @@ public abstract class AbstractSeleniumTest
present = present || getSelenium().isTextPresent( text );
sb.append( " " + text + " " );
}
- Assert.assertTrue( present, "'one of the following test " + sb.toString() + "' isn't present." );
+ Assert.assertTrue( "'one of the following test " + sb.toString() + "' isn't present.", present );
}
public void assertTextNotPresent( String text )
{
- Assert.assertFalse( getSelenium().isTextPresent( text ), "'" + text + "' is present." );
+ Assert.assertFalse( "'" + text + "' is present.", getSelenium().isTextPresent( text ) );
}
public void assertElementPresent( String elementLocator )
{
- Assert.assertTrue( isElementPresent( elementLocator ), "'" + elementLocator + "' isn't present." );
+ Assert.assertTrue( "'" + elementLocator + "' isn't present.", isElementPresent( elementLocator ) );
}
public void assertElementNotPresent( String elementLocator )
{
- Assert.assertFalse( isElementPresent( elementLocator ), "'" + elementLocator + "' is present." );
+ Assert.assertFalse( "'" + elementLocator + "' is present.", isElementPresent( elementLocator ) );
}
public void assertLinkPresent( String text )
{
- Assert.assertTrue( isElementPresent( "link=" + text ), "The link '" + text + "' isn't present." );
+ Assert.assertTrue( "The link '" + text + "' isn't present.", isElementPresent( "link=" + text ) );
}
public void assertLinkNotPresent( String text )
{
- Assert.assertFalse( isElementPresent( "link=" + text ), "The link('" + text + "' is present." );
+ Assert.assertFalse( "The link('" + text + "' is present.", isElementPresent( "link=" + text ) );
}
public void assertLinkNotVisible( String text )
{
- Assert.assertFalse( isElementVisible( "link=" + text ), "The link('" + text + "' is visible." );
+ Assert.assertFalse( "The link('" + text + "' is visible.", isElementVisible( "link=" + text ) );
}
public void assertLinkVisible( String text )
{
- Assert.assertTrue( isElementVisible( "link=" + text ), "The link('" + text + "' is not visible." );
+ Assert.assertTrue( "The link('" + text + "' is not visible.", isElementVisible( "link=" + text ) );
}
public void assertImgWithAlt( String alt )
@@ -313,7 +318,7 @@ public abstract class AbstractSeleniumTest
String[] optionsPresent = getSelenium().getSelectOptions( selectField );
List<String> expected = Arrays.asList( options );
List<String> present = Arrays.asList( optionsPresent );
- Assert.assertTrue( present.containsAll( expected ), "Options expected are not included in present options" );
+ Assert.assertTrue( "Options expected are not included in present options", present.containsAll( expected ) );
}
public void assertSelectedValue( String value, String fieldName )
@@ -330,17 +335,17 @@ public abstract class AbstractSeleniumTest
public void assertButtonWithValuePresent( String text )
{
- Assert.assertTrue( isButtonWithValuePresent( text ), "'" + text + "' button isn't present" );
+ Assert.assertTrue( "'" + text + "' button isn't present", isButtonWithValuePresent( text ) );
}
public void assertButtonWithIdPresent( String id )
{
- Assert.assertTrue( isButtonWithIdPresent( id ), "'Button with id =" + id + "' isn't present" );
+ Assert.assertTrue( "'Button with id =" + id + "' isn't present", isButtonWithIdPresent( id ) );
}
public void assertButtonWithValueNotPresent( String text )
{
- Assert.assertFalse( isButtonWithValuePresent( text ), "'" + text + "' button is present" );
+ Assert.assertFalse( "'" + text + "' button is present", isButtonWithValuePresent( text ) );
}
public boolean isButtonWithValuePresent( String text )
@@ -496,4 +501,43 @@ public abstract class AbstractSeleniumTest
Assert.assertEquals( getSelenium().getValue( locator ), expectedValue );
}
+ @AfterSeleniumFailure
+ public void captureScreenShotOnFailure( Throwable failure )
+ {
+ SimpleDateFormat sdf = new SimpleDateFormat( "yyyy.MM.dd-HH_mm_ss" );
+ String time = sdf.format( new Date() );
+ File targetPath = new File( "target", "screenshots" );
+ StackTraceElement stackTrace[] = failure.getStackTrace();
+ String cName = this.getClass().getName();
+ int index = getStackTraceIndexOfCallingClass( cName, stackTrace );
+ String methodName = stackTrace[index].getMethodName();
+ int lNumber = stackTrace[index].getLineNumber();
+ String lineNumber = Integer.toString( lNumber );
+ String className = cName.substring( cName.lastIndexOf( '.' ) + 1 );
+ targetPath.mkdirs();
+ Selenium selenium = AbstractSeleniumTest.getSelenium();
+ String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-" + time;
+
+ selenium.windowMaximize();
+
+ File fileName = new File( targetPath, fileBaseName + ".png" );
+ selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "background=#FFFFFF" );
+
+ }
+
+ private int getStackTraceIndexOfCallingClass( String nameOfClass, StackTraceElement stackTrace[] )
+ {
+ boolean match = false;
+ int i = 0;
+ do
+ {
+ String className = stackTrace[i].getClassName();
+ match = Pattern.matches( nameOfClass, className );
+ i++;
+ }
+ while ( match == false );
+ i--;
+ return i;
+ }
+
} \ No newline at end of file