archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1296187 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js: ./ src/test/java/org/apache/archiva/web/test/ src/test/java/org/apache/archiva/web/test/listener/ src/test/java/org/apache/archiva/web/test/parent/
Date Fri, 02 Mar 2012 13:14:58 GMT
Author: olamy
Date: Fri Mar  2 13:14:58 2012
New Revision: 1296187

URL: http://svn.apache.org/viewvc?rev=1296187&view=rev
Log:
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

Removed:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/listener/CaptureScreenShotsListener.java
Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml (original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml Fri Mar  2 13:14:58
2012
@@ -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>

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
Fri Mar  2 13:14:58 2012
@@ -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 );

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
Fri Mar  2 13:14:58 2012
@@ -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

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
Fri Mar  2 13:14:58 2012
@@ -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

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
Fri Mar  2 13:14:58 2012
@@ -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" );

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
Fri Mar  2 13:14:58 2012
@@ -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 AbstractArchivaTes
     protected String fullname;
 
     @Override
-    @AfterTest
+    @After
     public void close()
         throws Exception
     {
@@ -45,25 +45,24 @@ public abstract class AbstractArchivaTes
     }
 
     @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
     {
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
Fri Mar  2 13:14:58 2012
@@ -21,7 +21,7 @@ package org.apache.archiva.web.test.pare
 
 import java.io.File;
 
-public class AbstractMergingRepositoriesTest
+public abstract class AbstractMergingRepositoriesTest
     extends AbstractArchivaTest
 {
 

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
Fri Mar  2 13:14:58 2012
@@ -19,8 +19,9 @@ package org.apache.archiva.web.test.pare
  * 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 AbstractRepository
             "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 AbstractRepository
         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 AbstractRepository
         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 AbstractRepository
             "**/*.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] );
+        }
     }
 
     // ///////////////////////////////////////////

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java?rev=1296187&r1=1296186&r2=1296187&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
Fri Mar  2 13:14:58 2012
@@ -21,18 +21,23 @@ package org.apache.archiva.web.test.pare
 
 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 AbstractSeleniumTe
     }
 
     /**
-     * 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 AbstractSeleniumTe
 
     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 AbstractSeleniumTe
             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 AbstractSeleniumTe
         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 AbstractSeleniumTe
 
     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 AbstractSeleniumTe
         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



Mime
View raw message