Restart app after clicking on the back button in android devices

Hi,
I have a test case in which I have to test some scenarios related to the cancel button, so , I started my app, I did some steps and I pressed the cancel button in the android device (the app is putted to the background), this ok, but when I called my function again to start the app, the test case failed. what is the reason and how can I solve it, should I call getDriver().launchApp(); to start an activity or what ?

thanks,
salhi

after sending app into background (or closing) to start app again (valid ONLY for Android. with iOS it does not work due to limitation) add:

try{driver.runAppInBackground(1);}catch (Exception e) {}

try catch is needed due to issue that appium trying to find other activity that is needed in some cases (this is depending on your client). in all cases app will be started again and you can continue.

1 Like

thank you sir , you re genius :smiley: