mirror of
https://github.com/apache/archiva.git
synced 2025-03-08 01:43:06 +00:00
move to a junit based solution for selenium test as it's very convenient to test single test with -Dtest=MyClass#myTest and was not possible or complicated cli with TestNG
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1296187 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6f416163a7
commit
9b375e97bd
@ -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>
|
||||
|
@ -20,13 +20,13 @@
|
||||
*/
|
||||
|
||||
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 );
|
||||
|
@ -20,9 +20,7 @@
|
||||
*/
|
||||
|
||||
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 @@
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
@Test( groups = { "login" }, dependsOnGroups = { "about" } )
|
||||
|
||||
public class LoginTest
|
||||
extends AbstractArchivaTest
|
||||
{
|
||||
|
||||
@Test
|
||||
public void testWithBadUsername()
|
||||
{
|
||||
@ -64,7 +63,7 @@ public void testWithEmptyUsername()
|
||||
assertTextPresent( "This field is required." );
|
||||
}
|
||||
|
||||
@Test( alwaysRun = true )
|
||||
@Test
|
||||
public void testWithEmptyPassword()
|
||||
{
|
||||
goToLoginPage();
|
||||
@ -84,18 +83,5 @@ public void testWithCorrectUsernamePassword()
|
||||
assertUserLoggedIn( getProperty( "ADMIN_USERNAME" ) );
|
||||
}
|
||||
|
||||
@BeforeTest
|
||||
public void open()
|
||||
throws Exception
|
||||
{
|
||||
super.open();
|
||||
}
|
||||
|
||||
@Override
|
||||
@AfterTest
|
||||
public void close()
|
||||
throws Exception
|
||||
{
|
||||
super.close();
|
||||
}
|
||||
}
|
@ -20,16 +20,17 @@
|
||||
|
||||
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
|
||||
|
@ -19,15 +19,16 @@
|
||||
*/
|
||||
|
||||
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" );
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
@ -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 @@
|
||||
* 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 void close()
|
||||
}
|
||||
|
||||
@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
|
||||
{
|
||||
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class AbstractMergingRepositoriesTest
|
||||
public abstract class AbstractMergingRepositoriesTest
|
||||
extends AbstractArchivaTest
|
||||
{
|
||||
|
||||
|
@ -19,8 +19,9 @@
|
||||
* 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 void assertAddProxyConnectorPage()
|
||||
"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 void assertAddRemoteRepository()
|
||||
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 void editManagedRepository( String fieldName, String value )
|
||||
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 void assertRepositoryScanningPage()
|
||||
"**/*.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] );
|
||||
}
|
||||
}
|
||||
|
||||
// ///////////////////////////////////////////
|
||||
|
@ -21,18 +21,23 @@
|
||||
|
||||
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 @@ protected String getEscapeProperty( String key )
|
||||
}
|
||||
|
||||
/**
|
||||
* Close selenium session. Called from AfterSuite method of sub-class
|
||||
* Close selenium session.
|
||||
*/
|
||||
public void close()
|
||||
throws Exception
|
||||
@ -168,7 +173,7 @@ public String getText( String locator )
|
||||
|
||||
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 void assertTextPresent( String... texts )
|
||||
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 void assertOptionPresent( String selectField, String[] options )
|
||||
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 void submit()
|
||||
|
||||
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 void assertElementValue( String locator, String expectedValue )
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user