1

I'm using serenity with appium (v2.3.12)

My scenario require to switch app from native to open chrome and validate a form to create new account then go back in native and try to login.

I use the classic way of serenity.properties to instantiate the appiumDriver and automate the app with UIAutomator2. When I need to switch in chrome I use a new AppiumDriver with the same url and new capabilities like this :

DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("automationName", "UIAutomator2");
    capabilities.setCapability("browserName", "Chrome");
    capabilities.setCapability("UDID", udid);
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", "emulator-5554");
    capabilities.setCapability("platformVersion", "11.0");
    AppiumDriver newDriver = new AndroidDriver(new URL(url), capabilities);

Chrome launch well and I can perform my action.

But the problem is here : when I wan't to switch back.

I tried many ways but none working so far:

First try was to call back my app with :

((AndroidDriver)((WebDriverFacade) getDriver()).getProxiedDriver()).launchApp();

or

((AndroidDriver)((WebDriverFacade) getDriver()).getProxiedDriver()).resetApp();

Native app launch but the driver is not able to find any elements and when I tried to getPageSource :

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy error: 'GET /wd/hub/session/f2dd1d65-351f-4845-b321-298e41b7df4d/source' cannot be proxied to UiAutomator2 server because the instrumentation process is not running (probably crashed). Check the server log and/or the logcat output for more details

Second try : Do a .quit() the first appiumDriver before using the second but when I do a .launchApp() after chrome actions I got this :

org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?

I also try to use two different appium server for each appiumDriver.


Maybe the solution is to relaunch the serenity appiumDriver after quiting and performing action in chrome because I tried to launch a third appiumDriver and it's works well and find elements in native app but it didn't worked with the PageObject from serenity and I don't know how to quit and relaunch the appiumDriver from serenity in a test.


The same process works fine on iOS, when I switch back on app elements are found correctly. Maybe the problem is the way serenity handle UIAutomator2 ?

Jannette
  • 19
  • 1
  • 4

1 Answers1

1

I suggest a way to workaround. Try to not create the Chrome driver. When you wanna leave app(main app) to open Chrome, just click on Android Home(or Back) button to go back to the Home Screen. Then click on Chrome icon and check if you can continue to interact with it or not. If yes, then just keep using Chrome until wanna back to app. Use:

driver.launchApp()

or

driver.activateApp(variables.getProperty("appium.appPackage")); //Android 
driver.activateApp(variables.getProperty("appium.bundleId")); //iOS 

For Exceptions you met, I think it comes from the way you manage the multiple drivers. Your main app driver session seems call quit() unexpectedly when you switch to Chrome driver. I'm not sure how your code structure is. But if you don't wanna fix it by workaround way above, manage your drivers carefully could be a fine approach.

More information about SessionNotFoundException here

Huy Hóm Hỉnh
  • 597
  • 7
  • 18
  • 1
    Thanks for your workaround, it worked, even xpath are not exactly the same as we used a chrome WebDriver but I can make chrome do action I want to pass my test. Just need little changes from the safari/ios stepdef version. Thanks (I voted but my reputation is not high enough to be displayed) – Jannette Mar 22 '21 at 15:53