|
24 | 24 | class TestSafari:
|
25 | 25 | def setup_method(self) -> None:
|
26 | 26 | caps = get_desired_capabilities()
|
27 |
| - caps.update({'browserName': 'safari', 'nativeWebTap': True, 'safariIgnoreFraudWarning': True}) |
| 27 | + caps.update( |
| 28 | + { |
| 29 | + 'bundleId': 'com.apple.mobilesafari', |
| 30 | + 'nativeWebTap': True, |
| 31 | + 'safariIgnoreFraudWarning': True, |
| 32 | + 'webviewConnectTimeout': 100000, |
| 33 | + } |
| 34 | + ) |
28 | 35 | self.driver = webdriver.Remote(SERVER_URL_BASE, options=AppiumOptions().load_capabilities(caps))
|
29 | 36 |
|
| 37 | + # Fresh iOS 17.4 simulator may not show up the webview context with "safari" |
| 38 | + # after a fresh simlator instance creation. |
| 39 | + # Re-launch the process could be a workaround in my debugging. |
| 40 | + self.driver.terminate_app('com.apple.mobilesafari') |
| 41 | + self.driver.activate_app('com.apple.mobilesafari') |
| 42 | + |
30 | 43 | def teardown_method(self) -> None:
|
31 | 44 | self.driver.quit()
|
32 | 45 |
|
33 | 46 | def test_context(self) -> None:
|
34 |
| - assert 'NATIVE_APP' == self.driver.contexts[0] |
35 |
| - assert self.driver.contexts[1].startswith('WEBVIEW_') |
| 47 | + contexts = self.driver.contexts |
| 48 | + assert 'NATIVE_APP' == contexts[0] |
| 49 | + assert contexts[1].startswith('WEBVIEW_') |
| 50 | + self.driver.switch_to.context(contexts[1]) |
36 | 51 | assert 'WEBVIEW_' in self.driver.current_context
|
37 | 52 |
|
38 | 53 | def test_get(self) -> None:
|
| 54 | + ok = False |
| 55 | + contexts = self.driver.contexts |
| 56 | + for context in contexts: |
| 57 | + if context.startswith('WEBVIEW_'): |
| 58 | + self.driver.switch_to.context(context) |
| 59 | + ok = True |
| 60 | + break |
| 61 | + |
| 62 | + if ok is False: |
| 63 | + assert False, 'Could not set WEBVIEW context' |
| 64 | + |
39 | 65 | self.driver.get('http://google.com')
|
40 | 66 | for _ in range(5):
|
41 | 67 | time.sleep(0.5)
|
|
0 commit comments