archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1296372 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test: ./ parent/ tools/
Date Fri, 02 Mar 2012 18:38:16 GMT
Author: olamy
Date: Fri Mar  2 18:38:16 2012
New Revision: 1296372

URL: http://svn.apache.org/viewvc?rev=1296372&view=rev
Log:
use a rule to execute test and being able to capture screenshots

Added:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ScreenshotCaptureRule.java
  (with props)
Modified:
    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/parent/AbstractArchivaTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/parent/AbstractSeleniumTest.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ArchivaSeleniumRunner.java

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=1296372&r1=1296371&r2=1296372&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 18:38:16 2012
@@ -40,7 +40,7 @@ public class LoginTest
         goToLoginPage();
         setFieldValue( "user-login-form-username", "badUsername" );
         clickLinkWithLocator( "modal-login-ok", true );
-        assertTextPresent( "This field is required." );
+        assertTextPresent( "This field is required.f" );
 
     }
 

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=1296372&r1=1296371&r2=1296372&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 18:38:16 2012
@@ -1,8 +1,9 @@
 package org.apache.archiva.web.test.parent;
 
-import org.apache.archiva.web.test.tools.ArchivaSeleniumRunner;
-import org.junit.Before;
+import org.apache.archiva.web.test.tools.ScreenshotCaptureRule;
+import org.junit.Rule;
 import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
 
 import java.io.File;
 import java.io.IOException;
@@ -26,10 +27,11 @@ import java.io.IOException;
  * under the License.
  */
 
-@RunWith( ArchivaSeleniumRunner.class )
+@RunWith( BlockJUnit4ClassRunner.class )
 public abstract class AbstractArchivaTest
     extends AbstractSeleniumTest
 {
+
     protected String username;
 
     protected String fullname;

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=1296372&r1=1296371&r2=1296372&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 18:38:16 2012
@@ -22,9 +22,9 @@ 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.junit.After;
+import org.apache.archiva.web.test.tools.ScreenshotCaptureRule;
 import org.junit.Assert;
-import org.junit.Before;
+import org.junit.Rule;
 
 import java.io.File;
 import java.text.SimpleDateFormat;
@@ -43,6 +43,10 @@ import java.util.Properties;
 
 public abstract class AbstractSeleniumTest
 {
+
+    @Rule
+    public ScreenshotCaptureRule screenshotCaptureRule = new ScreenshotCaptureRule();
+
     public String browser = System.getProperty( "browser" );
 
     public String baseUrl = System.getProperty( "baseUrl" );
@@ -57,22 +61,20 @@ public abstract class AbstractSeleniumTe
 
     public Properties p;
 
-    @Before
     public void open()
         throws Exception
     {
         p = new Properties();
         p.load( this.getClass().getClassLoader().getResourceAsStream( "test.properties" )
);
         open( baseUrl, browser, seleniumHost, seleniumPort, maxWaitTimeInMs );
+        screenshotCaptureRule.selenium = selenium;
         assertAdminCreated();
     }
 
     /**
      * Close selenium session.
      */
-    @After
     public void close()
-        throws Exception
     {
         if ( getSelenium() != null )
         {
@@ -645,27 +647,23 @@ public abstract class AbstractSeleniumTe
     }
 
     @AfterSeleniumFailure
-    public void captureScreenShotOnFailure( Throwable failure )
+    public void captureScreenShotOnFailure( Throwable failure, String methodName, String
className )
     {
         SimpleDateFormat sdf = new SimpleDateFormat( "yyyy.MM.dd-HH_mm_ss" );
         String time = sdf.format( new Date() );
         File targetPath = new File( "target", "screenshots" );
-        String cName = this.getClass().getName();
 
-        String methodName = "";
         int lineNumber = 0;
 
         for ( StackTraceElement stackTrace : failure.getStackTrace() )
         {
             if ( stackTrace.getClassName().equals( this.getClass().getName() ) )
             {
-                methodName = stackTrace.getMethodName();
                 lineNumber = stackTrace.getLineNumber();
                 break;
             }
         }
 
-        String className = cName.substring( cName.lastIndexOf( '.' ) + 1 );
         targetPath.mkdirs();
         Selenium selenium = getSelenium();
         String fileBaseName = methodName + "_" + className + ".java_" + lineNumber + "-"
+ time;

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ArchivaSeleniumRunner.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/tools/ArchivaSeleniumRunner.java?rev=1296372&r1=1296371&r2=1296372&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ArchivaSeleniumRunner.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ArchivaSeleniumRunner.java
Fri Mar  2 18:38:16 2012
@@ -42,9 +42,11 @@ public class ArchivaSeleniumRunner
         super( clazz );
     }
 
+
+
     /*
-     * FIXME move that to a Rule.
-     */
+    * FIXME move that to a Rule.
+    */
     @Override
     protected Statement withAfters( FrameworkMethod method, Object target, Statement statement
)
     {

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ScreenshotCaptureRule.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/tools/ScreenshotCaptureRule.java?rev=1296372&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ScreenshotCaptureRule.java
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ScreenshotCaptureRule.java
Fri Mar  2 18:38:16 2012
@@ -0,0 +1,68 @@
+package org.apache.archiva.web.test.tools;
+/*
+ * 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.junit.rules.MethodRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.FrameworkMethod;
+import org.junit.runners.model.Statement;
+
+/**
+ * @author Olivier Lamy
+ */
+public class ScreenshotCaptureRule
+    implements MethodRule //TestRule
+{
+
+    public Selenium selenium;
+
+    public Statement apply( Statement base, FrameworkMethod method, Object target )
+    {
+        try
+        {
+            ( (AbstractSeleniumTest) target ).open();
+            method.getMethod().invoke( target );
+        }
+        catch ( Throwable e )
+        {
+            ( (AbstractSeleniumTest) target ).captureScreenShotOnFailure( e, method.getMethod().getName(),
+                                                                          target.getClass().getName()
);
+        }
+        finally
+        {
+            ( (AbstractSeleniumTest) target ).close();
+        }
+        return new Statement()
+        {
+            @Override
+            public void evaluate()
+                throws Throwable
+            {
+                // no op
+            }
+        };
+    }
+
+    public Statement apply( Statement base, Description description )
+    {
+        return base;  //To change body of implemented methods use File | Settings | File
Templates.
+    }
+}

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ScreenshotCaptureRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp-test-js/src/test/java/org/apache/archiva/web/test/tools/ScreenshotCaptureRule.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message