File tree Expand file tree Collapse file tree
src/test/java/io/appium/java_client/ios Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525import java .io .File ;
2626import java .io .IOException ;
2727import java .net .URL ;
28+ import java .time .Duration ;
2829
2930public 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}
You can’t perform that action at this time.
0 commit comments