You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ca...@apache.org on 2009/07/18 04:28:37 UTC
svn commit: r795300 - in
/continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test:
listener/SeleniumListener.java selenium/ selenium/SeleniumTestException.java
Author: carlos
Date: Sat Jul 18 02:28:37 2009
New Revision: 795300
URL: http://svn.apache.org/viewvc?rev=795300&view=rev
Log:
Fix synchronization issues and encapsulate exceptions to provide the environments and other parameters that the test was run with
Added:
continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/
continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java (with props)
Modified:
continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/listener/SeleniumListener.java
Modified: continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/listener/SeleniumListener.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/listener/SeleniumListener.java?rev=795300&r1=795299&r2=795300&view=diff
==============================================================================
--- continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/listener/SeleniumListener.java (original)
+++ continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/listener/SeleniumListener.java Sat Jul 18 02:28:37 2009
@@ -24,8 +24,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.Iterator;
import org.apache.continuum.web.test.parent.SeleniumSession;
+import org.apache.continuum.web.test.selenium.SeleniumTestException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.Assert;
@@ -71,25 +73,54 @@
super.onTestStart( result );
}
- @Override
- public void onFinish( ITestContext testContext )
+ private void ensureStopAllSessionsOnExit()
{
- /* ensure all browsers are killed */
- for ( SeleniumSession session : SELENIUM_SESSIONS )
+ Runtime.getRuntime().addShutdownHook( new Thread()
{
- try
+ public void run()
{
- if ( session.isStarted() )
- {
- session.stop();
- SELENIUM_SESSIONS.remove( session );
- }
+ stopAllSessions();
}
- catch ( RuntimeException e )
+ } );
+ }
+
+ private void stopAllSessions()
+ {
+ /* ensure all browsers are stopped */
+ synchronized ( SELENIUM_SESSIONS )
+ {
+ for ( Iterator<SeleniumSession> it = SELENIUM_SESSIONS.iterator(); it.hasNext(); )
{
- logger.error( "Error stoping selenium server: " + session.configurationString(), e );
+ SeleniumSession session = it.next();
+
+ try
+ {
+ if ( session.isStarted() )
+ {
+ logger.info( "Stoping selenium session {}", session.configurationString() );
+ session.stop();
+ it.remove();
+ }
+ }
+ catch ( RuntimeException e )
+ {
+ logger.error( "Error stoping selenium server: " + session.configurationString(), e );
+ }
}
}
+ }
+
+ @Override
+ public void onStart( ITestContext testContext )
+ {
+ ensureStopAllSessionsOnExit();
+ super.onStart( testContext );
+ }
+
+ @Override
+ public void onFinish( ITestContext testContext )
+ {
+ stopAllSessions();
super.onFinish( testContext );
}
@@ -110,7 +141,9 @@
{
getSession().stop();
}
- logger.error( "Test {} -> Failed", tr.getName(), getSession().configurationString() );
+ logger.error( "Test {} {} -> Failed", tr.getName(), getSession().configurationString() );
+ SeleniumTestException e = new SeleniumTestException( getSession(), tr.getThrowable() );
+ tr.setThrowable( e );
super.onTestFailure( tr );
}
Added: continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java?rev=795300&view=auto
==============================================================================
--- continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java (added)
+++ continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java Sat Jul 18 02:28:37 2009
@@ -0,0 +1,51 @@
+package org.apache.continuum.web.test.selenium;
+
+/*
+ * 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 org.apache.continuum.web.test.parent.SeleniumSession;
+
+/**
+ * Exception to encapsulate exceptions in a Selenium Grid environment
+ *
+ * @author Carlos Sanchez <a href="mailto:carlos@apache.org">
+ */
+public class SeleniumTestException
+ extends Exception
+{
+ private static final long serialVersionUID = -7855624601993372434L;
+
+ private SeleniumSession session;
+
+ public SeleniumTestException( SeleniumSession session, Throwable cause )
+ {
+ super( "Selenium exception " + session.configurationString(), cause );
+ this.setSession( session );
+ }
+
+ public void setSession( SeleniumSession session )
+ {
+ this.session = session;
+ }
+
+ public SeleniumSession getSession()
+ {
+ return session;
+ }
+}
Propchange: continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: continuum/branches/continuum-selenium-parallel-carlos/src/test/testng/org/apache/continuum/web/test/selenium/SeleniumTestException.java
------------------------------------------------------------------------------
svn:mime-type = text/plain