Skip to content

feat: define AppiumClientConfig #1070

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 31 commits into from
Mar 21, 2025
Merged

feat: define AppiumClientConfig #1070

merged 31 commits into from
Mar 21, 2025

Conversation

KazuCocoa
Copy link
Member

@KazuCocoa KazuCocoa commented Nov 28, 2024

BREAKING CHANGE: Some of WebDriver.Remote constructor arguments were moved to AppiumClientConfig:

  • direct_connection
  • keep_alive
  • strict_ssl

https://github.com/SeleniumHQ/selenium/blob/trunk/py/selenium/webdriver/remote/client_config.py

@testerxiaodong
Copy link
Contributor

When will this PR be merged?

options: Union[AppiumOptions, List[AppiumOptions], None] = None,
client_config: Optional[ClientConfig] = None,
client_config: Optional[AppiumClientConfig] = None,
):
if isinstance(command_executor, str):
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

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

super class init would be the very first call there?

Actually we could by modifying here like below:

    def __init__(
        self,
        command_executor: AppiumConnection,
        client_config: AppiumClientConfig,
        extensions: Optional[List['WebDriver']] = None,
        file_detector: Optional[FileDetector] = None,
        options: Union[AppiumOptions, List[AppiumOptions], None] = None,
    ):

Then, a new method will help to build client_config and command_executor.

To avoid handling string of command_executor in selenium, which uses ClientConfig, I have added these lines to keep using AppiumClientConfig as appium python client for such a string case (to keep providing similar syntax to webdriver.Remote for selenium and appium)

@KazuCocoa KazuCocoa changed the title [wip]: define AppiumClientConfig feat: define AppiumClientConfig Mar 10, 2025
@KazuCocoa KazuCocoa marked this pull request as ready for review March 12, 2025 07:12
@KazuCocoa KazuCocoa requested a review from Copilot March 16, 2025 23:39
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces the new AppiumClientConfig to centralize client configuration while deprecating legacy direct connection arguments, which is a breaking change. Key changes include:

  • New file appium/webdriver/client_config.py defining the AppiumClientConfig.
  • Updates in tests and migration documentation to use the new client_config parameter.
  • Modifications in WebDriver initialization to integrate AppiumClientConfig for command executor creation.

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
appium/webdriver/client_config.py Introduces the new AppiumClientConfig class.
test/unit/webdriver/webdriver_test.py Updates tests to use client_config instead of direct_connection.
README.md Provides migration guide and updates examples for new config usage.
appium/webdriver/webdriver.py Updates WebDriver and connection logic to integrate AppiumClientConfig.
Comments suppressed due to low confidence (1)

appium/webdriver/client_config.py:28

  • Consider rephrasing 'If enables' to 'If enabled' for grammatical correctness in the argument description.
            direct_connection: If enables [directConnect](https://github.com/appium/python-client?tab=readme-ov-file#direct-connect-urls) feature.

SERVER_URL_BASE = 'http://127.0.0.1:4723'
# before
driver = webdriver.Remote(
SERVER_URL_BASE,
Copy link
Contributor

Choose a reason for hiding this comment

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

I would still prefer to keep the url positional argument
I believe most of the clients have the remote client arguments defined as (url, options), so this change would require all of them to change the code, which is a major inconvenience.

Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good.

The ClinetConfig requires remote_server_addr https://github.com/SeleniumHQ/selenium/blob/dbf3daef5519b0a35a8408510854ec7766455c66/py/selenium/webdriver/remote/client_config.py#L80C9-L80C27 so current example is to reduce adding remote_server_addr to both, but actually current one will confuse users.

I'll add this.

@@ -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]
Copy link
Contributor

Choose a reason for hiding this comment

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

should the optional value be assigned to None by default?

Copy link
Member Author

Choose a reason for hiding this comment

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

Either is fine. Just wanted to let the caller explicitly set both

@KazuCocoa KazuCocoa requested a review from Copilot March 18, 2025 05:30
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

README.md Outdated
@@ -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`:
Copy link
Contributor

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 ...

README.md Outdated
@@ -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:
Copy link
Contributor

Choose a reason for hiding this comment

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

typo arguemnt

Copy link
Contributor

Choose a reason for hiding this comment

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

as below -> similar to how it is specified below

README.md Outdated
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`
Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Mar 19, 2025

Choose a reason for hiding this comment

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

Then, the ... -> In such case the remote_server_addr argument of AppiumClientConfig constructor would have priority over the url argument of webdriver.Remote constructor

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)
Copy link
Contributor

Choose a reason for hiding this comment

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

would it be possible to do the same without reassigning method arguments?

@KazuCocoa KazuCocoa merged commit 525d5b8 into master Mar 21, 2025
11 checks passed
@KazuCocoa KazuCocoa deleted the use-client-config branch March 21, 2025 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants