You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lo...@apache.org on 2012/07/24 18:59:57 UTC
svn commit: r1365170 - in
/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test:
./ tc/
Author: lofwyr
Date: Tue Jul 24 16:59:57 2012
New Revision: 1365170
URL: http://svn.apache.org/viewvc?rev=1365170&view=rev
Log:
TOBAGO-1174: Easier handling of Selenium tests
- cleanup
Added:
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TobagoSelenium.java
Removed:
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/MultiSuffixSeleniumTest.java
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/tc/
Modified:
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SeleniumTest.java
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SimpleSeleniumTest.java
myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java?rev=1365170&r1=1365169&r2=1365170&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/AutomaticSeleniumTest.java Tue Jul 24 16:59:57 2012
@@ -49,12 +49,12 @@ public class AutomaticSeleniumTest exten
public void testPageConsistency() throws Exception {
SeleniumScript script = getSeleniumScript(url);
- getCommandProcessor().doCommand("open", new String[] {"http://localhost:8080/" + "KillSession", ""});
+ getSelenium().killSession();
for (SeleniumScriptItem item : script.getItems()) {
LOG.info("Calling: " + item);
- getCommandProcessor().doCommand(item.getCommand(), item.getParameters());
- checkPage();
+ getSelenium().command(item.getCommand(), item.getParameters()[0], item.getParameters()[1]);
+ getSelenium().checkPage();
}
}
@@ -75,7 +75,7 @@ public class AutomaticSeleniumTest exten
if (!new File(base).exists()) {
base = "tobago-example/tobago-example-test/" + base;
}
-
+
collect(paths, base, "");
Collections.sort(paths);
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SeleniumTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SeleniumTest.java?rev=1365170&r1=1365169&r2=1365170&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SeleniumTest.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SeleniumTest.java Tue Jul 24 16:59:57 2012
@@ -17,10 +17,6 @@ package org.apache.myfaces.tobago.exampl
* limitations under the License.
*/
-import com.thoughtworks.selenium.CommandProcessor;
-import com.thoughtworks.selenium.DefaultSelenium;
-import com.thoughtworks.selenium.HttpCommandProcessor;
-import com.thoughtworks.selenium.SeleniumException;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
@@ -31,106 +27,23 @@ public abstract class SeleniumTest {
// private static final String CONTEXT_PATH = "tobago-example-test";
private static final String SERVLET_MAPPING = "faces";
- public static final String ERROR_ON_SERVER = "error on server";
- public static final String HAS_ERROR_SEVERITY = "has error severity";
- public static final String IS_BROKEN = "is broken";
-
- @Deprecated
- private static DefaultSelenium selenium;
- private static CommandProcessor commandProcessor;
+ private static TobagoSelenium selenium;
@BeforeClass
public static void setUp() throws Exception {
- selenium = createSeleniumClient();
+ selenium = new TobagoSelenium("http://localhost:8080/");
selenium.start();
-//todo alternative commandProcessor.start();
}
@AfterClass
public static void tearDown() throws Exception {
selenium.stop();
-//todo alternative commandProcessor.stop();
}
- @Deprecated
- protected DefaultSelenium getSelenium() {
+ protected TobagoSelenium getSelenium() {
return selenium;
}
- protected CommandProcessor getCommandProcessor() {
- return commandProcessor;
- }
-
- protected static DefaultSelenium createSeleniumClient() throws Exception {
- commandProcessor = new HttpCommandProcessor("localhost", 4444, "*firefox", "http://localhost:8080/");
- return new DefaultSelenium(commandProcessor);
- }
-
- protected void waitForAjaxComplete() {
- getSelenium().waitForCondition(
- "selenium.browserbot.getCurrentWindow().document.getElementsByClassName('tobago-page-overlay').length == 0",
- "5000"
- );
- }
-
- protected void checkPage() {
- final String location = selenium.getLocation();
- final String html = getHtmlSource();
- if (errorOnServer()) {
- Assert.fail(format(ERROR_ON_SERVER, location, html, ""));
- }
- if (location.endsWith(".xhtml") || location.endsWith(".jspx")) {
- try {
- if (isErrorOnPage()) {
- Assert.fail(format(HAS_ERROR_SEVERITY, location, html, getErrors()));
- }
- } catch (SeleniumException e) {
- Assert.fail(format(IS_BROKEN, location, html, "Not a Tobago page? Exception=" + e));
- }
- }
- }
-
- public String format(String error, String location, String html, String options) {
- StringBuilder b = new StringBuilder();
- b.append(error);
- b.append("\nPage URL: ");
- b.append(location);
- b.append("\n");
- b.append(options);
- b.append("\n---------------------------------------------------------------------------------------------------\n");
- b.append(html);
- b.append("\n---------------------------------------------------------------------------------------------------\n");
- return b.toString();
- }
-
- /**
- * Happen an exception from MyFaces on the page?
- */
- protected boolean errorOnServer() {
- return selenium.getHtmlSource().contains("An Error Occurred");
- }
-
- /**
- * Checks the page for the Tobago JavaScript Logging Framework and tests its severity.
- *
- * @return True if the severity level of the page is error
- * @throws com.thoughtworks.selenium.SeleniumException
- * If the page is not a Tobago page, or any other problem with JavaScrpt or the page.
- */
- protected boolean isErrorOnPage() throws SeleniumException {
- String errorSeverity = selenium.getEval("window.LOG.getMaximumSeverity() >= window.LOG.ERROR");
- return Boolean.parseBoolean(errorSeverity);
- }
-
- protected String getErrors() throws SeleniumException {
- String errors = selenium.getEval("window.LOG.getMessages(window.LOG.INFO)");
- return errors;
- }
-
- protected String getHtmlSource() {
- return selenium.getHtmlSource();
- }
-
protected static String createUrl(String page) {
Assert.assertTrue("Page name must start with a slash.", page.startsWith("/"));
if (CONTEXT_PATH.length() == 0) {
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SimpleSeleniumTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SimpleSeleniumTest.java?rev=1365170&r1=1365169&r2=1365170&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SimpleSeleniumTest.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/SimpleSeleniumTest.java Tue Jul 24 16:59:57 2012
@@ -25,7 +25,7 @@ public class SimpleSeleniumTest extends
@Test
public void testHelloWorld() {
getSelenium().open("/faces/simple.xhtml");
- checkPage();
+ getSelenium().checkPage();
Assert.assertEquals("Simple Test", getSelenium().getValue("page:in"));
getSelenium().captureScreenshot(SimpleSeleniumTest.class.getName() + ".testHelloWorld.png");
}
Modified: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java?rev=1365170&r1=1365169&r2=1365170&view=diff
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java (original)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TestTheAutomaticSeleniumTest.java Tue Jul 24 16:59:57 2012
@@ -98,7 +98,7 @@ public class TestTheAutomaticSeleniumTes
Assert.fail("The test should fail, but wasn't.");
} catch (AssertionError e) {
- if (e.getMessage().contains(AutomaticSeleniumTest.HAS_ERROR_SEVERITY)) {
+ if (e.getMessage().contains(TobagoSelenium.HAS_ERROR_SEVERITY)) {
// okay, the error was detected.
} else {
throw e;
@@ -117,7 +117,7 @@ public class TestTheAutomaticSeleniumTes
Assert.fail("The test should fail, but wasn't.");
} catch (AssertionError e) {
- if (e.getMessage().contains(AutomaticSeleniumTest.IS_BROKEN)) {
+ if (e.getMessage().contains(TobagoSelenium.IS_BROKEN)) {
// okay, the error was detected.
} else {
throw e;
Added: myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TobagoSelenium.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TobagoSelenium.java?rev=1365170&view=auto
==============================================================================
--- myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TobagoSelenium.java (added)
+++ myfaces/tobago/trunk/tobago-example/tobago-example-test/src/test/java/org/apache/myfaces/tobago/example/test/TobagoSelenium.java Tue Jul 24 16:59:57 2012
@@ -0,0 +1,98 @@
+package org.apache.myfaces.tobago.example.test;
+
+/*
+ * 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.DefaultSelenium;
+import com.thoughtworks.selenium.HttpCommandProcessor;
+import com.thoughtworks.selenium.SeleniumException;
+import org.junit.Assert;
+
+public class TobagoSelenium extends DefaultSelenium {
+
+ public static final String ERROR_ON_SERVER = "error on server";
+ public static final String HAS_ERROR_SEVERITY = "has error severity";
+ public static final String IS_BROKEN = "is broken";
+
+ private String browserUrl;
+
+ public TobagoSelenium(String browserUrl) {
+ super(new HttpCommandProcessor("localhost", 4444, "*firefox", browserUrl));
+ this.browserUrl = browserUrl;
+ }
+
+ public String command(String command, String parameter1, String parameter2) {
+ return commandProcessor.doCommand(command, new String[]{parameter1, parameter2});
+ }
+
+ public void killSession() {
+ open(browserUrl + "KillSession");
+ }
+
+ public void checkPage() {
+ final String location = getLocation();
+ final String html = getHtmlSource();
+ if (errorOnServer()) {
+ Assert.fail(format(ERROR_ON_SERVER, location, html, ""));
+ }
+ if (location.endsWith(".xhtml") || location.endsWith(".jspx")) {
+ try {
+ if (isErrorOnPage()) {
+ Assert.fail(format(HAS_ERROR_SEVERITY, location, html, getErrors()));
+ }
+ } catch (SeleniumException e) {
+ Assert.fail(format(IS_BROKEN, location, html, "Not a Tobago page? Exception=" + e));
+ }
+ }
+ }
+
+ public String format(String error, String location, String html, String options) {
+ StringBuilder b = new StringBuilder();
+ b.append(error);
+ b.append("\nPage URL: ");
+ b.append(location);
+ b.append("\n");
+ b.append(options);
+ b.append("\n---------------------------------------------------------------------------------------------------\n");
+ b.append(html);
+ b.append("\n---------------------------------------------------------------------------------------------------\n");
+ return b.toString();
+ }
+
+ /**
+ * Happen an exception from MyFaces on the page?
+ */
+ protected boolean errorOnServer() {
+ return getHtmlSource().contains("An Error Occurred");
+ }
+
+ /**
+ * Checks the page for the Tobago JavaScript Logging Framework and tests its severity.
+ *
+ * @return True if the severity level of the page is error
+ * @throws com.thoughtworks.selenium.SeleniumException
+ * If the page is not a Tobago page, or any other problem with JavaScrpt or the page.
+ */
+ protected boolean isErrorOnPage() throws SeleniumException {
+ String errorSeverity = getEval("window.LOG.getMaximumSeverity() >= window.LOG.ERROR");
+ return Boolean.parseBoolean(errorSeverity);
+ }
+
+ protected String getErrors() throws SeleniumException {
+ return getEval("window.LOG.getMessages(window.LOG.INFO)");
+ }
+}