Author: ljelinko
Date: 2012-08-16 04:31:14 -0400 (Thu, 16 Aug 2012)
New Revision: 43068
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/BrowserUrlMatcher.java
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/PageSourceMatcher.java
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/portlet/PortletLoadsInJBPortalMatcher.java
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/console/ConsoleOutputMatcher.java
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/factory/PortletMatchersFactory.java
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/HotDeploymentGateinTemplate.java
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/RunAsLoadsPortalURLTemplate.java
Log:
Added timetouts to some matchers
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/BrowserUrlMatcher.java
===================================================================
---
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/BrowserUrlMatcher.java 2012-08-16
08:30:51 UTC (rev 43067)
+++
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/BrowserUrlMatcher.java 2012-08-16
08:31:14 UTC (rev 43068)
@@ -2,9 +2,13 @@
import java.util.Arrays;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.hamcrest.Description;
import org.jboss.tools.portlet.ui.bot.matcher.AbstractSWTMatcher;
import org.jboss.tools.ui.bot.ext.SWTBotFactory;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
/**
* Checks if the URL of the page laoded in the browser is one of the accepted URLs.
@@ -15,11 +19,21 @@
public class BrowserUrlMatcher extends AbstractSWTMatcher<String[]> {
private String realURL;
-
+
+ private long timeout;
+
+ public BrowserUrlMatcher(TaskDuration duration){
+ timeout = duration.getTimeout();
+ }
+
@Override
public boolean matchesSafely(String[] acceptedURL) {
- realURL = SWTBotFactory.getBot().browser().getUrl();
- return Arrays.asList(acceptedURL).contains(realURL);
+ try {
+ SWTBotFactory.getBot().waitUntil(new BrowserContainsUrlCondition(acceptedURL,
realURL), timeout);
+ return true;
+ } catch (TimeoutException e){
+ return false;
+ }
}
@Override
@@ -27,4 +41,31 @@
description.appendText("are the only allowed loaded URLs but it was:");
description.appendValue(realURL);
}
+
+ private class BrowserContainsUrlCondition extends DefaultCondition {
+
+ private String[] acceptedURL;
+
+ private String realURL;
+
+ public BrowserContainsUrlCondition(String[] acceptedURL, String realURL) {
+ this.acceptedURL = acceptedURL;
+ this.realURL = realURL;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ try {
+ realURL = SWTBotFactory.getBot().browser().getUrl();
+ return Arrays.asList(acceptedURL).contains(realURL);
+ } catch (WidgetNotFoundException e){
+ return false;
+ }
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return null;
+ }
+ }
}
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/PageSourceMatcher.java
===================================================================
---
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/PageSourceMatcher.java 2012-08-16
08:30:51 UTC (rev 43067)
+++
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/PageSourceMatcher.java 2012-08-16
08:31:14 UTC (rev 43068)
@@ -1,8 +1,12 @@
package org.jboss.tools.portlet.ui.bot.matcher.browser;
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
import org.hamcrest.Description;
import org.jboss.tools.portlet.ui.bot.matcher.AbstractSWTMatcher;
-import org.jboss.tools.portlet.ui.bot.task.browser.LoadBrowserPageTask;
+import org.jboss.tools.ui.bot.ext.SWTBotFactory;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
+import org.jboss.tools.ui.bot.ext.parts.SWTBotBrowserExt;
/**
* Checks if the given page contains specified text.
@@ -12,20 +16,41 @@
*/
public class PageSourceMatcher extends AbstractSWTMatcher<String> {
+ private String pageText;
+
private String url;
- private String pageText;
+ private long timeout;
- public PageSourceMatcher(String url) {
+ public PageSourceMatcher() {
super();
+ timeout = 0;
+ }
+
+ public PageSourceMatcher(TaskDuration timeout) {
+ super();
+ this.timeout = timeout.getTimeout();
+ }
+
+ public PageSourceMatcher(String url, TaskDuration duration) {
+ this();
this.url = url;
+ this.timeout = duration.getTimeout();
}
-
+
@Override
public boolean matchesSafely(String item) {
- performInnerTask(new LoadBrowserPageTask(url));
- pageText = getBot().browser().getText();
- return pageText.contains(item);
+ SWTBotBrowserExt browser = SWTBotFactory.getBot().browserExt();
+ if (url != null){
+ browser.loadUrlToBrowser(url, SWTBotFactory.getBot());
+ }
+
+ try {
+ SWTBotFactory.getBot().waitUntil(new PageContainsTextCondition(browser, item),
timeout);
+ return true;
+ } catch (TimeoutException e){
+ return false;
+ }
}
@Override
@@ -33,4 +58,30 @@
description.appendText("is on the page, but there was instead: ");
description.appendValue(pageText);
}
+
+ private class PageContainsTextCondition extends DefaultCondition {
+
+ private SWTBotBrowserExt browser;
+
+ private String expectedText;
+
+ public PageContainsTextCondition(SWTBotBrowserExt browser, String item) {
+ this.browser = browser;
+ this.expectedText = item;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ pageText = browser.getText();
+ if ("".equals(expectedText)){
+ return pageText.equals(expectedText);
+ }
+ return pageText.contains(expectedText);
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return null;
+ }
+ }
}
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/portlet/PortletLoadsInJBPortalMatcher.java
===================================================================
---
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/portlet/PortletLoadsInJBPortalMatcher.java 2012-08-16
08:30:51 UTC (rev 43067)
+++
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/browser/portlet/PortletLoadsInJBPortalMatcher.java 2012-08-16
08:31:14 UTC (rev 43068)
@@ -4,6 +4,7 @@
import org.jboss.tools.portlet.ui.bot.entity.PortletDefinition;
import org.jboss.tools.portlet.ui.bot.matcher.AbstractSWTMatcher;
import org.jboss.tools.portlet.ui.bot.matcher.browser.PageSourceMatcher;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
/**
* Check if the given portlet can be loaded in EPP 4.x runtime.
@@ -17,9 +18,15 @@
private PageSourceMatcher pageMatcher;
+ private TaskDuration duration;
+
+ public PortletLoadsInJBPortalMatcher(TaskDuration duration){
+ this.duration = duration;
+ }
+
@Override
public boolean matchesSafely(PortletDefinition portletTitle) {
- pageMatcher = new PageSourceMatcher(PORTAL_URL + portletTitle.getPage());
+ pageMatcher = new PageSourceMatcher(PORTAL_URL + portletTitle.getPage(), duration);
pageMatcher.setBot(getBot());
return pageMatcher.matchesSafely("<span
class=\"portlet-titlebar-title\">" + portletTitle.getDisplayName() +
"</span>");
}
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/console/ConsoleOutputMatcher.java
===================================================================
---
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/console/ConsoleOutputMatcher.java 2012-08-16
08:30:51 UTC (rev 43067)
+++
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/console/ConsoleOutputMatcher.java 2012-08-16
08:31:14 UTC (rev 43068)
@@ -2,6 +2,7 @@
import org.hamcrest.Description;
import org.jboss.tools.portlet.ui.bot.matcher.AbstractSWTMatcher;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
/**
* Checks if the console contains specified text.
@@ -17,6 +18,10 @@
wrappedMatcher = new
org.jboss.tools.ui.bot.ext.matcher.console.ConsoleOutputMatcher();
}
+ public ConsoleOutputMatcher(TaskDuration duration) {
+ wrappedMatcher = new
org.jboss.tools.ui.bot.ext.matcher.console.ConsoleOutputMatcher(duration);
+ }
+
@Override
public boolean matchesSafely(String item) {
return wrappedMatcher.matchesSafely(item);
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/factory/PortletMatchersFactory.java
===================================================================
---
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/factory/PortletMatchersFactory.java 2012-08-16
08:30:51 UTC (rev 43067)
+++
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/matcher/factory/PortletMatchersFactory.java 2012-08-16
08:31:14 UTC (rev 43068)
@@ -3,6 +3,7 @@
import org.jboss.tools.portlet.ui.bot.entity.PortletDefinition;
import org.jboss.tools.portlet.ui.bot.matcher.SWTMatcher;
import
org.jboss.tools.portlet.ui.bot.matcher.browser.portlet.PortletLoadsInJBPortalMatcher;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
public class PortletMatchersFactory {
@@ -11,6 +12,6 @@
}
public static SWTMatcher<PortletDefinition> canLoadAt4xRuntime(){
- return new PortletLoadsInJBPortalMatcher();
+ return new PortletLoadsInJBPortalMatcher(TaskDuration.NORMAL);
}
}
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/HotDeploymentGateinTemplate.java
===================================================================
---
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/HotDeploymentGateinTemplate.java 2012-08-16
08:30:51 UTC (rev 43067)
+++
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/HotDeploymentGateinTemplate.java 2012-08-16
08:31:14 UTC (rev 43068)
@@ -7,6 +7,7 @@
import org.jboss.tools.portlet.ui.bot.task.editor.CloseAllEditors;
import org.jboss.tools.portlet.ui.bot.task.wizard.web.jboss.AbstractPortletCreationTask;
import org.jboss.tools.portlet.ui.bot.test.testcase.SWTTaskBasedTestCase;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
import org.jboss.tools.ui.bot.ext.config.Annotations.Require;
import org.jboss.tools.ui.bot.ext.config.Annotations.Server;
import org.jboss.tools.ui.bot.ext.config.Annotations.ServerState;
@@ -31,7 +32,7 @@
doPerform(new ConsoleClearingTask());
doPerform(createPortlet());
- assertThatInWorkspace("undeploy, ctxPath=/" + getProjectName(), new
ConsoleOutputMatcher());
- assertThatInWorkspace("deploy, ctxPath=/" + getProjectName(), new
ConsoleOutputMatcher());
+ assertThatInWorkspace("undeploy, ctxPath=/" + getProjectName(), new
ConsoleOutputMatcher(TaskDuration.LONG));
+ assertThatInWorkspace("deploy, ctxPath=/" + getProjectName(), new
ConsoleOutputMatcher(TaskDuration.LONG));
}
}
Modified:
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/RunAsLoadsPortalURLTemplate.java
===================================================================
---
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/RunAsLoadsPortalURLTemplate.java 2012-08-16
08:30:51 UTC (rev 43067)
+++
branches/jbosstools-3.3.x/portlet/tests/org.jboss.tools.portlet.ui.bot.test/src/org/jboss/tools/portlet/ui/bot/test/template/RunAsLoadsPortalURLTemplate.java 2012-08-16
08:31:14 UTC (rev 43068)
@@ -11,6 +11,7 @@
import
org.jboss.tools.portlet.ui.bot.task.wizard.web.jboss.JBossPortletCapabilitiesWizardPageFillingTask;
import org.jboss.tools.portlet.ui.bot.test.testcase.SWTTaskBasedTestCase;
import org.jboss.tools.ui.bot.ext.SWTTestExt;
+import org.jboss.tools.ui.bot.ext.condition.TaskDuration;
import org.junit.Test;
/**
@@ -32,7 +33,7 @@
doPerform(createJavaPortletTask());
doPerform(runOnServerTask());
- doAssertThatInWorkspace(getExpectedURLs(), new BrowserUrlMatcher());
+ doAssertThatInWorkspace(getExpectedURLs(), new
BrowserUrlMatcher(TaskDuration.NORMAL));
}
private SWTTask createJavaPortletTask() {