|
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 |
|
@@ -413,6 +414,35 @@ public void testSwitchToWebViewWithMultipleWebViewsAndroid() { |
413 | 414 | assertThat(windowHandleTracker.currentHandle, is(equalTo(testWindowHandle))); |
414 | 415 | } |
415 | 416 |
|
| 417 | + /** |
| 418 | + * Tests that the expectation to switch to no windows and not attempt to get handles when only |
| 419 | + * native context exists on Android platform, negative case |
| 420 | + */ |
| 421 | + @Test |
| 422 | + public void testSwitchToWebViewWithNoWebViewsAndroid() { |
| 423 | + ContextTracker contextTracker = new ContextTracker(); |
| 424 | + |
| 425 | + MockUtilities mock = new MockUtilities(AppiumDriver.class); |
| 426 | + AppiumDriver driver = mock.getAppiumDriverMock(); |
| 427 | + SupportsContextSwitching contextSwitcher = mock.getContextSwitcherMock(); |
| 428 | + |
| 429 | + Set<String> contextHandles = new HashSet<>(List.of(NATIVE_CONTEXT_HANDLE)); |
| 430 | + |
| 431 | + String testWebViewTitle = "Test Application"; |
| 432 | + when(driver.getCapabilities().getPlatformName()).thenReturn(Platform.ANDROID); |
| 433 | + when(contextSwitcher.getContextHandles()).thenReturn(contextHandles); |
| 434 | + when(driver.getWindowHandles()) |
| 435 | + .then( |
| 436 | + (arg) -> { |
| 437 | + throw new UnsupportedCommandException("getWindowHandles {}"); |
| 438 | + }); |
| 439 | + when(contextSwitcher.getContext()).thenReturn(contextTracker.currentContext); |
| 440 | + mock.setMobilePlatform(Platform.LINUX); |
| 441 | + MobileDriverAdapter adapter = mock.getMobileDriverAdapter(); |
| 442 | + assertThat(adapter.switchToWebView(testWebViewTitle), nullValue()); |
| 443 | + assertThat(contextTracker.currentContext, is(equalTo(NATIVE_CONTEXT_HANDLE))); |
| 444 | + } |
| 445 | + |
416 | 446 | @Test |
417 | 447 | public void testSetPageContext() { |
418 | 448 | MockUtilities mock = new MockUtilities(AppiumDriver.class); |
|
0 commit comments