continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmora...@apache.org
Subject svn commit: r787880 - in /continuum/trunk/continuum-webapp-test: ./ src/test/testng/org/apache/continuum/web/test/ src/test/testng/org/apache/continuum/web/test/listener/ src/test/testng/org/apache/continuum/web/test/parent/
Date Wed, 24 Jun 2009 01:00:06 GMT
Author: jmorales
Date: Wed Jun 24 01:00:05 2009
New Revision: 787880

URL: http://svn.apache.org/viewvc?rev=787880&view=rev
Log:
[CONTINUUM-2267][CONTINUUM-2268] . Selenium tests fail when run with JDK 1.6 and Capture Screenshots
in TestNG listener.

Update BuildAgentTest for enable/disable agents before/after each test.

Added:
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
  (with props)
Modified:
    continuum/trunk/continuum-webapp-test/pom.xml
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/BuildAgentsTest.java
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/QueueTest.java
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractBuildAgentsTest.java
    continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractSeleniumTest.java

Modified: continuum/trunk/continuum-webapp-test/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/pom.xml?rev=787880&r1=787879&r2=787880&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/pom.xml (original)
+++ continuum/trunk/continuum-webapp-test/pom.xml Wed Jun 24 01:00:05 2009
@@ -97,6 +97,12 @@
               <goal>test</goal>
             </goals>
             <configuration>
+              <properties>
+                <property>
+                  <name>listener</name>
+                  <value>org.apache.continuum.web.test.listener.CaptureScreenShotsListener</value>
+                </property>
+              </properties>
               <systemProperties>
                 <property>
                   <name>browser</name>

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/BuildAgentsTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/BuildAgentsTest.java?rev=787880&r1=787879&r2=787880&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/BuildAgentsTest.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/BuildAgentsTest.java
Wed Jun 24 01:00:05 2009
@@ -25,10 +25,10 @@
 
 
 @Test( groups = { "agent" }, dependsOnMethods = { "testDeleteBuildDefinitionTemplate" } )
-    public class BuildAgentsTest
+public class BuildAgentsTest
     extends AbstractBuildAgentsTest
-    {
-    
+{
+
     public void testAddBuildAgent()
     {
 		String BUILD_AGENT_NAME = getProperty( "BUILD_AGENT_NAME" );
@@ -37,117 +37,129 @@
 		String BUILD_AGENT_DESCRIPTION2 = getProperty( "BUILD_AGENT_DESCRIPTION2" );
 		String BUILD_AGENT_NAME3 = getProperty( "BUILD_AGENT_NAME3" );
 		String BUILD_AGENT_DESCRIPTION3 = getProperty( "BUILD_AGENT_DESCRIPTION3" );
-		
+
 		enableDistributedBuilds();
-		goToAddBuildAgent();
-		addBuildAgent( BUILD_AGENT_NAME, BUILD_AGENT_DESCRIPTION, true ) ;
-		goToAddBuildAgent();
-		addBuildAgent( BUILD_AGENT_NAME2, BUILD_AGENT_DESCRIPTION2, true ) ;
-		goToAddBuildAgent();
-		addBuildAgent( BUILD_AGENT_NAME3, BUILD_AGENT_DESCRIPTION3, true ) ;
+        goToAddBuildAgent();
+        addBuildAgent( BUILD_AGENT_NAME, BUILD_AGENT_DESCRIPTION, true );
+        goToAddBuildAgent();
+        addBuildAgent( BUILD_AGENT_NAME2, BUILD_AGENT_DESCRIPTION2, true );
+        goToAddBuildAgent();
+        addBuildAgent( BUILD_AGENT_NAME3, BUILD_AGENT_DESCRIPTION3, true );
+        disableDistributedBuilds();
 	}
-	
+
 	@Test( dependsOnMethods = { "testEditBuildAgent" } )
     public void testAddAnExistingBuildAgent()
     {
 		String BUILD_AGENT_NAME = getProperty( "BUILD_AGENT_NAME" );
 		String BUILD_AGENT_DESCRIPTION = getProperty( "BUILD_AGENT_DESCRIPTION" );
-		
+
+		enableDistributedBuilds();
 		goToAddBuildAgent();
 		addBuildAgent( BUILD_AGENT_NAME, BUILD_AGENT_DESCRIPTION, false ) ;
         assertTextPresent( "Build agent already exists" );
+        disableDistributedBuilds();
     }
-	
+
 	@Test( dependsOnMethods = { "testAddBuildAgent" } )
 	public void testEditBuildAgent()
-	
+
     {
 		String BUILD_AGENT_NAME = getProperty( "BUILD_AGENT_NAME" );
 		String BUILD_AGENT_DESCRIPTION = getProperty( "BUILD_AGENT_DESCRIPTION" );
 		String new_agentDescription = "new_agentDescription";
-        
+
+		enableDistributedBuilds();
         goToEditBuildAgent( BUILD_AGENT_NAME, BUILD_AGENT_DESCRIPTION);
 		addEditBuildAgent( BUILD_AGENT_NAME, new_agentDescription );
 		goToEditBuildAgent( BUILD_AGENT_NAME, new_agentDescription);
 		addEditBuildAgent( BUILD_AGENT_NAME, BUILD_AGENT_DESCRIPTION );
-		
-    } 
-	
+		disableDistributedBuilds();
+    }
+
 	@Test( dependsOnMethods = { "testAddAnExistingBuildAgent" } )
     public void testDeleteBuildAgent()
-   
+
     {
+	    enableDistributedBuilds();
         goToBuildAgentPage();
         String BUILD_AGENT_NAME3 = getProperty( "BUILD_AGENT_NAME3" );
         removeBuildAgent( BUILD_AGENT_NAME3 );
         assertTextNotPresent( BUILD_AGENT_NAME3 );
+        disableDistributedBuilds();
     }
-	
+
 	@Test( dependsOnMethods = { "testDeleteBuildAgent" } )
     public void testAddEmptyBuildAgent()
     {
     	String BUILD_AGENT_DESCRIPTION = getProperty( "BUILD_AGENT_DESCRIPTION" );
-    	
+
+    	enableDistributedBuilds();
     	goToAddBuildAgent();
 		addBuildAgent( "", BUILD_AGENT_DESCRIPTION, false ) ;
 		assertTextPresent( "Build agent url is required." );
+		disableDistributedBuilds();
     }
-    
-//TESTS FOR BUILD AGENT GROUPS    
-    
+
+//TESTS FOR BUILD AGENT GROUPS
+
     @Test( dependsOnMethods = { "testAddBuildAgent" } )
     public void testAddBuildAgentGroup()
     throws Exception
     {
     	String BUILD_AGENT_GROUPNAME = getProperty( "BUILD_AGENT_GROUPNAME" );
-		
+    	enableDistributedBuilds();
     	goToAddBuildAgentGroup();
 		addEditBuildAgentGroup( BUILD_AGENT_GROUPNAME, new String[] { "Agent_url_name", "Second_Agent"
}, new String[] {}, true );
-    	
+		disableDistributedBuilds();
 	}
-	
+
 	@Test( dependsOnMethods = { "testAddBuildAgentGroup" } )
     public void testEditBuildAgentGroup()
         throws Exception
     {
     	String BUILD_AGENT_GROUPNAME = getProperty( "BUILD_AGENT_GROUPNAME" );
         String newName = "new_agentgroupname";
+        enableDistributedBuilds();
         goToEditBuildAgentGroup( BUILD_AGENT_GROUPNAME, new String[] { "Agent_url_name",
"Second_Agent" } );
         addEditBuildAgentGroup( newName, new String[] {},
                          new String[] { "Second_Agent" }, true );
         goToEditBuildAgentGroup( newName, new String[] { "Agent_url_name" } );
         addEditBuildAgentGroup( BUILD_AGENT_GROUPNAME, new String[] { "Second_Agent" },
                          new String[] {}, true );
+        disableDistributedBuilds();
     }
-	
+
 	@Test( dependsOnMethods = { "testEditBuildAgentGroup" } )
     public void testAddAnExistingBuildAgentGroup()
     throws Exception
     {
         String BUILD_AGENT_GROUPNAME = getProperty( "BUILD_AGENT_GROUPNAME" );
-		
+
+        enableDistributedBuilds();
     	goToAddBuildAgentGroup();
 	   	addEditBuildAgentGroup( BUILD_AGENT_GROUPNAME, new String[] { "Agent_url_name", "Second_Agent"
}, new String[] {}, false );
 	   	assertTextPresent( "Build agent group already exists." );
-     
-    }   
-    
+	   	disableDistributedBuilds();
+    }
+
     @Test( dependsOnMethods = { "testAddAnExistingBuildAgentGroup" } )
     public void testAddEmptyBuildAgentGroupName()
     throws Exception
     {
-    	
+        enableDistributedBuilds();
     	goToAddBuildAgentGroup();
     	addEditBuildAgentGroup( "", new String[] {}, new String[] {}, false );
 		assertTextPresent( "Build agent group name required." );
+		disableDistributedBuilds();
     }
-    
+
     @Test( dependsOnMethods = { "testAddEmptyBuildAgentGroupName" } )
     public void testDeleteBuildAgentGroup()
     {
     	String BUILD_AGENT_GROUPNAME = getProperty( "BUILD_AGENT_GROUPNAME" );
+    	enableDistributedBuilds();
         removeBuildAgentGroup( BUILD_AGENT_GROUPNAME );
+        disableDistributedBuilds();
     }
-    
-    
 }

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/QueueTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/QueueTest.java?rev=787880&r1=787879&r2=787880&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/QueueTest.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/QueueTest.java
Wed Jun 24 01:00:05 2009
@@ -31,17 +31,17 @@
 
 
 @Test( groups = { "queue" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } )
-    public class QueueTest
-        extends AbstractBuildQueueTest
-    {
-    
-	public void testAddBuildQueue()
+public class QueueTest
+    extends AbstractBuildQueueTest
+{
+
+    public void testAddBuildQueue()
     {
         setMaxBuildQueue( 2 );
         String BUILD_QUEUE_NAME = getProperty( "BUILD_QUEUE_NAME" );
         addBuildQueue( BUILD_QUEUE_NAME, true );
     }
-	
+
 	@Test( dependsOnMethods = { "testAddBuildQueue" } ) //"testDeleteBuildQueue" } )
     public void testQueuePageWithoutBuild()
     {
@@ -55,14 +55,13 @@
 	    assertTextPresent( "Checkout Queue " );
 	    assertTextPresent( "Current Prepare Build" );
 	    assertTextPresent( "Prepare Build Queue" );
-       
-    }    
-	
+    }
+
 	@Test( dependsOnMethods = { "testAddBuildQueue", "testAddSchedule" } )
     public void testAddBuildQueueToSchedule()
   {
 	    ScheduleTest sched = new ScheduleTest();
-	  
+
 	    String SCHEDULE_NAME = getProperty( "SCHEDULE_NAME" );
         String SCHEDULE_DESCRIPTION = getProperty( "SCHEDULE_DESCRIPTION" );
         String SCHEDULE_EXPR_SECOND = getProperty( "SCHEDULE_EXPR_SECOND" );
@@ -74,20 +73,20 @@
         String SCHEDULE_EXPR_YEAR = getProperty( "SCHEDULE_EXPR_YEAR" );
         String SCHEDULE_MAX_TIME = getProperty( "SCHEDULE_MAX_TIME" );
         String SCHEDULE_PERIOD = getProperty( "SCHEDULE_PERIOD" );
-        
+
         String BUILD_QUEUE_NAME = getProperty( "BUILD_QUEUE_NAME" );
-        
-     		  
+
+
       sched.goToEditSchedule( SCHEDULE_NAME, SCHEDULE_DESCRIPTION, SCHEDULE_EXPR_SECOND,
SCHEDULE_EXPR_MINUTE,
               SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_DAY_WEEK,
-              SCHEDULE_EXPR_YEAR, SCHEDULE_MAX_TIME, SCHEDULE_PERIOD );	
+              SCHEDULE_EXPR_YEAR, SCHEDULE_MAX_TIME, SCHEDULE_PERIOD );
 	  getSelenium().removeSelection("saveSchedule_availableBuildQueues", "label=DEFAULT_BUILD_QUEUE");
 	  getSelenium().addSelection("saveSchedule_availableBuildQueues", "label="+BUILD_QUEUE_NAME);
 	  getSelenium().click("//input[@value='->']");
 	  submit();
-      
+
   }
-	
+
 	@Test( dependsOnMethods = { "testAddBuildQueue" } )
     public void testAddNotAllowedBuildQueue()
     {
@@ -105,7 +104,7 @@
         addBuildQueue( BUILD_QUEUE_NAME, false );
         assertTextPresent( "Build queue name already exists." );
     }
-    
+
     @Test( dependsOnMethods = { "testAddAlreadyExistBuildQueue" } )
     public void testAddEmptyBuildQueue()
     {
@@ -114,7 +113,7 @@
         assertTextPresent( "You must define a name" );
     }
 
-    @Test( dependsOnMethods = { "testAddBuildQueueToSchedule" } ) 
+    @Test( dependsOnMethods = { "testAddBuildQueueToSchedule" } )
     public void testDeleteBuildQueue()
     {
         goToBuildQueuePage();
@@ -122,18 +121,18 @@
         removeBuildQueue( BUILD_QUEUE_NAME );
         assertTextNotPresent( BUILD_QUEUE_NAME );
     }
-    
-       
+
+
     @Test( dependsOnMethods = { "testAddMavenTwoProject" } )
     public void testQueuePageWithProjectCurrentlyBuilding()
         throws Exception
-    {   
+    {
     	//build a project
         String M2_PROJ_GRP_NAME = getProperty( "M2_PROJ_GRP_NAME" );
         String M2_PROJ_GRP_ID = getProperty( "M2_PROJ_GRP_ID" );
         String M2_PROJ_GRP_DESCRIPTION = getProperty( "M2_PROJ_GRP_DESCRIPTION" );
         buildProjectForQueuePageTest( M2_PROJ_GRP_NAME, M2_PROJ_GRP_ID, M2_PROJ_GRP_DESCRIPTION,
M2_PROJ_GRP_NAME );
-        
+
         //check queue page while building
     	clickAndWait( "link=Queues" );
 	    assertPage( "Continuum - Build Queue" );
@@ -151,5 +150,5 @@
 	    waitForElementPresent( "//img[@alt='Success']" );
 	    Thread.sleep( 10000 );
     }
-    
+
  }

Added: 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=787880&view=auto
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
(added)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
Wed Jun 24 01:00:05 2009
@@ -0,0 +1,101 @@
+package org.apache.continuum.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 java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.regex.Pattern;
+
+import org.apache.continuum.web.test.parent.AbstractSeleniumTest;
+import org.testng.ITestResult;
+import org.testng.TestListenerAdapter;
+
+public class CaptureScreenShotsListener
+    extends TestListenerAdapter
+{
+    @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 )
+    {
+        try
+        {
+            captureScreenshot( tr );
+        }
+        catch ( RuntimeException e )
+        {
+            System.out.println( "Error when take screenshot for test " + tr.getName() );
+            e.printStackTrace();
+        }
+    }
+
+    // captureAssertionError() creates a 'target/screenshots' directory and saves '.png'
page screenshot of the
+    // encountered error
+    private void captureScreenshot( ITestResult tr )
+    {
+        File f = new File( "" );
+        String filePath = f.getAbsolutePath();
+        Date d = new Date();
+        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy.MM.dd-HH_mm_ss" );
+        String time = sdf.format( d );
+        String fs = File.separator;
+        File targetPath = new File( filePath + fs + "target" + fs + "screenshots" );
+        targetPath.mkdir();
+        String cName = tr.getTestClass().getName();
+        StackTraceElement stackTrace[] = tr.getThrowable().getStackTrace();
+        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 );
+        String fileName =
+            targetPath.toString() + fs + methodName + "(" + className + ".java_" + lineNumber
+ ")-" + time + ".png";
+        AbstractSeleniumTest.getSelenium().windowMaximize();
+        AbstractSeleniumTest.getSelenium().captureEntirePageScreenshot( fileName, "" );
+    }
+
+    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;
+    }
+}

Propchange: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/listener/CaptureScreenShotsListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractBuildAgentsTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractBuildAgentsTest.java?rev=787880&r1=787879&r2=787880&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractBuildAgentsTest.java
(original)
+++ continuum/trunk/continuum-webapp-test/src/test/testng/org/apache/continuum/web/test/parent/AbstractBuildAgentsTest.java
Wed Jun 24 01:00:05 2009
@@ -29,16 +29,29 @@
     {
 		ConfigurationTest config = new ConfigurationTest();
 	    config.goToConfigurationPage();
-		setFieldValue( "numberOfAllowedBuildsinParallel", "2" );
-        if (!isChecked("configuration_distributedBuildEnabled"));
+        setFieldValue( "numberOfAllowedBuildsinParallel", "2" );
+        if ( !isChecked( "configuration_distributedBuildEnabled" ) )
         {
-		checkField("configuration_distributedBuildEnabled");
+            checkField( "configuration_distributedBuildEnabled" );
         }
-		clickAndWait("configuration_");
-		assertTextPresent("true");
-		assertTextPresent("Distributed Builds");
-		assertElementPresent("link=Build Agents");
-		
+        clickAndWait( "configuration_" );
+        assertTextPresent( "true" );
+        assertTextPresent( "Distributed Builds" );
+        assertElementPresent( "link=Build Agents" );
+    }
+
+    public void disableDistributedBuilds()
+    {
+        ConfigurationTest config = new ConfigurationTest();
+        config.goToConfigurationPage();
+        setFieldValue( "numberOfAllowedBuildsinParallel", "2" );
+        if ( isChecked( "configuration_distributedBuildEnabled" ) )
+        {
+            uncheckField( "configuration_distributedBuildEnabled" );
+        }
+        submit();
+        assertTextPresent( "false" );
+        assertElementNotPresent( "link=Build Agents" );
     }
 
 	public void goToBuildAgentPage()
@@ -46,16 +59,16 @@
 		clickAndWait("link=Build Agents");
 		assertPage("Continuum - Build Agents");
 	}
-	
+
 	public void assertBuildAgentPage()
     {
 		assertPage("Continuum - Build Agents");
 		assertTextPresent("Build Agents");
 		assertTextPresent("Build Agent Groups");
 		assertButtonWithValuePresent( "Add" );
-		
+
     }
-	
+
 	public void goToAddBuildAgent()
     {
 		goToBuildAgentPage();
@@ -63,7 +76,7 @@
 		clickAndWait("editBuildAgent_0"); //add button
 		assertAddEditBuildAgentPage();
     }
-	
+
 	public void assertAddEditBuildAgentPage()
     {
 		assertPage( "Continuum - Add/Edit Build Agent" );
@@ -76,8 +89,8 @@
         assertButtonWithValuePresent( "Save" );
         assertButtonWithValuePresent( "Cancel" );
     }
-	
-	public void removeBuildAgent( String agentName ) 
+
+	public void removeBuildAgent( String agentName )
 	{
         clickLinkWithXPath( "(//a[contains(@href,'deleteBuildAgent.action') and contains(@href,
'" + agentName + "')])//img" );
 		assertPage("Continuum - Delete Build Agent");
@@ -87,7 +100,7 @@
         assertButtonWithValuePresent( "Cancel" );
         clickButtonWithValue( "Delete" );
         assertBuildAgentPage();
-    } 
+    }
 
 	public void addBuildAgent( String agentURL, String description, boolean success )
 	{
@@ -99,15 +112,15 @@
 	    {
 	        assertBuildAgentPage();
 	        assertElementPresent( "link=" + agentURL );
-	        
+
 	    }
 	    else
 	    {
 	        assertAddEditBuildAgentPage();
 	    }
-	    
+
 	}
-	
+
 	public void goToEditBuildAgent( String name, String description )
 	{
 	   goToBuildAgentPage();
@@ -115,9 +128,9 @@
 	   assertAddEditBuildAgentPage();
 	   assertFieldValue( name, "saveBuildAgent_buildAgent_url" );
 	   assertFieldValue( description, "saveBuildAgent_buildAgent_description" );
-	    
+
 	}
-	
+
 	public void addEditBuildAgent( String agentName, String newDesc )
 	{
 		assertFieldValue( agentName, "saveBuildAgent_buildAgent_url" );
@@ -125,10 +138,10 @@
 		submit();
 		assertBuildAgentPage();
 		assertTextPresent( newDesc );
-		
+
 	}
-	
-	
+
+
 	public void goToAddBuildAgentGroup()
     {
 		goToBuildAgentPage();
@@ -137,8 +150,8 @@
             new String[] { "--- Available Build Agents ---", "Agent_url_name", "Second_Agent"
};
         assertAddEditBuildAgentGroupPage( options, null );
     }
-	
-	
+
+
 	public void addEditBuildAgentGroup( String name, String[] addBuildAgents, String[] removeBuildAgents,
             boolean success ) throws Exception
 	{
@@ -168,10 +181,10 @@
 		{
 			assertAddEditBuildAgentGroupPage( null, null );
 		}
-		
-		 
+
+
 	}
-	
+
 	public void assertAddEditBuildAgentGroupPage( String[] availableBuildAgents, String[] usedBuildAgents
)
     {
 		assertPage( "Continuum - Add/Edit Build Agent Group" );
@@ -187,11 +200,11 @@
         {
             assertOptionPresent( "selectedBuildAgentIds", usedBuildAgents );
         }
-		
+
 		assertButtonWithValuePresent( "Save" );
         assertButtonWithValuePresent( "Cancel" );
     }
-	
+
 	public void goToEditBuildAgentGroup( String name, String[] buildAgents )
     {
 		goToBuildAgentPage();
@@ -201,8 +214,8 @@
         assertFieldValue( name, "buildAgentGroup.name" );
     }
 
-   	
-	public void removeBuildAgentGroup( String name ) 
+
+	public void removeBuildAgentGroup( String name )
 	{
 		goToBuildAgentPage();
 		clickLinkWithXPath( "(//a[contains(@href,'deleteBuildAgentGroup.action') and contains(@href,
'" + name + "')])//img" );
@@ -214,6 +227,6 @@
         clickButtonWithValue( "Delete" );
         assertBuildAgentPage();
     }
-	
+
 
 }

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=787880&r1=787879&r2=787880&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 Jun 24 01:00:05 2009
@@ -32,7 +32,6 @@
 import java.util.Map.Entry;
 import java.util.regex.Pattern;
 import java.text.SimpleDateFormat;
-import java.lang.Object;
 import java.lang.Throwable;
 
 import org.apache.commons.io.IOUtils;
@@ -94,7 +93,7 @@
         getSelenium().start();
     }
 
-    protected static Selenium getSelenium()
+    public static Selenium getSelenium()
     {
         return selenium.get();
     }
@@ -145,26 +144,12 @@
     public void assertFieldValue( String fieldValue, String fieldName )
     {
         assertElementPresent( fieldName );
-        try
-        {
-            Assert.assertEquals( fieldValue, getSelenium().getValue( fieldName ) );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertEquals( fieldValue, getSelenium().getValue( fieldName ) );
     }
 
     public void assertPage( String title )
     {
-        try
-        {
-            Assert.assertEquals( getTitle(), title );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertEquals( getTitle(), title );
     }
 
     public String getTitle()
@@ -179,74 +164,32 @@
 
     public void assertTextPresent( String text )
     {
-        try
-        {
-            Assert.assertTrue( getSelenium().isTextPresent( text ), "'" + text + "' isn't
present." );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertTrue( getSelenium().isTextPresent( text ), "'" + text + "' isn't present."
);
     }
 
     public void assertTextNotPresent( String text )
     {
-        try
-        {
-            Assert.assertFalse( getSelenium().isTextPresent( text ), "'" + text + "' is present."
);
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertFalse( getSelenium().isTextPresent( text ), "'" + text + "' is present."
);
     }
 
     public void assertElementPresent( String elementLocator )
     {
-        try
-        {
-            Assert.assertTrue( isElementPresent( elementLocator ), "'" + elementLocator +
"' isn't present." );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertTrue( isElementPresent( elementLocator ), "'" + elementLocator + "'
isn't present." );
     }
 
     public void assertElementNotPresent( String elementLocator )
     {
-        try
-        {
-            Assert.assertFalse( isElementPresent( elementLocator ), "'" + elementLocator
+ "' is present." );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertFalse( isElementPresent( elementLocator ), "'" + elementLocator + "'
is present." );
     }
 
     public void assertLinkPresent( String text )
     {
-        try
-        {
-            Assert.assertTrue( isElementPresent( "link=" + text ), "The link '" + text +
"' isn't present." );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertTrue( isElementPresent( "link=" + text ), "The link '" + text + "' isn't
present." );
     }
 
     public void assertLinkNotPresent( String text )
     {
-        try
-        {
             Assert.assertFalse( isElementPresent( "link=" + text ), "The link '" + text +
"' is present." );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
     }
 
     public void assertImgWithAlt( String alt )
@@ -265,14 +208,7 @@
 
     public void assertCellValueFromTable( String expected, String tableElement, int row,
int column )
     {
-        try
-        {
-            Assert.assertEquals( expected, getCellValueFromTable( tableElement, row, column
) );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertEquals( expected, getCellValueFromTable( tableElement, row, column )
);
     }
 
     public boolean isTextPresent( String text )
@@ -316,28 +252,16 @@
         String[] optionsPresent = getSelenium().getSelectOptions( selectField );
         List<String> expected = Arrays.asList( options );
         List<String> present = Arrays.asList( optionsPresent );
-        try
-        {
-            Assert.assertTrue( present.containsAll( expected ), "Options expected are not
included in present options" );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+
+        Assert.assertTrue( present.containsAll( expected ), "Options expected are not included
in present options" );
     }
 
     public void assertSelectedValue( String value, String fieldName )
     {
         assertElementPresent( fieldName );
         String optionsPresent = getSelenium().getSelectedLabel( value );
-        try
-        {
-            Assert.assertEquals( optionsPresent, value );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+
+        Assert.assertEquals( optionsPresent, value );
     }
 
     public void submit()
@@ -347,38 +271,17 @@
 
     public void assertButtonWithValuePresent( String text )
     {
-        try
-        {
-            Assert.assertTrue( isButtonWithValuePresent( text ), "'" + text + "' button isn't
present" );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertTrue( isButtonWithValuePresent( text ), "'" + text + "' button isn't
present" );
     }
 
     public void assertButtonWithIdPresent( String id )
     {
-        try
-        {
-            Assert.assertTrue( isButtonWithIdPresent( id ), "'Button with id =" + id + "'
isn't present" );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertTrue( isButtonWithIdPresent( id ), "'Button with id =" + id + "' isn't
present" );
     }
 
     public void assertButtonWithValueNotPresent( String text )
     {
-        try
-        {
-            Assert.assertFalse( isButtonWithValuePresent( text ), "'" + text + "' button
is present" );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertFalse( isButtonWithValuePresent( text ), "'" + text + "' button is present"
);
     }
 
     public boolean isButtonWithValuePresent( String text )
@@ -495,26 +398,12 @@
 
     public void assertIsChecked( String locator )
     {
-        try
-        {
-            Assert.assertTrue( getSelenium().isChecked( locator ) );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertTrue( getSelenium().isChecked( locator ) );
     }
 
     public void assertIsNotChecked( String locator )
     {
-        try
-        {
-            Assert.assertFalse( getSelenium().isChecked( locator ) );
-        }
-        catch ( java.lang.AssertionError e )
-        {
-            captureAssertionError( e );
-        }
+        Assert.assertFalse( getSelenium().isChecked( locator ) );
     }
 
     public void clickAndWait( String locator )
@@ -562,52 +451,4 @@
             Thread.sleep( 1000 );
         }
     }
-
-    // captureAssertionError() creates a 'target/screenshots' directory and saves '.png'
page screenshot of the
-    // encountered error
-    public void captureError()
-    {
-        File f = new File( "" );
-        String filePath = f.getAbsolutePath();
-        Date d = new Date();
-        SimpleDateFormat sdf = new SimpleDateFormat( "yyyy.MM.dd-HH_mm_ss" );
-        String time = sdf.format( d );
-        String fs = File.separator;
-        File targetPath = new File( filePath + fs + "target" + fs + "screenshots" );
-        targetPath.mkdir();
-        String cName = getClass().getName();
-        StackTraceElement stackTrace[] = new Throwable().fillInStackTrace().getStackTrace();
-        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 );
-        String fileName =
-            targetPath.toString() + fs + methodName + "(" + className + ".java_" + lineNumber
+ ")-" + time + ".png";
-        getSelenium().windowMaximize();
-        getSelenium().captureEntirePageScreenshot( fileName, "" );
-    }
-
-    public 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;
-    }
-
-    // captureError calls the captureAssertionError method to capture screenshot and
-    // throw an assertion error for the errors to be displayed in the build results summary
-    public void captureAssertionError( Object e )
-    {
-        captureError();
-        throw new java.lang.AssertionError( e );
-    }
 }



Mime
View raw message