Mobile Testing Appium

org.openqa.selenium.InvalidElementStateException: An element command could not be completed because the element is in an invalid state. Selenium error: The application under test with bundleid****** is not running, possible crashed.
What capability to be added to relaunch mobile application(ios) after resetting app i.e., (changing environment in settings) in single appium session.

// iOS
appID = String.valueOf(driver.getCapabilities().getCapability(IOSMobileCapabilityType.BUNDLE_ID));
((IOSDriver) driver).terminateApp(appID);
((IOSDriver) driver).launchApp(); // new: driver.execute(MobileCommand.LAUNCH_APP);

// Android
appID = (String) driver.getCapabilities().getCapability(AndroidMobileCapabilityType.APP_PACKAGE);
((AndroidDriver) driver).terminateApp(appID);
((AndroidDriver) driver).launchApp(); // new driver.execute(MobileCommand.LAUNCH_APP);

“terminateApp”: “true”,
“launchApp”: “true”

I added above capabilities, but same error is repeated.
Please help me out with this.

I wrote not capabilities but commands that do app restart without need to close driver.

By default appium driver does app restart on open.
Read more logs. Your short logs does not clear problem. Set appium logs to debug. Read logs before and after problem.

In your logs it looks like app not running at all.

Yes for changing environment of the application, I need to reset the app in settings, after resetting it need to change the environment of the app->close the app-> and again relaunch the app with changed environment.
But while doing the change itself I am getting the above error that the application is not running, possibly crashed.

so what exact steps? e.g.:

  1. in app settings in code navigate to menu and change environment
  2. app does restart itself?

While inspecting app in Appium Inspector
In app settings-> click on new environment-> resett app warning popup is displayed->on clicking reset app -> the resett should happen->It should close the app ->iphone simulator is displayed with app-> again I should click on app and go to app settings to check whether the change is replicated or not…these all should take place in single appium session.
While clicking on reset app itself I am getting that error.

oiiiii. stop using Appium Inspector for anything accept inspection and simple tap/clicks… It just for simple things.

So it is not possible to avoid getting that error

using appium server you should not meet this after app restart.

Using appium server with ios simulator through browserstack
I am getting issue before restarting app i.e., while clicking on the reset app.
Please can you give me idea what is the reason for such type of error.

Not use it helps, but… Does appium not restart the simulator “instance” itself? I don’t use the simulator at all, but the simulator starts clean each time does it not?