Author: lfryc(a)redhat.com
Date: 2010-01-15 07:07:59 -0500 (Fri, 15 Jan 2010)
New Revision: 16302
Modified:
branches/community/3.3.X/test-applications/selenium-testing-lib/src/main/java/org/jboss/test/selenium/waiting/Wait.java
Log:
- richfaces-selenium - added noDelay()/withDelay(boolean) methods to define delay after
start of waiting and first condition testing (RFPL-320)
Modified:
branches/community/3.3.X/test-applications/selenium-testing-lib/src/main/java/org/jboss/test/selenium/waiting/Wait.java
===================================================================
---
branches/community/3.3.X/test-applications/selenium-testing-lib/src/main/java/org/jboss/test/selenium/waiting/Wait.java 2010-01-15
11:43:16 UTC (rev 16301)
+++
branches/community/3.3.X/test-applications/selenium-testing-lib/src/main/java/org/jboss/test/selenium/waiting/Wait.java 2010-01-15
12:07:59 UTC (rev 16302)
@@ -186,6 +186,30 @@
}
/**
+ * Constructs preset instance of waiting (@see Waiting) with no delay by
+ * interval between start waiting and first test for conditions.
+ *
+ * @return Waiting instance initialized with no delay
+ */
+ public static Waiting noDelay() {
+ return getDefault().withDelay(false);
+ }
+
+ /**
+ * Constructs preset instance of waiting (@see Waiting) and set that testing
+ * condition should or shouldn't be delayed of one interval after the start
+ * of waiting.
+ *
+ * @param isDelayed
+ * true if condition testing should be delayed; false otherwise
+ * @return Waiting instance initialized with delay if isDelayed is set to
+ * true; with no delay otherwise
+ */
+ public static Waiting withDelay(boolean isDelayed) {
+ return getDefault().withDelay(isDelayed);
+ }
+
+ /**
* Will wait for default amount of time. Default timeout specified in
* Wait.DEFAULT_TIMEOUT
*/
@@ -263,6 +287,12 @@
private long timeout = DEFAULT_TIMEOUT;
/**
+ * Indicates when the first test for the condition should be delayed
+ * after waiting starts.
+ */
+ public boolean isDelayed = true;
+
+ /**
* Failure indicates waiting timeout.
*
* If is set to null, no failure will be thrown after timeout.
@@ -371,8 +401,37 @@
public Waiting dontFail() {
return failWith((Throwable) null);
}
+
+ /**
+ * Sets no delay by interval between start waiting and first test for
+ * conditions.
+ *
+ * @return Waiting instance initialized with no delay
+ */
+ public Waiting noDelay() {
+ return withDelay(false);
+ }
/**
+ * Set if testing condition should be delayed of one interval after the
+ * start of waiting.
+ *
+ * @param isDelayed
+ * true if condition testing should be delayed; false
+ * otherwise
+ * @return Waiting instance initialized with delay if isDelayed is set
+ * to true; with no delay otherwise
+ */
+ public Waiting withDelay(boolean isDelayed) {
+ if (isDelayed == this.isDelayed) {
+ return this;
+ }
+ Waiting copy = this.copy();
+ copy.isDelayed = isDelayed;
+ return copy;
+ }
+
+ /**
* Stars loop waiting to satisfy condition.
*
* @param condition
@@ -380,15 +439,22 @@
*/
public void until(Condition condition) {
long start = System.currentTimeMillis();
- long end = start + timeout;
+ long end = start + this.timeout;
+ boolean delay = this.isDelayed;
while (System.currentTimeMillis() < end) {
+ if (!delay && condition.isTrue())
+ return;
+ delay = false;
try {
- Thread.sleep(interval);
+ Thread.sleep(this.interval);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
- if (condition.isTrue())
- return;
+ if (System.currentTimeMillis() >= end) {
+ if (condition.isTrue()) {
+ return;
+ }
+ }
}
fail();
}
@@ -475,6 +541,7 @@
copy.interval = this.interval;
copy.timeout = this.timeout;
copy.failure = this.failure;
+ copy.isDelayed = this.isDelayed;
return copy;
}
}
Show replies by date