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

feat: Add mobile endpoint to retrieve UIAutomator page source dump #628

Merged
merged 5 commits into from
Oct 26, 2020
Merged

feat: Add mobile endpoint to retrieve UIAutomator page source dump #628

merged 5 commits into from
Oct 26, 2020

Conversation

pr4bh4sh
Copy link
Contributor

Problem: driver.page_source doesn't return page source when AUT is not in focus.

We had an issue while working on an application flow where the test navigates outside of the AUT's context. The test performs a photo upload operation as part of the test flow. When the active app is not AUT we use driver.execute_script('mobile:uiautomator',*args) to perform the UI interactions.

When a test fails our framework attaches the screenshot and page source of the active screen. But when the active app is not AUT, espresso driver can't return the page source with driver.page_source. To overcome this we can dump the UI dom with UIDevice.

Problem with the current implementation:

  1. UI dump returned by this PR's change is not ready to be consumed by the Appium Inspector.
  2. I'm unsure whether this is the most suitable approach.

I don't expect this PR change's to be merged, this is just what works for me now. Perhaps @mykola-mokhnach or @KazuCocoa can suggest a more refined solution for this.

@mykola-mokhnach
Copy link
Contributor

Why not to create another mobile command to get the uia page source? I don't think this is a good idea to mix Espresso's and uia2 output under the same endpoint

var dumpXml = ""
var dumpView: File? = null

try {
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

Copy link
Contributor

@mykola-mokhnach mykola-mokhnach Oct 26, 2020

Choose a reason for hiding this comment

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

This method could be simplified as

override fun handleInternal(params: AppiumParams): String = try {
    val stream = ByteArrayOutputStream()
    InteractionHelper.getUiDevice().dumpWindowHierarchy(stream)
    String(stream.toByteArray())
} catch (e: IOException) {
    throw AppiumException("Could not get page source with UiAutomator", e)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@mykola-mokhnach mykola-mokhnach changed the title [WIP][Proposal] Use UIAutomator dump when AUT is not in focus [WIP][Proposal] feat: Use UIAutomator dump when AUT is not in focus Oct 26, 2020
@mykola-mokhnach mykola-mokhnach changed the title [WIP][Proposal] feat: Use UIAutomator dump when AUT is not in focus feat: Use UIAutomator dump when AUT is not in focus Oct 26, 2020
@mykola-mokhnach mykola-mokhnach changed the title feat: Use UIAutomator dump when AUT is not in focus feat: Add mobile endpoint to retrieve UIAutomator page source dump Oct 26, 2020
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.

2 participants