[jbosstools-commits] JBoss Tools SVN: r42943 - in branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test: web and 1 other directory.

jbosstools-commits at lists.jboss.org jbosstools-commits at lists.jboss.org
Thu Aug 9 04:40:21 EDT 2012


Author: ljelinko
Date: 2012-08-09 04:40:20 -0400 (Thu, 09 Aug 2012)
New Revision: 42943

Modified:
   branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/template/DeployJSPProjectTemplate.java
   branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/web/PageSourceMatcher.java
Log:
Changed PageSourceMatcher so that it actually waits for the text to appear. 

Modified: branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/template/DeployJSPProjectTemplate.java
===================================================================
--- branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/template/DeployJSPProjectTemplate.java	2012-08-09 08:38:01 UTC (rev 42942)
+++ branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/template/DeployJSPProjectTemplate.java	2012-08-09 08:40:20 UTC (rev 42943)
@@ -51,7 +51,7 @@
 		assertThat("Exception:", not(new ConsoleOutputMatcher()));
 		// web
 		serversView.openWebPage(configuredState.getServer().name, PROJECT_NAME);
-		assertThat("Hello tests!", new PageSourceMatcher());
+		assertThat("Hello tests!", new PageSourceMatcher(TaskDuration.SHORT));
 		// view
 		assertTrue("Server contains project", serversView.containsProject(configuredState.getServer().name, PROJECT_NAME));
 		assertEquals("Started", serversView.getServerStatus(configuredState.getServer().name));

Modified: branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/web/PageSourceMatcher.java
===================================================================
--- branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/web/PageSourceMatcher.java	2012-08-09 08:38:01 UTC (rev 42942)
+++ branches/jbosstools-3.3.x/as/tests/org.jboss.ide.eclipse.as.ui.bot.test/src/org/jboss/ide/eclipse/as/ui/bot/test/web/PageSourceMatcher.java	2012-08-09 08:40:20 UTC (rev 42943)
@@ -1,8 +1,11 @@
 package org.jboss.ide.eclipse.as.ui.bot.test.web;
 
+import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
 import org.hamcrest.Description;
 import org.hamcrest.TypeSafeMatcher;
 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;
 
 public class PageSourceMatcher extends TypeSafeMatcher<String> {
@@ -11,13 +14,27 @@
 
 	private String url;
 	
+	private long timeout;
+	
 	public PageSourceMatcher() {
 		super();
+		timeout = 0;
 	}
 
+	public PageSourceMatcher(long timeout) {
+		super();
+		this.timeout = timeout;
+	}
+	
+	public PageSourceMatcher(TaskDuration timeout) {
+		super();
+		this.timeout = timeout.getTimeout();
+	}
+	
 	public PageSourceMatcher(String url) {
 		this();
 		this.url = url;
+		this.timeout = 0;
 	}
 	
 	@Override
@@ -27,11 +44,12 @@
 			browser.loadUrlToBrowser(url, SWTBotFactory.getBot());
 		}
 		
-		pageText = browser.getText();
-		if ("".equals(item)){
-			return pageText.equals(item);
+		try {
+			SWTBotFactory.getBot().waitUntil(new PageContainsTextCondition(browser, item), timeout);
+			return true;
+		} catch (TimeoutException e){
+			return false;
 		}
-		return pageText.contains(item);
 	}
 
 	@Override
@@ -39,4 +57,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;
+		}
+	}
 }



More information about the jbosstools-commits mailing list