Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions src/test/java/io/appium/java_client/ios/BaseIOSWebViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.time.Duration;

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

@BeforeClass public static void beforeClass() throws IOException {
@BeforeClass
public static void beforeClass() throws IOException {
final String ip = startAppiumServer();

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

protected void findAndSwitchToWebView() throws InterruptedException {
Thread.sleep(10000);
driver.getContextHandles().forEach((handle) -> {
if (handle.contains("WEBVIEW")) {
driver.context(handle);
final long msStarted = System.currentTimeMillis();
while (System.currentTimeMillis() - msStarted <= WEB_VIEW_DETECT_DURATION.toMillis()) {
for (String handle : driver.getContextHandles()) {
if (handle.contains("WEBVIEW")) {
driver.context(handle);
return;
}
}
});
Thread.sleep(WEB_VIEW_DETECT_INTERVAL.toMillis());
}
throw new IllegalStateException(String.format("No web views have been detected within %sms timeout",
WEB_VIEW_DETECT_DURATION.toMillis()));
}
}