From 4fcfa530395ca797363a0153cc93ed4447ed2009 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 20 Oct 2021 00:44:48 -0700 Subject: [PATCH 1/3] chore: cleanup non-w3c --- appium/webdriver/webdriver.py | 24 ++++++-------- appium/webdriver/webelement.py | 46 +++++++++++++-------------- test/unit/webdriver/webdriver_test.py | 2 -- 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/appium/webdriver/webdriver.py b/appium/webdriver/webdriver.py index ab5998ae5..326e1be10 100644 --- a/appium/webdriver/webdriver.py +++ b/appium/webdriver/webdriver.py @@ -23,7 +23,6 @@ from selenium.webdriver.remote.remote_connection import RemoteConnection from appium.common.logger import logger -from appium.webdriver.command_method import CommandMethod from appium.webdriver.common.mobileby import MobileBy from .appium_connection import AppiumConnection @@ -83,31 +82,31 @@ # Add appium prefix for the non-W3C capabilities -def _make_w3c_caps(caps: Dict) -> Dict[str, List[Dict[str, Any]]]: +def _make_w3c_caps(caps: Dict) -> Dict[str, Union[Dict[str, Any], List[Dict[str, Any]]]]: appium_prefix = 'appium:' caps = copy.deepcopy(caps) profile = caps.get('firefox_profile') - first_match = {} + always_match = {} if caps.get('proxy') and caps['proxy'].get('proxyType'): caps['proxy']['proxyType'] = caps['proxy']['proxyType'].lower() for k, v in caps.items(): if v and k in _OSS_W3C_CONVERSION: - first_match[_OSS_W3C_CONVERSION[k]] = v.lower() if k == 'platform' else v + always_match[_OSS_W3C_CONVERSION[k]] = v.lower() if k == 'platform' else v if k in _W3C_CAPABILITY_NAMES or _EXTENSION_CAPABILITY in k: - first_match[k] = v + always_match[k] = v else: if not k.startswith(appium_prefix): - first_match[appium_prefix + k] = v + always_match[appium_prefix + k] = v if profile: - moz_opts = first_match.get('moz:firefoxOptions', {}) + moz_opts = always_match.get('moz:firefoxOptions', {}) # If it's already present, assume the caller did that intentionally. if 'profile' not in moz_opts: # Don't mutate the original capabilities. new_opts = copy.deepcopy(moz_opts) new_opts['profile'] = profile - first_match['moz:firefoxOptions'] = new_opts - return {'firstMatch': [first_match]} + always_match['moz:firefoxOptions'] = new_opts + return {'alwaysMatch': always_match, 'firstMatch': [{}]} T = TypeVar('T', bound='WebDriver') @@ -259,7 +258,7 @@ def __init__( browser_profile: str = None, proxy: str = None, keep_alive: bool = True, - direct_connection: bool = False, + direct_connection: bool = True, extensions: List[T] = [], strict_ssl: bool = True, ): @@ -334,7 +333,7 @@ def _update_command_executor(self, keep_alive: bool) -> None: path = self.caps[direct_path] executor = f'{protocol}://{hostname}:{port}{path}' - logger.info('Updated request endpoint to %s', executor) + logger.debug('Updated request endpoint to %s', executor) # Override command executor self.command_executor = RemoteConnection(executor, keep_alive=keep_alive) self._addCommands() @@ -373,9 +372,6 @@ def start_session(self, capabilities: Dict, browser_profile: Optional[str] = Non if self.caps is None: self.caps = response.get('capabilities') - # Double check to see if we have a W3C Compliant browser - self.command_executor.w3c = True - def _merge_capabilities(self, capabilities: Dict) -> Dict[str, Any]: """Manage capabilities whether W3C format or MJSONWP format""" w3c_caps = _make_w3c_caps(capabilities) diff --git a/appium/webdriver/webelement.py b/appium/webdriver/webelement.py index c0ef235f1..9542377f2 100644 --- a/appium/webdriver/webelement.py +++ b/appium/webdriver/webelement.py @@ -95,18 +95,17 @@ def find_element(self, by: str = By.ID, value: Union[str, Dict] = None) -> T: `appium.webdriver.webelement.WebElement` """ # TODO: If we need, we should enable below converter for Web context - # if self._w3c: - # if by == By.ID: - # by = By.CSS_SELECTOR - # value = '[id="%s"]' % value - # elif by == By.TAG_NAME: - # by = By.CSS_SELECTOR - # elif by == By.CLASS_NAME: - # by = By.CSS_SELECTOR - # value = ".%s" % value - # elif by == By.NAME: - # by = By.CSS_SELECTOR - # value = '[name="%s"]' % value + # if by == By.ID: + # by = By.CSS_SELECTOR + # value = '[id="%s"]' % value + # elif by == By.TAG_NAME: + # by = By.CSS_SELECTOR + # elif by == By.CLASS_NAME: + # by = By.CSS_SELECTOR + # value = ".%s" % value + # elif by == By.NAME: + # by = By.CSS_SELECTOR + # value = '[name="%s"]' % value return self._execute(RemoteCommand.FIND_CHILD_ELEMENT, {"using": by, "value": value})['value'] @@ -128,18 +127,17 @@ def find_elements(self, by: str = By.ID, value: Union[str, Dict] = None) -> List :obj:`list` of :obj:`appium.webdriver.webelement.WebElement` """ # TODO: If we need, we should enable below converter for Web context - # if self._w3c: - # if by == By.ID: - # by = By.CSS_SELECTOR - # value = '[id="%s"]' % value - # elif by == By.TAG_NAME: - # by = By.CSS_SELECTOR - # elif by == By.CLASS_NAME: - # by = By.CSS_SELECTOR - # value = ".%s" % value - # elif by == By.NAME: - # by = By.CSS_SELECTOR - # value = '[name="%s"]' % value + # if by == By.ID: + # by = By.CSS_SELECTOR + # value = '[id="%s"]' % value + # elif by == By.TAG_NAME: + # by = By.CSS_SELECTOR + # elif by == By.CLASS_NAME: + # by = By.CSS_SELECTOR + # value = ".%s" % value + # elif by == By.NAME: + # by = By.CSS_SELECTOR + # value = '[name="%s"]' % value return self._execute(RemoteCommand.FIND_CHILD_ELEMENTS, {"using": by, "value": value})['value'] diff --git a/test/unit/webdriver/webdriver_test.py b/test/unit/webdriver/webdriver_test.py index db0281a10..6565277aa 100644 --- a/test/unit/webdriver/webdriver_test.py +++ b/test/unit/webdriver/webdriver_test.py @@ -20,7 +20,6 @@ from appium import version as appium_version from appium import webdriver -from appium.webdriver.command_method import CommandMethod from appium.webdriver.webdriver import ExtensionBase, WebDriver from test.unit.helper.test_helper import ( android_w3c_driver, @@ -61,7 +60,6 @@ def test_create_session(self): assert request_json.get('desiredCapabilities') is not None assert driver.session_id == 'session-id' - assert driver.command_executor.w3c @httpretty.activate def test_create_session_change_session_id(self): From dcfab95c40e589ef743bd96f114ee7f311c25b3c Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 20 Oct 2021 00:47:45 -0700 Subject: [PATCH 2/3] bump isort --- Pipfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index d4e0eda45..e6f416d29 100644 --- a/Pipfile +++ b/Pipfile @@ -23,6 +23,6 @@ mock = "~=4.0" pylint = "~=2.11" astroid = "~=2.7" -isort = "~=5.8" +isort = "~=5.9" mypy = "~=0.910" From 758b925490a5dc7fcb4f6cfdbb1bbd06f3c03e47 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Wed, 20 Oct 2021 00:53:08 -0700 Subject: [PATCH 3/3] bump Pipfiles --- Pipfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Pipfile b/Pipfile index e6f416d29..e1b163082 100644 --- a/Pipfile +++ b/Pipfile @@ -16,13 +16,13 @@ pytest-cov = "~=3.0" tox = "~=3.24" -httpretty = "~=1.0" +httpretty = "~=1.1" python-dateutil = "~=2.8" types-python-dateutil = "~=2.8" mock = "~=4.0" pylint = "~=2.11" -astroid = "~=2.7" +astroid = "~=2.8" isort = "~=5.9" mypy = "~=0.910"