1313# limitations under the License.
1414
1515import pytest
16+ from selenium .webdriver import ActionChains
17+ from selenium .webdriver .common .actions import interaction
18+ from selenium .webdriver .common .actions .action_builder import ActionBuilder
19+ from selenium .webdriver .common .actions .pointer_input import PointerInput
1620
1721from appium import webdriver
1822from appium .common .exceptions import NoSuchContextException
2327from .helper import desired_capabilities
2428
2529
26- @pytest .mark .skip (reason = 'Need to fix broken test' )
2730class TestContextSwitching (object ):
2831 def setup_method (self ) -> None :
29- caps = desired_capabilities .get_desired_capabilities ('selendroid-test-app .apk' )
32+ caps = desired_capabilities .get_desired_capabilities ('ApiDemos-debug .apk.zip ' )
3033 self .driver = webdriver .Remote (SERVER_URL_BASE , options = AppiumOptions ().load_capabilities (caps ))
3134
3235 def teardown_method (self ) -> None :
@@ -39,12 +42,11 @@ def test_contexts_list(self) -> None:
3942
4043 def test_move_to_correct_context (self ) -> None :
4144 self ._enter_webview ()
42- assert 'WEBVIEW_io.selendroid.testapp ' == self .driver .current_context
45+ assert 'WEBVIEW_io.appium.android.apis ' == self .driver .current_context
4346
4447 def test_actually_in_webview (self ) -> None :
4548 self ._enter_webview ()
46- self .driver .find_element (by = AppiumBy .CSS_SELECTOR , value = 'input[type=submit]' ).click ()
47- el = self .driver .find_element (by = AppiumBy .XPATH , value = '//h1[contains(., \' This is my way\' )]' )
49+ el = self .driver .find_element (by = AppiumBy .XPATH , value = '//a[@id="i am a link"]' )
4850 assert el is not None
4951
5052 def test_move_back_to_native_context (self ) -> None :
@@ -57,6 +59,19 @@ def test_set_invalid_context(self) -> None:
5759 self .driver .switch_to .context ('invalid name' )
5860
5961 def _enter_webview (self ) -> None :
60- btn = self .driver .find_element (by = AppiumBy .NAME , value = 'buttonStartWebviewCD ' )
62+ btn = self .driver .find_element (by = AppiumBy .ACCESSIBILITY_ID , value = 'Views ' )
6163 btn .click ()
64+ self ._scroll_to_webview ()
65+ self ._scroll_to_webview ()
66+ btn_web_view = self .driver .find_element (by = AppiumBy .ACCESSIBILITY_ID , value = 'WebView' )
67+ btn_web_view .click ()
6268 self .driver .switch_to .context ('WEBVIEW' )
69+
70+ def _scroll_to_webview (self ) -> None :
71+ actions = ActionChains (self .driver )
72+ actions .w3c_actions = ActionBuilder (self .driver , mouse = PointerInput (interaction .POINTER_TOUCH , "touch" ))
73+ actions .w3c_actions .pointer_action .move_to_location (393 , 1915 )
74+ actions .w3c_actions .pointer_action .pointer_down ()
75+ actions .w3c_actions .pointer_action .move_to_location (462 , 355 )
76+ actions .w3c_actions .pointer_action .release ()
77+ actions .perform ()
0 commit comments