Author: lfryc(a)redhat.com
Date: 2009-12-01 08:19:32 -0500 (Tue, 01 Dec 2009)
New Revision: 16025
Added:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ConsoleStatusTestListener.java
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/SeleniumLoggingTestListener.java
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/pom.xml
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
Log:
- RF-demo ftest - added extended logging facility to catch fine-grained execution log
(added selenium server's -debug and -browserSideLog parameters) (RFPL-283)
Modified: branches/community/3.3.X/samples/richfaces-demo/functional-test/pom.xml
===================================================================
--- branches/community/3.3.X/samples/richfaces-demo/functional-test/pom.xml 2009-11-30
10:01:39 UTC (rev 16024)
+++ branches/community/3.3.X/samples/richfaces-demo/functional-test/pom.xml 2009-12-01
13:19:32 UTC (rev 16025)
@@ -196,6 +196,9 @@
<debug>false</debug>
<port>${selenium.port}</port>
<userExtensions>${resources.dir}/custom-extensions.js</userExtensions>
+ <logOutput>true</logOutput>
+ <browserSideLog>true</browserSideLog>
+ <debug>true</debug>
</configuration>
</execution>
</executions>
@@ -218,6 +221,12 @@
</suiteXmlFiles>
<argLine>-Dbrowser='${browser}'
-Dcontext.root='${context.root}' -Dcontext.path='${context.path}'
-Dselenium.host='${selenium.host}' -Dselenium.port='${selenium.port}'
-Dmaven.resources.dir='${resources.dir}'
-Dmaven.project.build.directory='${project.build.directory}'</argLine>
<firefoxProfileTemplate>${firefoxProfileTemplate}</firefoxProfileTemplate>
+ <properties>
+ <property>
+ <name>listener</name>
+ <value>org.jboss.richfaces.integrationTest.ConsoleStatusTestListener</value>
+ </property>
+ </properties>
</configuration>
</execution>
</executions>
Modified:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-11-30
10:01:39 UTC (rev 16024)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-01
13:19:32 UTC (rev 16025)
@@ -27,8 +27,6 @@
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import org.jboss.test.selenium.AbstractSeleniumTestCase;
@@ -36,8 +34,6 @@
import org.jboss.test.selenium.waiting.Wait;
import org.jboss.test.selenium.waiting.Wait.Waiting;
import org.testng.ITestContext;
-import org.testng.ITestListener;
-import org.testng.ITestResult;
import org.testng.TestRunner;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
@@ -57,7 +53,7 @@
*/
public class AbstractSeleniumRichfacesTestCase extends AbstractSeleniumTestCase {
-
+
/**
* context root can be used to obtaining full URL paths, is set to actual
* tested application's context root
@@ -82,6 +78,28 @@
protected Waiting waitModelUpdate = Wait.interval(100).timeout(30000);
protected Waiting waitGuiInteraction = Wait.interval(100).timeout(500);
+ /**
+ * Test listener used to logging to selenium's server.log
+ * via getEval() method (see {@link SeleniumLoggingTestListener})
+ *
+ * Don't forget to use SeleniumLoggingTestListener.setSelenium(Selenium)
+ * to initialize selenium-side logging properly
+ */
+ SeleniumLoggingTestListener loggingTestListener;
+
+ /**
+ * Register test listener in test context
+ *
+ * @param context
+ * will be injected by TestNG
+ */
+ @BeforeTest
+ protected void addTestListeners(ITestContext context) {
+ TestRunner runner = (TestRunner) context;
+ loggingTestListener = new SeleniumLoggingTestListener();
+ runner.addTestListener(loggingTestListener);
+ }
+
/**
* Initializes context before each class run.
*
@@ -111,6 +129,8 @@
selenium.start();
allowInitialXpath();
loadCustomLocationStrategies();
+ // adding selenium-side logging facility
+ loggingTestListener.setSelenium(selenium);
}
/**
@@ -167,59 +187,8 @@
protected Properties getMessagesProperties() {
return getNamedPropertiesForClass(this.getClass(), "messages");
}
-
+
/**
- * Add test listener to get advanced logging and other possibilities.
- *
- * @param context
- * will be injected by TestNG
- */
- @BeforeTest
- protected void addTestListeners(ITestContext context) {
- TestRunner runner = (TestRunner) context;
- runner.addTestListener(testListener);
- }
-
- /**
- * Implementation of listener, which will trigger each test run.
- */
- private ITestListener testListener = new ITestListener() {
-
- /**
- * Will print to log name of test before each test run.
- */
- public void onTestStart(ITestResult result) {
- String methodName = result.getMethod().toString();
- Matcher matcher =
Pattern.compile(".*\\.(.*\\..*)").matcher(methodName);
-
- if (matcher.lookingAt()) {
- methodName = matcher.group(1);
- }
-
- String hashes = "##########";
- System.out.println(String.format("%s %s %s", hashes, methodName,
hashes));
- }
-
- public void onFinish(ITestContext context) {
- }
-
- public void onStart(ITestContext context) {
- }
-
- public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
- }
-
- public void onTestFailure(ITestResult result) {
- }
-
- public void onTestSkipped(ITestResult result) {
- }
-
- public void onTestSuccess(ITestResult result) {
- }
- };
-
- /**
* An abstract implementation of test for testing source code of examples.
*
* @param fieldset
Added:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ConsoleStatusTestListener.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ConsoleStatusTestListener.java
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/ConsoleStatusTestListener.java 2009-12-01
13:19:32 UTC (rev 16025)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.jboss.richfaces.integrationTest;
+
+import java.util.Date;
+
+import org.testng.ITestResult;
+import org.testng.TestListenerAdapter;
+
+import static
org.jboss.richfaces.integrationTest.SeleniumLoggingTestListener.getMethodName;
+import static org.jboss.richfaces.integrationTest.SeleniumLoggingTestListener.STATUSES;
+
+/**
+ * This class is used as ITestListener in testNG tests to put test's status to
+ * the console output
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>, <a
+ * href="mailto:pjha@redhat.com">Prabhat Jha</a>
+ * @version $Revision$
+ *
+ */
+public class ConsoleStatusTestListener extends TestListenerAdapter {
+
+ public void onTestStart(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestFailure(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestSkipped(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestSuccess(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
+ logStatus(result);
+ }
+
+ /**
+ * This method will output method name and status on the standard output
+ *
+ * @param result
+ * from the fine-grained listener's method such as
+ * onTestFailure(ITestResult)
+ */
+ private void logStatus(ITestResult result) {
+ final String methodName = getMethodName(result);
+ final String status = STATUSES.get(result.getStatus());
+
+ String message = String.format("[%tT] %s: %s", new Date(),
status.toUpperCase(), methodName);
+ System.out.println(message);
+ }
+}
Added:
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/SeleniumLoggingTestListener.java
===================================================================
---
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/SeleniumLoggingTestListener.java
(rev 0)
+++
branches/community/3.3.X/samples/richfaces-demo/functional-test/src/test/java/org/jboss/richfaces/integrationTest/SeleniumLoggingTestListener.java 2009-12-01
13:19:32 UTC (rev 16025)
@@ -0,0 +1,135 @@
+/*******************************************************************************
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ *******************************************************************************/
+package org.jboss.richfaces.integrationTest;
+
+import java.util.TreeMap;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.commons.lang.StringUtils;
+import org.testng.ITestResult;
+import org.testng.TestListenerAdapter;
+
+import com.thoughtworks.selenium.DefaultSelenium;
+
+/**
+ * Class determined to logging into Selenium Server's logs server.log via the
+ * DefaultSelenium.getEval(String) method which will evaluate JavaScript
+ * comment.
+ *
+ * You must rewrite the DefaultSelenium selenium property to allow logging
+ * facility.
+ *
+ * @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>
+ * @version $Revision$
+ *
+ */
+public class SeleniumLoggingTestListener extends TestListenerAdapter {
+
+ /**
+ * Must be specified to allow the logging facility
+ */
+ private DefaultSelenium selenium;
+
+ public void setSelenium(DefaultSelenium selenium) {
+ this.selenium = selenium;
+ }
+
+ public DefaultSelenium getSelenium() {
+ return selenium;
+ }
+
+ public void onTestStart(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestFailure(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestSkipped(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestSuccess(ITestResult result) {
+ logStatus(result);
+ }
+
+ public void onTestFailedButWithinSuccessPercentage(ITestResult result) {
+ logStatus(result);
+ }
+
+ /**
+ * This method will output method name and status into Selenium Server's log
+ * server.log via the DefaultSelenium.getEval(String) method which will
+ * evaluate JavaScript comment
+ *
+ * @param result
+ * from the fine-grained listener's method such as
+ * onTestFailure(ITestResult)
+ */
+ private void logStatus(ITestResult result) {
+ final String hashes = "##########";
+ final String methodName = getMethodName(result);
+ final String status = STATUSES.get(result.getStatus());
+
+ String message = String.format("%s %s: %s %s", hashes, status.toUpperCase(),
methodName, hashes);
+ String line = StringUtils.repeat("#", message.length());
+
+ if (selenium != null) {
+ String eval = String.format("/*\n%s\n%s\n%s\n*/", line, message, line);
+ selenium.getEval(eval);
+ }
+ }
+
+ /**
+ * Get method name from ITestResult
+ *
+ * @param result
+ * from the fine-grained listener's method such as
+ * onTestFailure(ITestResult)
+ * @return the method name in current context
+ */
+ protected static String getMethodName(ITestResult result) {
+ String methodName = result.getMethod().toString();
+ Matcher matcher =
Pattern.compile(".*\\.(.*\\..*)\\(\\)").matcher(methodName);
+ if (matcher.lookingAt()) {
+ methodName = matcher.group(1);
+ }
+ return methodName;
+ }
+
+ /**
+ * Mapping of the status ids to string equivalents
+ */
+ protected static TreeMap<Integer, String> STATUSES = new TreeMap<Integer,
String>() {
+ private static final long serialVersionUID = 1L;
+
+ {
+ put(ITestResult.FAILURE, "Failure");
+ put(ITestResult.SKIP, "Skip");
+ put(ITestResult.STARTED, "Started");
+ put(ITestResult.SUCCESS, "Success");
+ put(ITestResult.SUCCESS_PERCENTAGE_FAILURE, "FailurePercentage");
+ }
+ };
+}