appium-espresso-driver icon indicating copy to clipboard operation
appium-espresso-driver copied to clipboard

jetpack compose support

Open rajdeepv opened this issue 3 years ago • 8 comments

<< ref: https://github.com/appium/appium/issues/15138 >>

We are migrating our app to compose and plan to add composeTestRule support inside appium-espresso-driver. Before moving forward with any change, I wanted to check upon the approach so that it could be integrated into existing code seamlessly. We plan to introduce a switch between espresso and composeTestRule. we could utilize switch_context or execute_script to switch between contexts. on the espresso-server side, based on the current context of the driver, we can use either implementation. Please suggest if you have any other ideas

rajdeepv avatar Aug 09 '21 10:08 rajdeepv

context switch seems promising for such purpose, although I'm not sure it would be easy to update its current implementation without breaking many things as it was only created to switch to Chrome web views. What might be simpler is to organize context switch using settings API

mykola-mokhnach avatar Aug 09 '21 12:08 mykola-mokhnach

Haven't seen espresso using settings API, any pointer to it will be helpful. we could also do something like execute_script("mobile: switch_to_compose") or execute_script("mobile: switch_to_espresso") ?

rajdeepv avatar Aug 09 '21 14:08 rajdeepv

yes. Something like mobile: setServerContext (name: classic or compose) and mobile: getServerContext

Examples: https://github.com/appium/appium-mac2-driver/pull/28 https://github.com/appium/appium-mac2-driver/pull/30

mykola-mokhnach avatar Aug 09 '21 16:08 mykola-mokhnach

it would still be worth exploring the strategy of using the official context API. if that works sensibly, it will be a much better user experience.

jlipps avatar Aug 09 '21 18:08 jlipps

I remember I was trying to make the context stuff working with Firefox. My findings were:

  • Most of the code lives in appium-android-driver. Changing that will affect all Android drivers
  • The current implementation is very Chrome-specific. It was not developed for further extension
  • Some parts of the codebase are quite cryptic. It might take a lot of time to understand them not even talking about how to change them without breaking the existing functionality

mykola-mokhnach avatar Aug 09 '21 18:08 mykola-mokhnach

You're probably right. I was thinking of something simple like a wrapper around the existing functionality that simply adds a new context to the list and handles the case of selecting that context. Otherwise, everything is handled by just calling the existing methods.

jlipps avatar Aug 09 '21 21:08 jlipps

Its promising! Initially I thought a bit:

  • define a context like WebView/Native to be able to switch to compose
  • define a new look up like -android viewmatcher to manage an element object
    • add mobile: for new actions if needed
  • add mobile: getComposSource https://developer.android.com/jetpack/compose/testing#debugging as a workaround
    • until we add xml converter

I don't remember well, but when I dig in some compose code/appium espresso before, this espresso driver probably needed to up to dated (e.g. kotlin version(?)).

KazuCocoa avatar Aug 09 '21 22:08 KazuCocoa

Kotlin version was updated in https://github.com/appium/appium-espresso-driver/pull/663 and it worked for me with composeTestRule. My thought was to have context object having strategies for espressoAutomation and composeAutomation

rajdeepv avatar Aug 10 '21 09:08 rajdeepv