-
Notifications
You must be signed in to change notification settings - Fork 568
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
[wip]: 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
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 |
---|---|---|
@@ -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,8 +22,8 @@ | |
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.file_detector import FileDetector | ||
from selenium.webdriver.remote.remote_connection import RemoteConnection | ||
from typing_extensions import Self | ||
|
||
|
@@ -32,6 +32,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 | ||
|
@@ -204,28 +205,21 @@ class WebDriver( | |
): | ||
def __init__( # noqa: PLR0913 | ||
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. does it still complain about too many arguments after this change? |
||
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', | ||
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. this is also a breaking change |
||
extensions: Optional[List['WebDriver']] = None, | ||
strict_ssl: bool = True, | ||
file_detector: Optional[FileDetector] = None, | ||
options: Union[AppiumOptions, List[AppiumOptions], None] = None, | ||
client_config: Optional[ClientConfig] = None, | ||
client_config: Optional[AppiumClientConfig] = None, | ||
): | ||
if isinstance(command_executor, str): | ||
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 extract this logic into a separate method, so super class init would be the very first call there? 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.
Actually we could by modifying here like below:
Then, a new method will help to build client_config and command_executor. To avoid handling string of |
||
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 | ||
if client_config is None: | ||
client_config = AppiumClientConfig(remote_server_addr=command_executor) | ||
# To prevent generating RemoteConnection in selenium | ||
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." | ||
) | ||
|
||
super().__init__( | ||
command_executor=command_executor, | ||
file_detector=file_detector, | ||
options=options, | ||
locator_converter=AppiumLocatorConverter(), | ||
web_element_cls=MobileWebElement, | ||
|
@@ -237,8 +231,8 @@ def __init__( # noqa: PLR0913 | |
|
||
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.
typo
argument