-
Notifications
You must be signed in to change notification settings - Fork 567
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
feat: define AppiumClientConfig #1070
base: master
Are you sure you want to change the base?
Changes from all commits
27cb0ca
7823cd7
ce1f243
d31812d
c658460
09e0c59
dd19cff
3c1c02f
0fbbb8e
69f086e
bf0c96a
2aabd72
9569035
2bdbea8
b7fdaa4
d52e243
b06ed8e
671aa78
64a6553
2b19e2e
9262c78
f56de0d
2a33f0d
299f283
5bf6cc6
72b2e42
8139b41
7fc6113
25b5af0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,36 @@ For example, some changes in the Selenium binding could break the Appium client. | |
> to keep compatible version combinations. | ||
|
||
|
||
### Quick migration guide from v4 to v5 | ||
- This change affecs only for a user who speficies `keep_alive`, `direct_connection` and `strict_ssl` arguments for `webdriver.Remote`: | ||
- Please use `AppiumClientConfig` as `client_config` arguemnt as below: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo arguemnt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as below -> similar to how it is specified below |
||
```python | ||
SERVER_URL_BASE = 'http://127.0.0.1:4723' | ||
# before | ||
driver = webdriver.Remote( | ||
SERVER_URL_BASE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would still prefer to keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. upd: I can observe the below code supports such feature, so we just need to mention that in documents There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good. The ClinetConfig requires I'll add this. |
||
options=UiAutomator2Options().load_capabilities(desired_caps), | ||
direct_connection=True, | ||
keep_alive=False, | ||
strict_ssl=False | ||
) | ||
|
||
# after | ||
from appium.webdriver.client_config import AppiumClientConfig | ||
client_config = AppiumClientConfig( | ||
remote_server_addr=SERVER_URL_BASE, | ||
direct_connection=True, | ||
keep_alive=False, | ||
ignore_certificates=True, | ||
) | ||
driver = webdriver.Remote( | ||
options=UiAutomator2Options().load_capabilities(desired_caps), | ||
client_config=client_config | ||
) | ||
``` | ||
- Note that you can keep using `webdriver.Remote(url, options=options, client_config=client_config)` format as well. Then, the `remote_server_addr` in `AppiumClientConfig` will prior than the `url` specified via `webdriver.Remote` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then, the ... -> In such case the |
||
- Use `http://127.0.0.1:4723` as the default server url instead of `http://127.0.0.1:4444/wd/hub` | ||
|
||
### Quick migration guide from v3 to v4 | ||
- Removal | ||
- `MultiAction` and `TouchAction` are removed. Please use W3C WebDriver actions or `mobile:` extensions | ||
|
@@ -274,6 +304,7 @@ from appium import webdriver | |
# If you use an older client then switch to desired_capabilities | ||
# instead: https://github.com/appium/python-client/pull/720 | ||
from appium.options.ios import XCUITestOptions | ||
from appium.webdriver.client_config import AppiumClientConfig | ||
|
||
# load_capabilities API could be used to | ||
# load options mapping stored in a dictionary | ||
|
@@ -283,11 +314,16 @@ options = XCUITestOptions().load_capabilities({ | |
'app': '/full/path/to/app/UICatalog.app.zip', | ||
}) | ||
|
||
client_config = AppiumClientConfig( | ||
remote_server_addr='http://127.0.0.1:4723', | ||
direct_connection=True | ||
) | ||
|
||
driver = webdriver.Remote( | ||
# Appium1 points to http://127.0.0.1:4723/wd/hub by default | ||
'http://127.0.0.1:4723', | ||
options=options, | ||
direct_connection=True | ||
client_config=client_config | ||
) | ||
``` | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Licensed 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 selenium.webdriver.remote.client_config import ClientConfig | ||
|
||
|
||
class AppiumClientConfig(ClientConfig): | ||
"""ClientConfig class for Appium Python client. | ||
This class inherits selenium.webdriver.remote.client_config.ClientConfig. | ||
""" | ||
|
||
def __init__(self, remote_server_addr: str, *args, **kwargs): | ||
""" | ||
Please refer to selenium.webdriver.remote.client_config.ClientConfig documentation | ||
about available arguments. Only 'direct_connection' below is AppiumClientConfig | ||
specific argument. | ||
|
||
Args: | ||
direct_connection: If enables [directConnect](https://github.com/appium/python-client?tab=readme-ov-file#direct-connect-urls) | ||
feature. | ||
""" | ||
self._direct_connection = kwargs.pop('direct_connection', False) | ||
super().__init__(remote_server_addr, *args, **kwargs) | ||
|
||
@property | ||
def direct_connection(self) -> bool: | ||
"""Return if [directConnect](https://github.com/appium/python-client?tab=readme-ov-file#direct-connect-urls) | ||
is enabled.""" | ||
return self._direct_connection |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,6 @@ | |
WebDriverException, | ||
) | ||
from selenium.webdriver.common.by import By | ||
from selenium.webdriver.remote.client_config import ClientConfig | ||
from selenium.webdriver.remote.command import Command as RemoteCommand | ||
from selenium.webdriver.remote.remote_connection import RemoteConnection | ||
from typing_extensions import Self | ||
|
@@ -32,6 +31,7 @@ | |
from appium.webdriver.common.appiumby import AppiumBy | ||
|
||
from .appium_connection import AppiumConnection | ||
from .client_config import AppiumClientConfig | ||
from .errorhandler import MobileErrorHandler | ||
from .extensions.action_helpers import ActionHelpers | ||
from .extensions.android.activities import Activities | ||
|
@@ -174,6 +174,27 @@ def add_command(self) -> Tuple[str, str]: | |
raise NotImplementedError() | ||
|
||
|
||
def _get_remote_connection_and_client_config( | ||
command_executor: Union[str, AppiumConnection], client_config: Optional[AppiumClientConfig] = None | ||
) -> tuple[AppiumConnection, Optional[AppiumClientConfig]]: | ||
"""Return the pair of command executor and client config. | ||
If the given command executor is a custom one, returned client config will | ||
be None since the custom command executor has its own client config already. | ||
The custom command executor's one will be prior than the given client config. | ||
""" | ||
if not isinstance(command_executor, str): | ||
# client config already defined in the custom command executor | ||
# will be prior than the given one. | ||
return (command_executor, None) | ||
|
||
# command_executor is str | ||
if client_config is None: | ||
# Do not keep None to avoid warnings in Selenium | ||
# which can prevent with ClientConfig instance usage. | ||
client_config = AppiumClientConfig(remote_server_addr=command_executor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it be possible to do the same without reassigning method arguments? |
||
return (AppiumConnection(client_config=client_config), client_config) | ||
|
||
|
||
class WebDriver( | ||
webdriver.Remote, | ||
ActionHelpers, | ||
|
@@ -202,28 +223,16 @@ class WebDriver( | |
Sms, | ||
SystemBars, | ||
): | ||
def __init__( # noqa: PLR0913 | ||
def __init__( | ||
self, | ||
command_executor: Union[str, AppiumConnection] = 'http://127.0.0.1:4444/wd/hub', | ||
keep_alive: bool = True, | ||
direct_connection: bool = True, | ||
command_executor: Union[str, AppiumConnection] = 'http://127.0.0.1:4723', | ||
KazuCocoa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
extensions: Optional[List['WebDriver']] = None, | ||
strict_ssl: bool = True, | ||
options: Union[AppiumOptions, List[AppiumOptions], None] = None, | ||
client_config: Optional[ClientConfig] = None, | ||
client_config: Optional[AppiumClientConfig] = None, | ||
): | ||
if isinstance(command_executor, str): | ||
client_config = client_config or ClientConfig( | ||
remote_server_addr=command_executor, keep_alive=keep_alive, ignore_certificates=not strict_ssl | ||
) | ||
client_config.remote_server_addr = command_executor | ||
command_executor = AppiumConnection(client_config=client_config) | ||
elif isinstance(command_executor, AppiumConnection) and strict_ssl is False: | ||
logger.warning( | ||
"Please set 'ignore_certificates' in the given 'appium.webdriver.appium_connection.AppiumConnection' or " | ||
"'selenium.webdriver.remote.client_config.ClientConfig' instead. Ignoring." | ||
) | ||
|
||
command_executor, client_config = _get_remote_connection_and_client_config( | ||
command_executor=command_executor, client_config=client_config | ||
) | ||
super().__init__( | ||
command_executor=command_executor, | ||
options=options, | ||
|
@@ -232,13 +241,12 @@ def __init__( # noqa: PLR0913 | |
client_config=client_config, | ||
) | ||
|
||
if hasattr(self, 'command_executor'): | ||
self._add_commands() | ||
self._add_commands() | ||
|
||
mykola-mokhnach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self.error_handler = MobileErrorHandler() | ||
|
||
if direct_connection: | ||
self._update_command_executor(keep_alive=keep_alive) | ||
if client_config and client_config.direct_connection: | ||
self._update_command_executor(keep_alive=client_config.keep_alive) | ||
|
||
# add new method to the `find_by_*` pantheon | ||
By.IOS_PREDICATE = AppiumBy.IOS_PREDICATE | ||
|
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.
This change affects only user who specify ...