-
Notifications
You must be signed in to change notification settings - Fork 570
feat: Add support for w3c options #720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .uiautomator2.base import UiAutomator2Options |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .base import AppiumOptions |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = { | ||
| '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 {} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .xcuitest.base import XCUITestOptions |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| from .mac2.base import Mac2Options |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍