2222import static org .mockito .Mockito .when ;
2323import static org .testng .Assert .assertThrows ;
2424import static org .testng .Assert .expectThrows ;
25- import static utam .core .selenium .appium .MobileDriverAdapter .NATIVE_CONTEXT_HANDLE ;
26- import static utam .core .selenium .appium .MobileDriverAdapter .WEBVIEW_CONTEXT_HANDLE_PREFIX ;
25+ import static utam .core .selenium .appium .MobileDriverAdapter .*;
2726
2827import io .appium .java_client .AppiumDriver ;
2928import io .appium .java_client .remote .SupportsContextSwitching ;
@@ -131,9 +130,13 @@ public void testSwitchToWebViewTimeout() {
131130
132131 String testWebViewHandle = WEBVIEW_CONTEXT_HANDLE_PREFIX + "_1" ;
133132
134- Map <String , Object > nativeContext = Map .of ("id" , NATIVE_CONTEXT_HANDLE );
133+ Map <String , Object > nativeContext = Map .of (WEBVIEW_CONTEXT_KEY_IOS , NATIVE_CONTEXT_HANDLE );
135134 Map <String , Object > webviewContext =
136- Map .of ("id" , testWebViewHandle , "title" , DEFAULT_APP_CONTEXT_TITLE );
135+ Map .of (
136+ WEBVIEW_CONTEXT_KEY_IOS ,
137+ testWebViewHandle ,
138+ WEBVIEW_TITLE_KEY_IOS ,
139+ DEFAULT_APP_CONTEXT_TITLE );
137140
138141 Set <String > contextHandles =
139142 Stream .of (NATIVE_CONTEXT_HANDLE , testWebViewHandle ).collect (Collectors .toSet ());
@@ -160,9 +163,13 @@ public void testSwitchToWebView() {
160163
161164 String testWebViewHandle = WEBVIEW_CONTEXT_HANDLE_PREFIX + "_1" ;
162165
163- Map <String , Object > nativeContext = Map .of ("id" , NATIVE_CONTEXT_HANDLE );
166+ Map <String , Object > nativeContext = Map .of (WEBVIEW_CONTEXT_KEY_IOS , NATIVE_CONTEXT_HANDLE );
164167 Map <String , Object > webviewContext =
165- Map .of ("id" , testWebViewHandle , "title" , DEFAULT_WEBVIEW_TITLE );
168+ Map .of (
169+ WEBVIEW_CONTEXT_KEY_IOS ,
170+ testWebViewHandle ,
171+ WEBVIEW_TITLE_KEY_IOS ,
172+ DEFAULT_WEBVIEW_TITLE );
166173
167174 Set <String > contextHandles =
168175 Stream .of (NATIVE_CONTEXT_HANDLE , testWebViewHandle ).collect (Collectors .toSet ());
@@ -196,9 +203,13 @@ public void testSwitchToWebViewAlreadyOnTargetPage() {
196203 SupportsContextSwitching contextSwitcher = mock .getContextSwitcherMock ();
197204 MobileDriverAdapter provider = mock .getMobileDriverAdapter ();
198205
199- Map <String , Object > nativeContext = Map .of ("id" , NATIVE_CONTEXT_HANDLE );
206+ Map <String , Object > nativeContext = Map .of (WEBVIEW_CONTEXT_KEY_IOS , NATIVE_CONTEXT_HANDLE );
200207 Map <String , Object > webviewContext =
201- Map .of ("id" , testWebViewHandle , "title" , DEFAULT_WEBVIEW_TITLE );
208+ Map .of (
209+ WEBVIEW_CONTEXT_KEY_IOS ,
210+ testWebViewHandle ,
211+ WEBVIEW_TITLE_KEY_IOS ,
212+ DEFAULT_WEBVIEW_TITLE );
202213
203214 Set <String > contextHandles =
204215 new HashSet <>(Arrays .asList (NATIVE_CONTEXT_HANDLE , testWebViewHandle ));
@@ -233,9 +244,13 @@ public void testSwitchToBridge() {
233244
234245 String testWebViewHandle = WEBVIEW_CONTEXT_HANDLE_PREFIX + "_1" ;
235246
236- Map <String , Object > nativeContext = Map .of ("id" , NATIVE_CONTEXT_HANDLE );
247+ Map <String , Object > nativeContext = Map .of (WEBVIEW_CONTEXT_KEY_IOS , NATIVE_CONTEXT_HANDLE );
237248 Map <String , Object > webviewContext =
238- Map .of ("id" , testWebViewHandle , "title" , DEFAULT_APP_CONTEXT_TITLE );
249+ Map .of (
250+ WEBVIEW_CONTEXT_KEY_IOS ,
251+ testWebViewHandle ,
252+ WEBVIEW_TITLE_KEY_IOS ,
253+ DEFAULT_APP_CONTEXT_TITLE );
239254
240255 Set <String > contextHandles =
241256 Stream .of (NATIVE_CONTEXT_HANDLE , testWebViewHandle ).collect (Collectors .toSet ());
@@ -309,13 +324,13 @@ public void testSwitchToWebViewWait() {
309324 String testWebViewHandle = WEBVIEW_CONTEXT_HANDLE_PREFIX + "_1" ;
310325 String testWebViewTitle = "Test Application" ;
311326
312- Map <String , Object > nativeContext = Map .of ("id" , NATIVE_CONTEXT_HANDLE );
313- Map <String , Object > webviewContext = Map .of ("id" , testWebViewHandle , "title" , testWebViewTitle );
327+ Map <String , Object > nativeContext = Map .of (WEBVIEW_CONTEXT_KEY_IOS , NATIVE_CONTEXT_HANDLE );
328+ Map <String , Object > webviewContext =
329+ Map .of (WEBVIEW_CONTEXT_KEY_IOS , testWebViewHandle , WEBVIEW_TITLE_KEY_IOS , testWebViewTitle );
314330
315331 List <Map <String , Object >> contexts = List .of (nativeContext , webviewContext );
316332
317333 when (driver .executeScript (CONTEXT_SCRIPT , CONTEXT_ARGS )).thenReturn (contexts );
318- when (driver .getTitle ()).thenReturn (testWebViewTitle );
319334 when (contextSwitcher .context (anyString ()))
320335 .then (
321336 (arg ) -> {
@@ -338,20 +353,20 @@ public void testSwitchToWebViewWait() {
338353 public void testSwitchToWebViewAndPageTimeout () {
339354 MockUtilities mock = new MockUtilities (AppiumDriver .class );
340355 AppiumDriver driver = mock .getAppiumDriverMock ();
341- SupportsContextSwitching contextSwitcher = mock .getContextSwitcherMock ();
342356
343- String testWebViewHandle = WEBVIEW_CONTEXT_HANDLE_PREFIX + "_1" ;
344357 String testWebViewTitle = "Test Application" ;
345358 String testWebViewName = "WEBVIEW_com.io.appium.setting" ;
346359
347360 Map <String , Object > page1 =
348- Map .of ("description" , "{\" visible\" :true}" , "title" , testWebViewTitle );
361+ Map .of (
362+ WEBVIEW_PAGE_DESCRIPTION_KEY ,
363+ "{\" " + WEBVIEW_PAGE_DESCRIPTION_VISIBILITY_KEY + "\" :true}" ,
364+ WEBVIEW_TITLE_KEY_ANDROID ,
365+ testWebViewTitle );
349366 List <Map <String , Object >> pages = List .of (page1 );
350- Map context =
351- Map .of ("webview" , testWebViewHandle , "pages" , pages , "webviewName" , testWebViewName );
367+ Map context = Map .of (WEBVIEW_PAGES_KEY , pages , WEBVIEW_CONTEXT_KEY_ANDROID , testWebViewName );
352368
353369 when (driver .executeScript (CONTEXT_SCRIPT , CONTEXT_ARGS )).thenReturn (List .of (context ));
354- when (contextSwitcher .context (testWebViewHandle )).thenReturn (driver );
355370 MobileDriverAdapter adapter = mock .getMobileDriverAdapter ();
356371 mock .setMobilePlatform (Platform .ANDROID );
357372 TimeoutException e =
@@ -376,10 +391,11 @@ public void testSwitchToWebViewWithMultipleWebViewsiOS() {
376391 String testWebViewHandle = WEBVIEW_CONTEXT_HANDLE_PREFIX + "_1" ;
377392 String testWebViewTitle = "Test Application" ;
378393
379- Map <String , Object > nativeContext = Map .of ("id" , NATIVE_CONTEXT_HANDLE );
380- Map <String , Object > webviewContext1 = Map .of ("id" , "" , "title" , "" );
394+ Map <String , Object > nativeContext = Map .of (WEBVIEW_CONTEXT_KEY_IOS , NATIVE_CONTEXT_HANDLE );
395+ Map <String , Object > webviewContext1 =
396+ Map .of (WEBVIEW_CONTEXT_KEY_IOS , "" , WEBVIEW_TITLE_KEY_IOS , "" );
381397 Map <String , Object > webviewContext2 =
382- Map .of ("id" , testWebViewHandle , "title" , testWebViewTitle );
398+ Map .of (WEBVIEW_CONTEXT_KEY_IOS , testWebViewHandle , WEBVIEW_TITLE_KEY_IOS , testWebViewTitle );
383399
384400 List <Map <String , Object >> contexts = List .of (nativeContext , webviewContext1 , webviewContext2 );
385401
@@ -412,18 +428,28 @@ public void testSwitchToWebViewWithMultipleWebViewsAndroid() {
412428 SupportsContextSwitching contextSwitcher = mock .getContextSwitcherMock ();
413429 TargetLocator mockLocator = mock (TargetLocator .class );
414430
415- String testWebViewHandle = WEBVIEW_CONTEXT_HANDLE_PREFIX + "_1" ;
416431 String testWebViewName = "WEBVIEW_com.io.appium.setting" ;
417432 String testWebViewTitle = "Test Application" ;
418433 String testWindowHandle = "123" ;
419434
420- Map <String , Object > page1 = Map .of ("description" , "{\" visible\" :true}" , "id" , "" , "title" , "" );
435+ Map <String , Object > page1 =
436+ Map .of (
437+ WEBVIEW_PAGE_DESCRIPTION_KEY ,
438+ "{\" " + WEBVIEW_PAGE_DESCRIPTION_VISIBILITY_KEY + "\" :true}" ,
439+ WEBVIEW_PAGE_KEY ,
440+ "" ,
441+ WEBVIEW_TITLE_KEY_ANDROID ,
442+ "" );
421443 Map <String , Object > page2 =
422444 Map .of (
423- "description" , "{\" visible\" :true}" , "id" , testWindowHandle , "title" , testWebViewTitle );
445+ WEBVIEW_PAGE_DESCRIPTION_KEY ,
446+ "{\" " + WEBVIEW_PAGE_DESCRIPTION_VISIBILITY_KEY + "\" :true}" ,
447+ WEBVIEW_PAGE_KEY ,
448+ testWindowHandle ,
449+ WEBVIEW_TITLE_KEY_ANDROID ,
450+ testWebViewTitle );
424451 List <Map <String , Object >> pages = List .of (page1 , page2 );
425- Map context =
426- Map .of ("webview" , testWebViewHandle , "pages" , pages , "webviewName" , testWebViewName );
452+ Map context = Map .of (WEBVIEW_PAGES_KEY , pages , WEBVIEW_CONTEXT_KEY_ANDROID , testWebViewName );
427453
428454 when (driver .executeScript (CONTEXT_SCRIPT , CONTEXT_ARGS )).thenReturn (List .of (context ));
429455 when (contextSwitcher .context (anyString ()))
@@ -439,7 +465,7 @@ public void testSwitchToWebViewWithMultipleWebViewsAndroid() {
439465 windowHandleTracker .currentHandle = arg .getArgument (0 );
440466 return driver ;
441467 });
442- when (contextSwitcher .getContext ()).thenReturn (testWebViewHandle );
468+ when (contextSwitcher .getContext ()).thenReturn (testWebViewName );
443469 MobileDriverAdapter adapter = mock .getMobileDriverAdapter ();
444470 mock .setMobilePlatform (Platform .ANDROID );
445471 assertThat (
0 commit comments