Skip to content
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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
23 changes: 23 additions & 0 deletions appium/webdriver/client_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# 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 AppiumClientConfg(ClientConfig):
def __init__(self, remote_server_addr: str, *args, **kwargs):
self._direct_connection = kwargs.pop('direct_connection', False)
super().__init__(remote_server_addr, *args, **kwargs)

@property
def direct_connection(self) -> bool:
return self._direct_connection
24 changes: 8 additions & 16 deletions appium/webdriver/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +31,7 @@
from appium.webdriver.common.appiumby import AppiumBy

from .appium_connection import AppiumConnection
from .client_config import AppiumClientConfg
from .errorhandler import MobileErrorHandler
from .extensions.action_helpers import ActionHelpers
from .extensions.android.activities import Activities
Expand Down Expand Up @@ -205,24 +205,16 @@ class WebDriver(
def __init__( # noqa: PLR0913
self,
command_executor: Union[str, AppiumConnection] = 'http://127.0.0.1:4444/wd/hub',
keep_alive: bool = True,
direct_connection: bool = True,
extensions: Optional[List['WebDriver']] = None,
strict_ssl: bool = True,
options: Union[AppiumOptions, List[AppiumOptions], None] = None,
client_config: Optional[ClientConfig] = None,
client_config: Optional[AppiumClientConfg] = None,
):
if client_config is None:
# TODO: when command_executor is not string
client_config = AppiumClientConfg(remote_server_addr=command_executor)

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(remote_server_addr=command_executor, 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,
Expand All @@ -237,8 +229,8 @@ def __init__( # noqa: PLR0913

self.error_handler = MobileErrorHandler()

if direct_connection:
self._update_command_executor(keep_alive=keep_alive)
if 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
Expand Down
15 changes: 7 additions & 8 deletions test/unit/webdriver/webdriver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from appium import webdriver
from appium.options.android import UiAutomator2Options
from appium.webdriver.appium_connection import AppiumConnection
from appium.webdriver.client_config import AppiumClientConfg
from appium.webdriver.webdriver import ExtensionBase, WebDriver
from test.helpers.constants import SERVER_URL_BASE
from test.unit.helper.test_helper import (
Expand Down Expand Up @@ -124,10 +125,11 @@ def test_create_session_register_uridirect(self):
'app': 'path/to/app',
'automationName': 'UIAutomator2',
}
client_config = AppiumClientConfg(remote_server_addr=SERVER_URL_BASE, direct_connection=True)
driver = webdriver.Remote(
SERVER_URL_BASE,
options=UiAutomator2Options().load_capabilities(desired_caps),
direct_connection=True,
client_config=client_config,
)

assert 'http://localhost2:4800/special/path/wd/hub' == driver.command_executor._client_config.remote_server_addr
Expand Down Expand Up @@ -164,10 +166,9 @@ def test_create_session_register_uridirect_no_direct_connect_path(self):
'app': 'path/to/app',
'automationName': 'UIAutomator2',
}
client_config = AppiumClientConfg(remote_server_addr=SERVER_URL_BASE, direct_connection=True)
driver = webdriver.Remote(
SERVER_URL_BASE,
options=UiAutomator2Options().load_capabilities(desired_caps),
direct_connection=True,
SERVER_URL_BASE, options=UiAutomator2Options().load_capabilities(desired_caps), client_config=client_config
)

assert SERVER_URL_BASE == driver.command_executor._client_config.remote_server_addr
Expand Down Expand Up @@ -382,19 +383,17 @@ def test_extention_command_check(self):


class SubWebDriver(WebDriver):
def __init__(self, command_executor, direct_connection=False, options=None):
def __init__(self, command_executor, options=None):
super().__init__(
command_executor=command_executor,
direct_connection=direct_connection,
options=options,
)


class SubSubWebDriver(SubWebDriver):
def __init__(self, command_executor, direct_connection=False, options=None):
def __init__(self, command_executor, options=None):
super().__init__(
command_executor=command_executor,
direct_connection=direct_connection,
options=options,
)

Expand Down
Loading