[jbosstools-commits] JBoss Tools SVN: r41964 - trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/matcher/console.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Thu Jun 14 07:40:42 EDT 2012
Author: ljelinko
Date: 2012-06-14 07:40:41 -0400 (Thu, 14 Jun 2012)
New Revision: 41964
Modified:
trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/matcher/console/ConsoleOutputMatcher.java
Log:
Added possibility to wait until the required text appears in console
Modified: trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/matcher/console/ConsoleOutputMatcher.java
===================================================================
--- trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/matcher/console/ConsoleOutputMatcher.java 2012-06-14 05:24:49 UTC (rev 41963)
+++ trunk/tests/plugins/org.jboss.tools.ui.bot.ext/src/org/jboss/tools/ui/bot/ext/matcher/console/ConsoleOutputMatcher.java 2012-06-14 11:40:41 UTC (rev 41964)
@@ -1,11 +1,15 @@
package org.jboss.tools.ui.bot.ext.matcher.console;
+import org.eclipse.swtbot.swt.finder.SWTBot;
+import org.eclipse.swtbot.swt.finder.waits.ICondition;
+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;
/**
- * Checks if the console contains specified text.
+ * Checks if the console contains specified text (and waits for it to appear if necessary).
*
* @author Lucia Jelinkova
*
@@ -13,18 +17,63 @@
public class ConsoleOutputMatcher extends TypeSafeMatcher<String> {
private String consoleText;
+
+ private long timeout;
+
+ public ConsoleOutputMatcher() {
+ timeout = 0;
+ }
+ public ConsoleOutputMatcher(long timeout) {
+ this.timeout = timeout;
+ }
+
+ public ConsoleOutputMatcher(TaskDuration taskDuration) {
+ this.timeout = taskDuration.getTimeout();
+ }
+
@Override
public boolean matchesSafely(String item) {
- consoleText = SWTBotFactory.getConsole().getConsoleText();
- if (consoleText == null){
- throw new IllegalStateException("No console output present");
+ try {
+ SWTBotFactory.getBot().waitUntil(new ConsoleContainsTextCondition(item), timeout);
+ if (consoleText == null){
+ throw new IllegalStateException("No console output present");
+ }
+ return true;
+ } catch (TimeoutException e){
+ return false;
}
- return consoleText.contains(item);
}
@Override
public void describeTo(Description description) {
description.appendText("is in console output, but instead: \n" + consoleText);
}
+
+ private class ConsoleContainsTextCondition implements ICondition {
+
+ private String expectedText;
+
+ public ConsoleContainsTextCondition(String item) {
+ this.expectedText = item;
+ }
+
+ @Override
+ public boolean test() throws Exception {
+ consoleText = SWTBotFactory.getConsole().getConsoleText();
+ if (consoleText == null){
+ return false;
+ }
+ return consoleText.contains(expectedText);
+ }
+
+ @Override
+ public void init(SWTBot bot) {
+ }
+
+ @Override
+ public String getFailureMessage() {
+ return null;
+ }
+ }
}
More information about the jbosstools-commits
mailing list