runAppInBackground in Appium 1.3.5

Hi everybody!
This is my problem.

I have my android app managed with Appium and java-client, working fine.
Then I launch a second app (Facebook) using the AndroidDriver.startActivity(…) method.

The problem comes when I try to switch back to the original app.
Until Appium 1.3.4 I was using the method AndroidDriver.runAppInBackground(…) successfully, but from Appium 1.3.5 it raises the following error:

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command.
(Original error: com.facebook.katana/.FacebookLoginActivity never started. Current: com.example.myapp/.MainActivity)

However, my original app is in foreground.
If I catch the error and try to continue using my app, Appium raises the following error

org.openqa.selenium.SessionNotCreatedException: A new session could not be created

This app switching was working before Appium 1.3.5, but I can’t see anything related to it in the changelog.

Is there any other workaround to switch between apps ?

Can someone please help me?
Thanks!

  1. You may start appium server again and try it once…because some times may get “a new session could not be created”…Than start new session again.
  2. We have driver.startActivity(appPackage, appActivity);
    you can give appPackage and activity of facebook or any app. So for switching to previous app, must give previous app’s package & activity there where you have left,give that appActivity (you can know it by driver.currentActivity();)…you may get it. Hope this helps you.!!!

Technical Analyst,
ZenQ pvt ltd.

Thank you bhaskar.

I had already tried to use driver.startActivity to switch back to my app, but I keep getting the error “A new session could not be created”

Start Appium again would be the best solution, but the tests are executed in an external cloud with appium already started, and I can’t neither stop it nor start it again

@orestesd … better put some wait before the statement you are getting error…or else debug your test,it may help you where exactly the server is stopped.

Appium raises the error after invoking the AndroidDriver.runAppInBackground(…) method, when the facebook app goes in background and my own app in foreground.
Appium starts sending repeatedly this command to adb: “dumpsys window windows”, and after certain time it crashes with the message I posted before

I don’t think this is related with my code, because the same test is working with previous appium versions.

I finally found the answer checking the differences between 1.3.4 and 1.3.5 tags from appium’s source code.

Appium has introduced a new server capability named ‘stopAppOnReset’ to control whether the main application is killed or not
Setting this capability to ‘false’ makes solves the problem.

check https://github.com/appium/appium/blob/v1.3.5/docs/en/writing-running-appium/caps.md for further information

diff --git a/lib/devices/android/android-common.js b/lib/devices/android/android-common.js
index a91926a..0bbc013 100644
--- a/lib/devices/android/android-common.js
+++ b/lib/devices/android/android-common.js
@@ -123,7 +123,7 @@ androidCommon.background = function (secs, cb) {
           waitActivity: activity,
           optionalIntentArguments: this.args.optionalIntentArguments,
           retry: true,
-          stopApp: false
+          stopApp: this.args.stopAppOnReset
         }, onStart);
       }.bind(this), secs * 1000);
     }.bind(this));

thanks a lot guys. i was also stucked at it :grinning: !!!

How to change it? I have only an .exe file

I am also stucked at same problem ,could you please share that line code ( capability ) .