File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
src/test/java/io/appium/java_client/ios Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change 25
25
import java .io .File ;
26
26
import java .io .IOException ;
27
27
import java .net .URL ;
28
+ import java .time .Duration ;
28
29
29
30
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 );
30
33
31
- @ BeforeClass public static void beforeClass () throws IOException {
34
+ @ BeforeClass
35
+ public static void beforeClass () throws IOException {
32
36
final String ip = startAppiumServer ();
33
37
34
38
if (service == null || !service .isRunning ()) {
@@ -47,11 +51,17 @@ public class BaseIOSWebViewTest extends BaseIOSTest {
47
51
}
48
52
49
53
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
+ }
54
61
}
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 ()));
56
66
}
57
67
}
You can’t perform that action at this time.
0 commit comments