From d7b0fff0191ba448b03f896a4dffe7e8291c2000 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 20 Jan 2023 02:20:39 -0800 Subject: [PATCH 1/5] feat: add status tentatively --- appium/webdriver/mobilecommand.py | 2 ++ appium/webdriver/webdriver.py | 19 +++++++++++++++++++ test/unit/webdriver/webelement_test.py | 14 ++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/appium/webdriver/mobilecommand.py b/appium/webdriver/mobilecommand.py index 334f4710..2a83f1a4 100644 --- a/appium/webdriver/mobilecommand.py +++ b/appium/webdriver/mobilecommand.py @@ -18,6 +18,8 @@ class MobileCommand: GET_SESSION = 'getSession' GET_ALL_SESSIONS = 'getAllSessions' + GET_STATUS = 'getStatus' + ## MJSONWP for Selenium v4 GET_LOCATION = 'getLocation' SET_LOCATION = 'setLocation' diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 00f0eaf9..098cc1e9 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -338,6 +338,23 @@ def start_session(self, capabilities: Union[Dict, AppiumOptions], browser_profil self.session_id = session_id self.caps = get_response_value('capabilities') or {} + def get_status(self) -> Dict: + """ + Find an element given a AppiumBy strategy and locator + + Args: + by: The strategy + value: The locator + + Usage: + driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='accessibility_id') + + Returns: + `appium.webdriver.webelement.WebElement`: The found element + + """ + return self.execute(Command.GET_STATUS)['value'] + def find_element(self, by: str = AppiumBy.ID, value: Union[str, Dict, None] = None) -> MobileWebElement: """ Find an element given a AppiumBy strategy and locator @@ -492,6 +509,8 @@ def _add_commands(self) -> None: # noinspection PyProtectedMember,PyUnresolvedReferences commands = self.command_executor._commands + commands[Command.GET_STATUS] = ('GET', '/status') + # FIXME: remove after a while as MJSONWP commands[Command.TOUCH_ACTION] = ('POST', '/session/$sessionId/touch/perform') commands[Command.MULTI_ACTION] = ('POST', '/session/$sessionId/touch/multi/perform') diff --git a/test/unit/webdriver/webelement_test.py b/test/unit/webdriver/webelement_test.py index 59464fd8..76f556da 100644 --- a/test/unit/webdriver/webelement_test.py +++ b/test/unit/webdriver/webelement_test.py @@ -23,6 +23,20 @@ class TestWebElement(object): + @httpretty.activate + def test_status(self): + driver = android_w3c_driver() + response = {'ready': True, 'message': {'build': {'version': '2.0.0', 'revision': None}}} + httpretty.register_uri( + httpretty.GET, + appium_command('/status'), + body=json.dumps({"value": response}), + ) + driver.get_status() + + d = get_httpretty_request_body(httpretty.last_request()) + assert d['value'] == response + @httpretty.activate def test_set_value(self): driver = android_w3c_driver() From f362ead71d4121e2f566a58aa53d3ecb2e752e8a Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 20 Jan 2023 02:29:53 -0800 Subject: [PATCH 2/5] update test --- test/unit/webdriver/webelement_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/webdriver/webelement_test.py b/test/unit/webdriver/webelement_test.py index 76f556da..0e4567e5 100644 --- a/test/unit/webdriver/webelement_test.py +++ b/test/unit/webdriver/webelement_test.py @@ -23,6 +23,7 @@ class TestWebElement(object): + @httpretty.activate def test_status(self): driver = android_w3c_driver() @@ -32,10 +33,9 @@ def test_status(self): appium_command('/status'), body=json.dumps({"value": response}), ) - driver.get_status() + s = driver.get_status() - d = get_httpretty_request_body(httpretty.last_request()) - assert d['value'] == response + assert s == response @httpretty.activate def test_set_value(self): From a7b22abf11078937a032ee50d1d18ca38ecdad61 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 20 Jan 2023 02:34:51 -0800 Subject: [PATCH 3/5] fix docstring --- appium/webdriver/webdriver.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 098cc1e9..0a64f368 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -338,19 +338,14 @@ def start_session(self, capabilities: Union[Dict, AppiumOptions], browser_profil self.session_id = session_id self.caps = get_response_value('capabilities') or {} - def get_status(self) -> Dict: + def c(self) -> Dict: """ - Find an element given a AppiumBy strategy and locator - - Args: - by: The strategy - value: The locator + Get the Appium server status Usage: - driver.find_element(by=AppiumBy.ACCESSIBILITY_ID, value='accessibility_id') - + driver.get_status() Returns: - `appium.webdriver.webelement.WebElement`: The found element + Dict: The status information """ return self.execute(Command.GET_STATUS)['value'] From df2dc8cf7943f41ea527a68033f2ef23334388b9 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 20 Jan 2023 02:39:11 -0800 Subject: [PATCH 4/5] fix typo --- appium/webdriver/webdriver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index 0a64f368..2866b9e9 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -338,7 +338,7 @@ def start_session(self, capabilities: Union[Dict, AppiumOptions], browser_profil self.session_id = session_id self.caps = get_response_value('capabilities') or {} - def c(self) -> Dict: + def get_status(self) -> Dict: """ Get the Appium server status From bfaaa045af52f4821e2dfb9e626c860c5d2628d1 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 20 Jan 2023 02:40:31 -0800 Subject: [PATCH 5/5] fix lint --- test/unit/webdriver/webelement_test.py | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/webdriver/webelement_test.py b/test/unit/webdriver/webelement_test.py index 0e4567e5..168a8ba0 100644 --- a/test/unit/webdriver/webelement_test.py +++ b/test/unit/webdriver/webelement_test.py @@ -23,7 +23,6 @@ class TestWebElement(object): - @httpretty.activate def test_status(self): driver = android_w3c_driver()