|
30 | 30 | import java.util.Arrays; |
31 | 31 | import java.util.Collections; |
32 | 32 | import java.util.HashSet; |
| 33 | +import java.util.List; |
33 | 34 | import java.util.Set; |
34 | 35 | import java.util.stream.Collectors; |
35 | 36 | import java.util.stream.Stream; |
36 | 37 | import org.openqa.selenium.Platform; |
37 | 38 | import org.openqa.selenium.TimeoutException; |
| 39 | +import org.openqa.selenium.UnsupportedCommandException; |
38 | 40 | import org.openqa.selenium.WebDriver.Navigation; |
39 | 41 | import org.openqa.selenium.WebDriver.TargetLocator; |
40 | 42 | import org.testng.annotations.Test; |
@@ -253,7 +255,6 @@ public void testIsAnyWebViewContextAvailableWithNoWebView() { |
253 | 255 | @Test |
254 | 256 | public void testIsAnyWebViewContextAvailable() { |
255 | 257 | MockUtilities mock = new MockUtilities(AppiumDriver.class); |
256 | | - AppiumDriver driver = (AppiumDriver) mock.getWebDriverMock(); |
257 | 258 | SupportsContextSwitching contextSwitcher = mock.getContextSwitcherMock(); |
258 | 259 | MobileDriverAdapter provider = (MobileDriverAdapter) mock.getDriverAdapter(); |
259 | 260 |
|
@@ -405,14 +406,42 @@ public void testSwitchToWebViewWithMultipleWebViewsAndroid() { |
405 | 406 | }); |
406 | 407 | when(driver.getWindowHandles()).thenReturn(windowHandles); |
407 | 408 | when(driver.getTitle()).thenReturn("").thenReturn(testWebViewTitle); |
408 | | - when(contextSwitcher.getContext()).thenReturn(contextTracker.currentContext); |
| 409 | + when(contextSwitcher.getContext()) |
| 410 | + .thenReturn(contextTracker.currentContext) |
| 411 | + .thenReturn(testWebViewHandle); |
409 | 412 | mock.setMobilePlatform(Platform.LINUX); |
410 | 413 | MobileDriverAdapter adapter = mock.getMobileDriverAdapter(); |
411 | 414 | assertThat( |
412 | 415 | adapter.waitFor(() -> adapter.switchToWebView(testWebViewTitle)), is(sameInstance(driver))); |
413 | 416 | assertThat(windowHandleTracker.currentHandle, is(equalTo(testWindowHandle))); |
414 | 417 | } |
415 | 418 |
|
| 419 | + /** |
| 420 | + * Tests that the expectation to switch to no windows and not attempt to get handles when only |
| 421 | + * native context exists on Android platform, negative case |
| 422 | + */ |
| 423 | + @Test |
| 424 | + public void testSwitchToWebViewWithNoWebViewsAndroid() { |
| 425 | + ContextTracker contextTracker = new ContextTracker(); |
| 426 | + |
| 427 | + MockUtilities mock = new MockUtilities(AppiumDriver.class); |
| 428 | + AppiumDriver driver = mock.getAppiumDriverMock(); |
| 429 | + SupportsContextSwitching contextSwitcher = mock.getContextSwitcherMock(); |
| 430 | + |
| 431 | + Set<String> contextHandles = new HashSet<>(List.of(NATIVE_CONTEXT_HANDLE)); |
| 432 | + |
| 433 | + String testWebViewTitle = "Test Application"; |
| 434 | + when(driver.getCapabilities().getPlatformName()).thenReturn(Platform.ANDROID); |
| 435 | + when(contextSwitcher.getContextHandles()).thenReturn(contextHandles); |
| 436 | + when(driver.getWindowHandles()) |
| 437 | + .thenThrow(new UnsupportedCommandException("getWindowHandles {}")); |
| 438 | + when(contextSwitcher.getContext()).thenReturn(contextTracker.currentContext); |
| 439 | + mock.setMobilePlatform(Platform.LINUX); |
| 440 | + MobileDriverAdapter adapter = mock.getMobileDriverAdapter(); |
| 441 | + assertThat(adapter.switchToWebView(testWebViewTitle), nullValue()); |
| 442 | + assertThat(contextTracker.currentContext, is(equalTo(NATIVE_CONTEXT_HANDLE))); |
| 443 | + } |
| 444 | + |
416 | 445 | @Test |
417 | 446 | public void testSetPageContext() { |
418 | 447 | MockUtilities mock = new MockUtilities(AppiumDriver.class); |
|
0 commit comments