Skip to content

Commit 03172d8

Browse files
chore: Update web view detection algorithm for iOS tests (#1294)
1 parent 324fea2 commit 03172d8

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
import java.io.File;
2626
import java.io.IOException;
2727
import java.net.URL;
28+
import java.time.Duration;
2829

2930
public class BaseIOSWebViewTest extends BaseIOSTest {
31+
private static final Duration WEB_VIEW_DETECT_INTERVAL = Duration.ofSeconds(1);
32+
private static final Duration WEB_VIEW_DETECT_DURATION = Duration.ofSeconds(15);
3033

31-
@BeforeClass public static void beforeClass() throws IOException {
34+
@BeforeClass
35+
public static void beforeClass() throws IOException {
3236
final String ip = startAppiumServer();
3337

3438
if (service == null || !service.isRunning()) {
@@ -47,11 +51,17 @@ public class BaseIOSWebViewTest extends BaseIOSTest {
4751
}
4852

4953
protected void findAndSwitchToWebView() throws InterruptedException {
50-
Thread.sleep(10000);
51-
driver.getContextHandles().forEach((handle) -> {
52-
if (handle.contains("WEBVIEW")) {
53-
driver.context(handle);
54+
final long msStarted = System.currentTimeMillis();
55+
while (System.currentTimeMillis() - msStarted <= WEB_VIEW_DETECT_DURATION.toMillis()) {
56+
for (String handle : driver.getContextHandles()) {
57+
if (handle.contains("WEBVIEW")) {
58+
driver.context(handle);
59+
return;
60+
}
5461
}
55-
});
62+
Thread.sleep(WEB_VIEW_DETECT_INTERVAL.toMillis());
63+
}
64+
throw new IllegalStateException(String.format("No web views have been detected within %sms timeout",
65+
WEB_VIEW_DETECT_DURATION.toMillis()));
5666
}
5767
}

0 commit comments

Comments
 (0)