Author: lfryc(a)redhat.com
Date: 2009-12-01 11:28:32 -0500 (Tue, 01 Dec 2009)
New Revision: 16028
Added:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java
Modified:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
Log:
- added RichfacesSelenium adapter to DefaultSelenium to catch Permission denied exceptions
caused by AJAX (tries repeating the command)
Modified:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java
===================================================================
---
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-01
16:15:55 UTC (rev 16027)
+++
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/AbstractSeleniumRichfacesTestCase.java 2009-12-01
16:28:32 UTC (rev 16028)
@@ -42,8 +42,6 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
-import com.thoughtworks.selenium.DefaultSelenium;
-
/**
*
* @author <a href="mailto:lfryc@redhat.com">Lukas Fryc</a>, <a
@@ -125,14 +123,16 @@
this.mavenResourcesDir = mavenResourcesDir;
this.mavenProjectBuildDirectory = mavenProjectBuildDirectory;
- selenium = new DefaultSelenium(seleniumHost, Integer.valueOf(seleniumPort), browser,
contextRoot);
+
+ selenium = RichfacesSelenium.getInstance(seleniumHost, Integer.valueOf(seleniumPort),
browser,
+ contextRoot);
selenium.start();
allowInitialXpath();
loadCustomLocationStrategies();
// adding selenium-side logging facility
loggingTestListener.setSelenium(selenium);
}
-
+
/**
* Uses selenium.addLocationStrategy to implement own strategies to locate
* items in the tested page
@@ -157,16 +157,16 @@
selenium.allowNativeXpath("false");
}
- /**
- * Finalize context after each class run.
- */
- @AfterClass
- public void finalizeContext() {
- selenium.close();
- selenium.stop();
- selenium = null;
- contextPath = null;
- }
+ /**
+ * Finalize context after each class run.
+ */
+ @AfterClass
+ public void finalizeContext() {
+ selenium.close();
+ selenium.stop();
+ selenium = null;
+ contextPath = null;
+ }
/**
* Default implementation of obtaining properties for each class.
@@ -250,37 +250,37 @@
* name of component given from components' menu on the left of
* RF Live Demo application
*/
- protected void openComponent(final String componentName) {
+ protected void openComponent(final String componentName) {
final String LOC_MENU_ITEM = format("jquery=table.left_menu td.text a >
span:textEquals('{0}')", componentName);
// TODO needs to open clean page, see {@link
- //
https://jira.jboss.org/jira/browse/RF-7640}
- selenium.getEval("selenium.doDeleteAllVisibleCookies()");
+ //
https://jira.jboss.org/jira/browse/RF-7640}
+ selenium.getEval("selenium.doDeleteAllVisibleCookies()");
- // open context path of application
+ // open context path of application
selenium.open(contextPath);
- // wait for new page is opened
- selenium.waitForPageToLoad("5000");
+ // wait for new page is opened
+ selenium.waitForPageToLoad("5000");
- Wait.until(new Condition() {
- public boolean isTrue() {
- return selenium.isElementPresent(LOC_MENU_ITEM);
- }
- });
-
- // click the menu item
- selenium.click(LOC_MENU_ITEM);
+ Wait.until(new Condition() {
+ public boolean isTrue() {
+ return selenium.isElementPresent(LOC_MENU_ITEM);
+ }
+ });
- // wait for component's page opened
- waitModelUpdate.until(new Condition() {
- public boolean isTrue() {
- return isComponentPageActive(componentName);
- }
- });
- }
+ // click the menu item
+ selenium.click(LOC_MENU_ITEM);
+ // wait for component's page opened
+ waitModelUpdate.until(new Condition() {
+ public boolean isTrue() {
+ return isComponentPageActive(componentName);
+ }
+ });
+ }
+
private boolean isComponentPageActive(String componentName) {
final String LOC_OUTPUT_COMPONENT_NAME = "jquery=body table.left_menu
*.panel_documents strong";
return componentName.equals(getTextOrNull(LOC_OUTPUT_COMPONENT_NAME));
Added:
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java
===================================================================
---
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java
(rev 0)
+++
branches/sandbox/rf-demo-ftest-iexplore/src/test/java/org/jboss/richfaces/integrationTest/RichfacesSelenium.java 2009-12-01
16:28:32 UTC (rev 16028)
@@ -0,0 +1,73 @@
+package org.jboss.richfaces.integrationTest;
+
+import org.apache.commons.lang.ArrayUtils;
+import org.apache.commons.lang.StringUtils;
+import org.jboss.test.selenium.waiting.Retrieve;
+import org.jboss.test.selenium.waiting.Wait;
+
+import com.thoughtworks.selenium.CommandProcessor;
+import com.thoughtworks.selenium.DefaultSelenium;
+import com.thoughtworks.selenium.HttpCommandProcessor;
+import com.thoughtworks.selenium.SeleniumException;
+
+public class RichfacesSelenium extends DefaultSelenium {
+
+ public RichfacesSelenium(CommandProcessor processor) {
+ super(processor);
+ }
+
+ public static RichfacesSelenium getInstance(String serverHost, int serverPort, String
browserStartCommand,
+ String browserURL) {
+ return new RichfacesSelenium(new RichfacesCommandProcessor(serverHost, serverPort,
browserStartCommand,
+ browserURL));
+ }
+
+ public static class RichfacesCommandProcessor extends HttpCommandProcessor {
+ public RichfacesCommandProcessor(String serverHost, int serverPort, String
browserStartCommand,
+ String browserURL) {
+ super(serverHost, serverPort, browserStartCommand, browserURL);
+ }
+
+ private abstract class Command<T> {
+ public abstract T command();
+ }
+
+ private static String[] PERMISSION_DENIED = new String[] {
+ "ERROR: Threw an exception: Error executing strategy function jquery: Permission
denied",
+ "ERROR: Threw an exception: Permission denied",
+ "ERROR: Threw an exception: Object doesn't support this property or
method" };
+
+ private <T> T doAjax(final Command<T> command) {
+ final T start = null;
+ final SeleniumException fail = new SeleniumException(
+ "Fails with Permission denied when trying to execute jQuery");
+
+ return
Wait.timeout(Wait.DEFAULT_TIMEOUT).interval(25).failWith(fail).waitForChangeAndReturn(start,
+ new Retrieve<T>() {
+ public T retrieve() {
+ try {
+ return command.command();
+ } catch (SeleniumException e) {
+ final String message = StringUtils.defaultString(e.getMessage());
+ if (ArrayUtils.contains(PERMISSION_DENIED, message)) {
+ fail.setStackTrace((StackTraceElement[]) ArrayUtils.add(fail.getStackTrace(), e
+ .getStackTrace()[0]));
+ return null;
+ }
+ throw e;
+ }
+ }
+ });
+ }
+
+ @Override
+ public String doCommand(final String commandName, final String[] args) {
+ return doAjax(new Command<String>() {
+ @Override
+ public String command() {
+ return RichfacesCommandProcessor.super.doCommand(commandName, args);
+ }
+ });
+ }
+ }
+}