Sitelet https://github.com/appium/python-client/pull/720/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
Empty file added appium/options/__init__.py
Empty file.
1 change: 1 addition & 0 deletions appium/options/android/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .uiautomator2.base import UiAutomator2Options
Empty file.
31 changes: 31 additions & 0 deletions appium/options/android/uiautomator2/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from typing import Dict

from appium.options.common.base import AppiumOptions


class UiAutomator2Options(
AppiumOptions,
):
@property
def default_capabilities(self) -> Dict:
return {
AppiumOptions.AUTOMATION_NAME: 'UIAutomator2',
AppiumOptions.PLATFORM_NAME: 'Android',
}
1 change: 1 addition & 0 deletions appium/options/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .base import AppiumOptions
42 changes: 42 additions & 0 deletions appium/options/common/automation_name_option.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from typing import Optional

from .supports_capabilities import SupportsCapabilities


class AutomationNameOption(SupportsCapabilities):
AUTOMATION_NAME = 'automationName'

@property
def automation_name(self) -> Optional[str]:
"""
:Returns: String representing the name of the automation engine
"""
return self.get_capability(self.AUTOMATION_NAME)

@automation_name.setter
def automation_name(self, value: str) -> None:
"""
Set the automation driver to use.

:Args:
- value: One of supported automation names

"""
self.set_capability(self.AUTOMATION_NAME, value)
110 changes: 110 additions & 0 deletions appium/options/common/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

import copy
from typing import Any, Dict, TypeVar

from selenium.webdriver.common.options import BaseOptions

from .automation_name_option import AutomationNameOption

APPIUM_PREFIX = 'appium:'
T = TypeVar('T', bound='AppiumOptions')


class AppiumOptions(
BaseOptions,
AutomationNameOption,
):
_caps: Dict
PLATFORM_NAME = 'platformName'
W3C_CAPABILITY_NAMES = frozenset(
[
'acceptInsecureCerts',
'browserName',
'browserVersion',
PLATFORM_NAME,
'pageLoadStrategy',
'proxy',
'setWindowRect',
'timeouts',
'unhandledPromptBehavior',
]
)
_OSS_W3C_CONVERSION = {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

'acceptSslCerts': 'acceptInsecureCerts',
'version': 'browserVersion',
'platform': PLATFORM_NAME,
}

# noinspection PyMissingConstructor
def __init__(self) -> None:
self._caps = self.default_capabilities
# FIXME: https://github.com/SeleniumHQ/selenium/issues/10755
self._ignore_local_proxy = False

def set_capability(self, name: str, value: Any) -> T:
w3c_name = name if name in self.W3C_CAPABILITY_NAMES or ':' in name else f'{APPIUM_PREFIX}{name}'
if value is None:
if w3c_name in self._caps:
del self._caps[w3c_name]
else:
self._caps[w3c_name] = value
return self

def get_capability(self, name: str) -> Any:
"""Fetches capability value or None if the capability is not set"""
return self._caps[name] if name in self._caps else self._caps.get(f'{APPIUM_PREFIX}{name}')

def load_capabilities(self, caps: Dict[str, Any]) -> T:
"""Sets multiple capabilities"""
for name, value in caps.items():
self.set_capability(name, value)
return self

@staticmethod
def as_w3c(capabilities: Dict) -> Dict:
"""
Formats given capabilities to a valid W3C session request object

:param capabilities: Capabilities mapping
:return: W3C session request object
"""

def process_key(k: str) -> str:
key = AppiumOptions._OSS_W3C_CONVERSION.get(k, k)
if key in AppiumOptions.W3C_CAPABILITY_NAMES:
return key
return key if ':' in key else f'{APPIUM_PREFIX}{key}'

processed_caps = {process_key(k): v for k, v in copy.deepcopy(capabilities).items()}
return {'capabilities': {'firstMatch': [{}], 'alwaysMatch': processed_caps}}

def to_w3c(self) -> Dict:
"""
Formats the instance to a valid W3C session request object

:return: W3C session request object
"""
return self.as_w3c(self.to_capabilities())

def to_capabilities(self) -> Dict:
return copy.copy(self._caps)

@property
def default_capabilities(self) -> Dict:
return {}
30 changes: 30 additions & 0 deletions appium/options/common/supports_capabilities.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from typing import Any, TypeVar

from appium.protocols.protocol import Protocol

T = TypeVar('T')


class SupportsCapabilities(Protocol):
def set_capability(self: T, name: str, value: Any) -> T:
...

def get_capability(self: T, name: str) -> Any:
...
1 change: 1 addition & 0 deletions appium/options/ios/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .xcuitest.base import XCUITestOptions
Empty file.
31 changes: 31 additions & 0 deletions appium/options/ios/xcuitest/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from typing import Dict

from appium.options.common.base import AppiumOptions


class XCUITestOptions(
AppiumOptions,
):
@property
def default_capabilities(self) -> Dict:
return {
AppiumOptions.AUTOMATION_NAME: 'XCUITest',
AppiumOptions.PLATFORM_NAME: 'iOS',
}
1 change: 1 addition & 0 deletions appium/options/mac/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .mac2.base import Mac2Options
Empty file.
31 changes: 31 additions & 0 deletions appium/options/mac/mac2/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Licensed to the Software Freedom Conservancy (SFC) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The SFC licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

from typing import Dict

from appium.options.common.base import AppiumOptions


class Mac2Options(
AppiumOptions,
):
@property
def default_capabilities(self) -> Dict:
return {
AppiumOptions.AUTOMATION_NAME: 'Mac2',
AppiumOptions.PLATFORM_NAME: 'Mac',
}
Loading