]> source.dussan.org Git - archiva.git/commitdiff
move to a junit based solution for selenium test as it's very convenient to test...
authorOlivier Lamy <olamy@apache.org>
Fri, 2 Mar 2012 13:14:58 +0000 (13:14 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 2 Mar 2012 13:14:58 +0000 (13:14 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1296187 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-test-js/pom.xml
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/ArchivaAdminTest.java
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/LoginTest.java
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/RolesManagementTest.java
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/UserManagementTest.java
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/listener/CaptureScreenShotsListener.java [deleted file]
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractArchivaTest.java
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractMergingRepositoriesTest.java
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractRepositoryTest.java
archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java

index d0f8faf7ce3d4394004cc2219e82076093b5a116..b58d589fa3eaf693419f06a175a153f9504c5098 100644 (file)
   </properties>
 
   <dependencies>
-    <dependency>
-      <groupId>org.testng</groupId>
-      <artifactId>testng</artifactId>
-      <scope>test</scope>
-    </dependency>
+
     <dependency>
       <groupId>commons-io</groupId>
       <artifactId>commons-io</artifactId>
         <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>
index 721d8ba3994978d19ec12aa29ab4d90b4ccf2f7d..8be57aa1478813f1cf5d5dbc3e0a9b73d8cd8cbc 100644 (file)
@@ -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 );
index 29ba5ef0c0e26ba3091de3c4be7fc5e33f67b164..0c888e03c3f73dcb424ab3c8098b34aecf63e8df 100644 (file)
@@ -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
index 388eb5f375085b31271ab4fe5338528650545e1c..1a13488a0add5cf580c3ae3f352d7a7e6d1b9e87 100644 (file)
@@ -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
index 3478c13654c0dbd4a1a8965d6d54e7e35b1de7b0..720e9ba1971147583581a0e0a9f008cf49c64789 100644 (file)
@@ -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 (file)
index 1cc89ed..0000000
+++ /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
index 5cfc89a127382db9ba0253a4a6ac64a1f95c3627..18419c3adb7d8abc28453210413fd12ec9893a59 100644 (file)
@@ -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
     {
 
index a1214acfb9822a57d759e9adfcd779ea03b56f66..a90e6ac2b5014856ac51f422f8a2870779560321 100644 (file)
@@ -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] );
+        }
     }
 
     // ///////////////////////////////////////////
index a394b5923e247c8e38866e429eca0ff71b0bc7ec..8afd1bedb929fcf91941c75e1113666850eca382 100644 (file)
@@ -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