continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r918330 - in /continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test: listener/CaptureScreenShotsListener.java parent/AbstractContinuumTest.java parent/AbstractSeleniumTest.java
Date Wed, 03 Mar 2010 06:05:13 GMT
Author: brett
Date: Wed Mar  3 06:05:12 2010
New Revision: 918330

URL: http://svn.apache.org/viewvc?rev=918330&view=rev
Log:
try to make tests more resistant to intermittently failing isElementPresent checks

Modified:
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractSeleniumTest.java

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java?rev=918330&r1=918329&r2=918330&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
Wed Mar  3 06:05:12 2010
@@ -58,6 +58,11 @@
 
     private void captureError( ITestResult tr )
     {
+        captureScreenshotAndSource( tr.getTestClass().getName(), tr.getThrowable() );
+    }
+
+    private static void captureScreenshotAndSource( String cName, Throwable throwable )
+    {
         Selenium selenium = AbstractSeleniumTest.getSelenium();
         String locator = "link=Show/hide Stack Trace";
         if ( selenium.isElementPresent( locator ) )
@@ -68,8 +73,7 @@
         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();
+        StackTraceElement stackTrace[] = throwable.getStackTrace();
         int index = getStackTraceIndexOfCallingClass( cName, stackTrace );
         String methodName = stackTrace[index].getMethodName();
         int lNumber = stackTrace[index].getLineNumber();
@@ -80,16 +84,16 @@
         try
         {
             selenium.windowMaximize();
-            File fileName = new File( targetPath, fileBaseName + ".png" );
+            File fileName = getFileName( targetPath, fileBaseName, ".png" );
             selenium.captureEntirePageScreenshot( fileName.getAbsolutePath(), "" );
         }
         catch ( RuntimeException e )
         {
-            System.out.println( "Error when take screenshot for test " + tr.getName() + ":
" + e.getMessage() );
+            System.out.println( "Error when take screenshot of error: " + e.getMessage()
);
         }
         try
         {
-            File fileName = new File( targetPath, fileBaseName + ".html" );
+            File fileName = getFileName( targetPath, fileBaseName, ".html" );
             FileUtils.writeStringToFile( fileName, selenium.getHtmlSource() );
         }
         catch ( IOException ioe )
@@ -98,9 +102,21 @@
         }
     }
 
-    private int getStackTraceIndexOfCallingClass( String nameOfClass, StackTraceElement stackTrace[]
)
+    private static File getFileName( File targetPath, String fileBaseName, String ext )
     {
-        boolean match = false;
+        File fileName = new File( targetPath, fileBaseName + ext );
+        int count = 0;
+        while ( fileName.exists() )
+        {
+            count++;
+            fileName = new File( targetPath, fileBaseName + "_" + count + ext );
+        }
+        return fileName;
+    }
+
+    private static int getStackTraceIndexOfCallingClass( String nameOfClass, StackTraceElement
stackTrace[] )
+    {
+        boolean match;
         int i = 0;
         do
         {
@@ -108,8 +124,13 @@
             match = Pattern.matches( nameOfClass, className );
             i++;
         }
-        while ( match == false );
+        while ( !match );
         i--;
         return i;
     }
+
+    public static void captureScreenshotAndSource( String name )
+    {
+        captureScreenshotAndSource( name, new Exception() );
+    }
 }

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java?rev=918330&r1=918329&r2=918330&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractContinuumTest.java
Wed Mar  3 06:05:12 2010
@@ -20,8 +20,11 @@
  */
 
 import org.apache.continuum.web.test.ConfigurationTest;
+import org.apache.continuum.web.test.listener.CaptureScreenShotsListener;
 import org.testng.Assert;
 
+import java.io.File;
+
 /**
  * Based on AbstractContinuumTestCase of Emmanuel Venisse test.
  *
@@ -407,9 +410,24 @@
             }
         }
 
+        // TODO: investigate and remove
+        // sometimes the project is still building in the later checks, even though the above
has passed. This is here
+        // to help diagnose
+        if ( !isElementPresent( "//img[@alt='Success']" ) )
+        {
+            CaptureScreenShotsListener.captureScreenshotAndSource( getClass().getName() );
+        }
+
+        // TODO: investigate and remove
         // not sure why this is needed, but the page seems to be partially loaded as the
screenshot can be
         // correct even if the link is not yet present
-        Thread.sleep( 1000 );
+        if ( !isLinkPresent( projectName ) )
+        {
+            CaptureScreenShotsListener.captureScreenshotAndSource( getClass().getName() );
+
+            // This seems to be enough to avoid it
+            Thread.sleep( 10000 );
+        }
 
         clickLinkWithText( projectName );
         clickLinkWithText( "Builds" );

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractSeleniumTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractSeleniumTest.java?rev=918330&r1=918329&r2=918330&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractSeleniumTest.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractSeleniumTest.java
Wed Mar  3 06:05:12 2010
@@ -355,7 +355,6 @@
 
     public void clickLinkWithLocator( String locator, boolean wait )
     {
-        assertElementPresent( locator );
         getSelenium().click( locator );
         if ( wait )
         {



Mime
View raw message