Skip to content

feat: Add multi-display support for Android automation#729

Open
ccxj wants to merge 1 commit intoappium:masterfrom
ccxj:android-multi-display-support
Open

feat: Add multi-display support for Android automation#729
ccxj wants to merge 1 commit intoappium:masterfrom
ccxj:android-multi-display-support

Conversation

@ccxj
Copy link

@ccxj ccxj commented Nov 24, 2025

feat: Add multi-display support for Android automation

Description

This PR implements comprehensive multi-display automation capabilities for Android devices, enabling robust testing of foldable phones, external displays, and multi-screen environments.

Technical Changes

New API Endpoints

  • POST /session/:sessionId/appium/element/on_display - Find element on specific display
  • POST /session/:sessionId/appium/elements/on_display - Find multiple elements on display
  • GET /session/:sessionId/appium/device/display_info - Retrieve display information
  • GET /session/:sessionId/appium/source/on_display - Get page source from display

Core Enhancements

  • AndroidElement Interface: Added setDisplayId() method for display context tracking
  • DisplayIdResolver: New utility for display identification and validation
  • UiSelectorBuilder: Enhanced to support display-specific element queries
  • Four New Handlers: Implement multi-display automation logic

Key Benefits

  • Precision element location on specific displays
  • Complete display topology awareness
  • Support for foldable devices and external displays
  • Fully backward compatible

Testing

  • Validated on multi-display Android devices
  • Verified backward compatibility
  • Confirmed parameter validation and error handling

- Add GetDisplayInfo handler for retrieving display information
- Implement FindElementOnDisplay and FindElementsOnDisplay for display-specific element location
- Add SourceOnDisplay handler for multi-display hierarchy dumping
- Create DisplayIdResolver for display index/ID mapping and caching
- Extend UiSelectorBuilder with displayId support
- Add comprehensive error handling and API level checks
- Maintain full backward compatibility with single-display devices"
@linux-foundation-easycla
Copy link

CLA Missing ID CLA Not Signed

@KazuCocoa
Copy link
Member

I haven't dug into this implementation well yet, but what is the difference between currentDisplayId and this implementation?
You could find the description in https://github.com/appium/appium-uiautomator2-driver and search the implementation in this repository

@pinnnkman
Copy link

Hi @KazuCocoa
I would like to ask: if the interaction test of different screens, for example, when screen A has performed an operation, if the operation is performed using the currentDisplayId method, then switching to screen B needs to be re-instantiated, is it possible for us to operate a different screen after instantiating it once?

@mykola-mokhnach
Copy link
Contributor

screen B needs to be re-instantiated

could you be more specific about that?

Eventually, I agree to @KazuCocoa. There is no need to re-introduce the same functionality twice if it already exists. Consider improving/fixing the existing implementation instead.

@pinnnkman
Copy link

@mykola-mokhnach

Here's my understanding for multi-screen operations, am I doing it right?

# main screen actions
screen_a = {
....,
currentDisplayId=0,
....}
driver_a = webdriver.Remote(str(remote_url), options=screen_a, strict_ssl=strict_ssl)
driver_a.actions...

# screen B actions
screen_b = {
....,
currentDisplayId=1,
....}
driver_b = webdriver.Remote(str(remote_url), options=screen_a, strict_ssl=strict_ssl)
driver_b.actions...

@KazuCocoa
Copy link
Member

No, as the readme, currentDisplayId is under settings api. https://github.com/appium/appium-uiautomator2-driver?tab=readme-ov-file#settings-api, so a session handles multiple displaies in the session dynamically.
e.g. https://github.com/appium/python-client/blob/e59b853497ae04706137cf252bfa3b92e6a1e229/test/unit/webdriver/settings_test.py#L57

@pinnnkman
Copy link

@mykola-mokhnach got it, thank you for your solutions very much, current i already use this to do, but i mean if we can:

POST     /session/element/on_display    {display_id: 0}
POST     /session/click/on_display    {display_id: 0}
POST     /session/element/on_display    {display_id: 1}
POST     /session/click/on_display    

not:

POST     /session/element/
POST     /session/click/
POST     /session/settings/update    {display_id: 1}
POST     /session/element/
POST     /session/click/

@KazuCocoa
Copy link
Member

Could you share the appium server log with timestamp for both? I assume you might concern about the delay with the extra endpoint call - /session/settings/update. As past comment in #729 (comment), we won't add the same functionality (and keep maintaining both.) Instead, we'd like to enhance the existing method with currentDisplayId

@pinnnkman
Copy link

@KazuCocoa I'm just raise a question and you have explained it well. I have no more questions, thanks.

@ccxj
Copy link
Author

ccxj commented Dec 1, 2025

I haven't dug into this implementation well yet, but what is the difference between currentDisplayId and this implementation? You could find the description in https://github.com/appium/appium-uiautomator2-driver and search the implementation in this repository

We tested currentDisplayId on our conference hardware device in an HDMI multi-display scenario, but it only returned controls on the primary display. Therefore, we implemented a separate solution to support multi-display control and interaction.

@KazuCocoa
Copy link
Member

KazuCocoa commented Dec 1, 2025

Thank you for checking. Would it be sufficient to use a secondary display on an emulator to test out this multi-display behavior?

Screenshot 2025-11-30 at 11 52 23 PM

[update]
It looks like no. We'll need to add several error handling for the emulator case (#741)

@mykola-mokhnach
Copy link
Contributor

@ccxj I've added some more helpers to address multi-display setups testing. Please check appium/appium-uiautomator2-driver#949 and share your feedback.

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.

4 participants