Is there a typo in your question? I think you wrote uiautomator2
twice, but I assume you want to switch between uiautomator2
and espresso
.
So, you cannot switch the session between automation frameworks, sorry. Both Espresso and UIAutomator2 launch your app when they start a session.
You could break your script into multiple tests, where one test uses one automation style while another test uses the other.
Another option is you could use intents and deep linking to open your app to a particular point. So if your tests needs to run commands like this:
uiautomator2 command
|
v
espresso command
|
v
uiautomator2 command
|
v
espresso command
You could create deep links to each of those steps in your app. So start a driver with uiautomator2, perform some actions, then close the driver and start a new espresso session, launching with an android intent that takes you into the app at the second step. Then keep switching this way.
More information on deep linking with appium:
Also look at the appPackage
and appActivity
desired capabilities