SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
29.77k stars 8.02k forks source link

[🐛 Bug]: Cannot start mobile application with appium when slot also specifies a 'browserName' capability #14216

Open bhecquet opened 2 days ago

bhecquet commented 2 days ago

What happened?

Hello,

I've set up a selenium grid with an appium server which is linked to grid through relay feature

the android device stereotype is:

{
"stereotype": {
              "appium:deviceName": "sdk_gphone64_x86_64",
              "appium:platformVersion": "14",
              "browserName": "chrome",
              "platformName": "ANDROID",
            }
}

When I want to test a mobile application, I provide the following capabilities

{
    "platformName": "ANDROID",
    "appium:appActivity": "com.company.AuthenticationActivity",
    "appium:chromedriverExecutable": "D:/drivers/chromedriver_113.0_chrome-113-114.exe",
    "appium:fullReset": true,
    "appium:automationName": "UIAutomator2",
    "appium:deviceName": "sdk_gphone64_x86_64",
    "appium:newCommandTimeout": 120,
    "appium:platformVersion": "14",
    "appium:app": "http://127.0.0.1:44454/app_2024_06_27.apk",
    "appium:udid": "emulator-5554"
}

But, the received capabilities on appium side are:

{
    "platformName": "ANDROID",
    "browserName": "chrome",
    "appium:appActivity": "com.company.AuthenticationActivity",
    "appium:chromedriverExecutable": "D:/drivers/chromedriver_113.0_chrome-113-114.exe",
    "appium:fullReset": true,
    "appium:automationName": "UIAutomator2",
    "appium:deviceName": "sdk_gphone64_x86_64",
    "appium:newCommandTimeout": 120,
    "appium:platformVersion": "14",
    "appium:app": "http://127.0.0.1:44454/app_2024_06_27.apk",
    "appium:udid": "emulator-5554"
}

This is due to https://github.com/SeleniumHQ/selenium/blob/54941080765f976b88da7f273f1647b2d98aaf70/java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java#L149

which merges stereotypes from slot (where 'browserName' is present) and requested capabilities (where 'appium:app' is present) According to UIAutomator2 driver, Do not provide both app and browserName capabilities at once.

This change has been introduced with this commit: https://github.com/SeleniumHQ/selenium/commit/0013140fd587310ad38cffef9150bd8fc96b89ed

I think one of the solution would be to make de "merge" operation more precise (e.g: not adding browserName if appium:app is provided). This would add some specific code whereas relay session is generic, but it's a common use case If you have any other idea, I would be glad to implement a correction

Bertrand

How can we reproduce the issue?

See details above

Relevant log output

Appium logs:

2024-07-01 07:52:05:854 [38;5;-154m[AndroidUiautomator2Driver@5a4c] Creating session with W3C capabilities: {
  "alwaysMatch": {
    "browserName": "chrome",
    "goog:chromeOptions": {},
    "platformName": "ANDROID",
    "appium:appActivity": "com.company.AuthenticationActivity",
    "appium:chromedriverExecutable": "D:/drivers/chromedriver_113.0_chrome-113-114.exe",
    "appium:fullReset": true,
    "appium:automationName": "UIAutomator2",
    "appium:deviceName": "sdk_gphone64_x86_64",
    "appium:newCommandTimeout": 120,
    "appium:platformVersion": "14",
    "appium:app": "http://10.200.71.24:44454/grid/admin/FileServlet?file=file:upload/app/d40777c0-c046-4dc0-8cc6-f7b419cfd3b6/app_2024_06_27.apk",
    "appium:udid": "emulator-5554"
  },
  "firstMatch": [
    {}
  ]
}
2024-07-01 07:52:05:862 [38;5;-154m[AndroidUiautomator2Driver@5a4c] The following provided capabilities were not recognized by this driver:
2024-07-01 07:52:05:863 [38;5;-154m[AndroidUiautomator2Driver@5a4c]   goog:chromeOptions
2024-07-01 07:52:05:864 [38;5;-154m[AndroidUiautomator2Driver@5a4c] The desired capabilities should generally not include both an 'app' and a 'browserName'

Operating System

Any

Selenium version

4.18.1

What are the browser(s) and version(s) where you see this issue?

Chrome / not related to browser

What are the browser driver(s) and version(s) where you see this issue?

not related to browser

Are you using Selenium Grid?

4.18.1

github-actions[bot] commented 2 days ago

@bhecquet, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

diemol commented 2 days ago

Good catch. Would you like to send a PR to fix this?

bhecquet commented 2 days ago

Yes sûre If you agree, I will just remove browserName cap in case appium:app is present, hoping there is no other incompatibility

diemol commented 1 day ago

That approach sounds good.