Skip to content

Commit a79f932

Browse files
committed
Moving Wait from com.thoughtworks.selenium to com.thoughtworks.selenium.webdriven because it is not used outside this package, and RC is going to be removed soon
1 parent 1cf9853 commit a79f932

File tree

7 files changed

+126
-5
lines changed

7 files changed

+126
-5
lines changed

java/client/src/com/thoughtworks/selenium/Wait.java

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
*
3434
*
3535
* @author Dan Fabulich
36+
*
37+
* @deprecated Moved to com.thoughtworks.selenium.webdriven
3638
*
3739
*/
3840
public abstract class Wait {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
Copyright 2006-2014 Selenium committers
3+
Copyright 2006-2014 Software Freedom Conservancy
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
19+
package com.thoughtworks.selenium.webdriven;
20+
21+
/**
22+
* A utility class, designed to help the user automatically wait until a condition turns true.
23+
*
24+
* Use it like this:
25+
*
26+
* <p>
27+
* <code>new Wait("Couldn't find close button!") {<br/>
28+
* &nbsp;&nbsp;&nbsp;&nbsp;boolean until() {<br/>
29+
* &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return selenium.isElementPresent("button_Close");<br/>
30+
* &nbsp;&nbsp;&nbsp;&nbsp;}<br/>
31+
* };</code>
32+
* </p>
33+
*/
34+
public abstract class Wait {
35+
public Wait() {
36+
}
37+
38+
public Wait(String messageToShowIfTimeout) {
39+
wait(messageToShowIfTimeout, DEFAULT_TIMEOUT, DEFAULT_INTERVAL);
40+
}
41+
42+
/** Returns true when it's time to stop waiting */
43+
public abstract boolean until();
44+
45+
/** The amount of time to wait before giving up; the default is 30 seconds */
46+
public static final long DEFAULT_TIMEOUT = 30000L;
47+
48+
/** The interval to pause between checking; the default is 500 milliseconds */
49+
public static final long DEFAULT_INTERVAL = 500L;
50+
51+
/**
52+
* Wait until the "until" condition returns true or time runs out.
53+
*
54+
* @param message the failure message
55+
* @throws WaitTimedOutException if "until" doesn't return true until the timeout
56+
* @see #until()
57+
*/
58+
public void wait(String message) {
59+
wait(message, DEFAULT_TIMEOUT, DEFAULT_INTERVAL);
60+
}
61+
62+
/**
63+
* Wait until the "until" condition returns true or time runs out.
64+
*
65+
* @param message the failure message
66+
* @param timeoutInMilliseconds the amount of time to wait before giving up
67+
* @throws WaitTimedOutException if "until" doesn't return true until the timeout
68+
* @see #until()
69+
*/
70+
public void wait(String message, long timeoutInMilliseconds) {
71+
wait(message, timeoutInMilliseconds, DEFAULT_INTERVAL);
72+
}
73+
74+
/**
75+
* Wait until the "until" condition returns true or time runs out.
76+
*
77+
* @param message the failure message
78+
* @param timeoutInMilliseconds the amount of time to wait before giving up
79+
* @param intervalInMilliseconds the interval to pause between checking "until"
80+
* @throws WaitTimedOutException if "until" doesn't return true until the timeout
81+
* @see #until()
82+
*/
83+
public void wait(String message, long timeoutInMilliseconds, long intervalInMilliseconds) {
84+
long start = System.currentTimeMillis();
85+
long end = start + timeoutInMilliseconds;
86+
while (System.currentTimeMillis() < end) {
87+
if (until()) return;
88+
try {
89+
Thread.sleep(intervalInMilliseconds);
90+
} catch (InterruptedException e) {
91+
throw new RuntimeException(e);
92+
}
93+
}
94+
throw new WaitTimedOutException(message);
95+
}
96+
97+
public class WaitTimedOutException extends RuntimeException {
98+
99+
private static final long serialVersionUID = 1L;
100+
101+
public WaitTimedOutException() {
102+
super();
103+
}
104+
105+
public WaitTimedOutException(String message, Throwable cause) {
106+
super(message, cause);
107+
}
108+
109+
public WaitTimedOutException(String message) {
110+
super(message);
111+
}
112+
113+
public WaitTimedOutException(Throwable cause) {
114+
super(cause);
115+
}
116+
117+
}
118+
}

java/client/src/com/thoughtworks/selenium/webdriven/commands/WaitForCondition.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
package com.thoughtworks.selenium.webdriven.commands;
1919

20-
import com.thoughtworks.selenium.Wait;
20+
import com.thoughtworks.selenium.webdriven.Wait;
2121
import com.thoughtworks.selenium.webdriven.ScriptMutator;
2222
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
2323

java/client/src/com/thoughtworks/selenium/webdriven/commands/WaitForPageToLoad.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.google.common.base.Throwables;
2020

21-
import com.thoughtworks.selenium.Wait;
21+
import com.thoughtworks.selenium.webdriven.Wait;
2222
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
2323

2424
import org.openqa.selenium.By;

java/client/src/com/thoughtworks/selenium/webdriven/commands/WaitForPopup.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package com.thoughtworks.selenium.webdriven.commands;
1818

1919
import com.thoughtworks.selenium.SeleniumException;
20-
import com.thoughtworks.selenium.Wait;
20+
import com.thoughtworks.selenium.webdriven.Wait;
2121
import com.thoughtworks.selenium.webdriven.SeleneseCommand;
2222
import com.thoughtworks.selenium.webdriven.Windows;
2323

java/client/test/com/thoughtworks/selenium/WaitTest.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
import static org.junit.Assert.assertTrue;
2222
import static org.junit.Assert.fail;
2323

24-
import com.thoughtworks.selenium.Wait.WaitTimedOutException;
24+
import com.thoughtworks.selenium.webdriven.Wait;
25+
import com.thoughtworks.selenium.webdriven.Wait.WaitTimedOutException;
2526

2627
import org.junit.Before;
2728
import org.junit.Test;

java/client/test/org/openqa/selenium/v1/WebDriverBackedSeleniumLargeTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static org.junit.Assert.fail;
2121

2222
import com.thoughtworks.selenium.Selenium;
23-
import com.thoughtworks.selenium.Wait;
23+
import com.thoughtworks.selenium.webdriven.Wait;
2424
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium;
2525

2626
import org.junit.Before;

0 commit comments

Comments
 (0)