Skip to content

Commit 991d57e

Browse files
committed
fix context switch tests in unit test
1 parent 0e4f039 commit 991d57e

File tree

4 files changed

+34
-82
lines changed

4 files changed

+34
-82
lines changed

.github/workflows/functional-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
name: func_test_android3
100100
- target: test/functional/android/finger_print_tests.py test/functional/android/screen_record_tests.py test/functional/android/settings_tests.py test/functional/android/chrome_tests.py
101101
name: func_test_android4
102-
- target: test/functional/android/context_switching_tests.py test/functional/android/remote_fs_tests.py
102+
- target: test/functional/android/remote_fs_tests.py
103103
name: func_test_android5
104104
- target: test/functional/android/common_tests.py test/functional/android/webelement_tests.py
105105
name: func_test_android6

test/functional/android/context_switching_tests.py

Lines changed: 0 additions & 77 deletions
This file was deleted.

test/unit/webdriver/context_test.py

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,41 @@
1414

1515
import httpretty
1616

17-
from test.unit.helper.test_helper import android_w3c_driver, appium_command
17+
from test.unit.helper.test_helper import android_w3c_driver, appium_command, get_httpretty_request_body
1818

1919

2020
class TestWebDriverContext(object):
21+
@httpretty.activate
22+
def test_current_contexts(self):
23+
driver = android_w3c_driver()
24+
httpretty.register_uri(
25+
httpretty.GET, appium_command('/session/1234567890/context'), body='{"value": "NATIVE_APP"}'
26+
)
27+
assert driver.current_context == 'NATIVE_APP'
28+
2129
@httpretty.activate
2230
def test_get_contexts(self):
2331
driver = android_w3c_driver()
24-
httpretty.register_uri(httpretty.GET, appium_command('/session/1234567890/context'), body='{"value": "NATIVE"}')
25-
assert driver.current_context == 'NATIVE'
32+
httpretty.register_uri(
33+
httpretty.GET, appium_command('/session/1234567890/contexts'), body='{"value": ["NATIVE_APP", "CHROMIUM"]}'
34+
)
35+
36+
assert ['NATIVE_APP', 'CHROMIUM'] == driver.contexts
37+
38+
@httpretty.activate
39+
def test_switch_to_context(self):
40+
driver = android_w3c_driver()
41+
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/context'), body='{"value": null}')
42+
43+
driver.switch_to.context(None)
44+
45+
assert {'name': None}, get_httpretty_request_body(httpretty.last_request())
46+
47+
@httpretty.activate
48+
def test_switch_to_context_native_app(self):
49+
driver = android_w3c_driver()
50+
httpretty.register_uri(httpretty.POST, appium_command('/session/1234567890/context'), body='{"value": null}')
51+
52+
driver.switch_to.context('NATIVE_APP')
53+
54+
assert {'name': 'NATIVE_APP'}, get_httpretty_request_body(httpretty.last_request())

test/unit/webdriver/webdriver_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def test_extention_command_check(self):
384384
assert {
385385
'args': [{'component': 'io.appium.android.apis/.accessibility.AccessibilityNodeProviderActivity'}],
386386
'script': 'mobile: startActivity',
387-
}, get_httpretty_request_body(httpretty.last_request())
387+
} == get_httpretty_request_body(httpretty.last_request())
388388

389389

390390
class SubWebDriver(WebDriver):

0 commit comments

Comments
 (0)