Sitelet https://github.com/appium/python-client/pull/646/files
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
isort = "~=5.8"
astroid = "~=2.8"
isort = "~=5.9"

mypy = "~=0.910"
24 changes: 10 additions & 14 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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,
):
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down
46 changes: 22 additions & 24 deletions appium/webdriver/webelement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand All @@ -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']

Expand Down
2 changes: 0 additions & 2 deletions test/unit/webdriver/webdriver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down