How to terminate app in IOS during test

Hello,
I have test where I need to terminate the app at the middle of the test and than because I connect through Bluetooth to hardware, the hardware starts the app again, I tried to terminate the app by using :

    driver.terminateApp('com.my.app');

but it is not terminate the app, the app still at the background (I see it when I use the device at the middle of the test),
How to terminate the app?
Thanks,

Ios 15.1
Java

I’ve seen this as well. The behavior I am seeing is that if I do ‘terminateApp’ on iOS Settings as you have, that it stops and restarts. The reason I know this is because when I open iOS Settings in the next test I’m back at the top level. When I don’t use ‘terminateApp’ it caches the last screen I had opened. I have found this useful for my testing, but I may not understand exactly what you are trying to do here. I think that when you terminate the app in such a way that iOS automatically restarts it. I’m not sure there is a way around that.

@wreed , Thank you,
I didn’t do it on the preferences, I did it on my tested app.
I didn’t fully understand your case but anyhow I need solution for terminate any other app than the prefernces :slight_smile:
Thank you

Can you terminate app manually succesfull without app re-appear?

@Aleksei,
Yes, the Hardware will restart the app again , but from the user side the app is terminated and I can do it.
The question is why the termination via appium is not working , it is strange

I looking for a way to terminate in real device through Appium, one application, I tired the

driver.terminateApp('com.my.app');

but it is not worked , I also tried to swipe from bottom of the screen to zero point to open the recent apps and close them but these didn’t worked too, so I need some help please how to terminate app.
These is the main problem

It is because https://developer.apple.com/documentation/xctest/xcuiapplication/1500637-terminate behaves so. (As an appium’s implementation)
Appium calls the termination method by Apple, so the behavior depends on how Apple implements it.

Oh… then, I guess apple does not allow to terminate the process in XCTest session…
So far, I assume uninstalling the app is the only method to kill the process completely (it also deletes the app thought)… Probably Apple has changed the behavior since some iOS/Xcode version…

@KazuCocoa, so there is no option to terminate app like the user do = scroll from down to up, see all recent apps, and than move the one he wants to terminate?
And also, does proccess like the user do, actualy close the proccess?

I tested a bit with com.apple.monbilesafari on an iOS 15.2 device.

After calling the terminate api, sometimes the app was removed from the recent apps list (double click home button), but sometimes remained. But both app state was not-running, which calls https://appium.io/docs/en/commands/device/app/app-state/index.html (calls https://developer.apple.com/documentation/xctest/xcuiapplication/2877401-state).
So, as the iOS system, the app was terminated (via XCTest), but not sure actually the app process has been killed. Then, I think yes, if we believe apple’s API. > does proccess like the user do, actualy close the proccess?

If the https://developer.apple.com/documentation/xctest/xcuiapplication/2877401-state returned wrong state, the app could keep running. Then, it should be Apple’s bug or expected behavior as XCTest framework by them.

@KazuCocoa Thank you,
I did try it too on preferences and it worked, but in other apps not of apple, it didn’t .
So I did also did on my app the same terminate command, and the state return as not runing, but actualy the app appear under the recent apps, so what does it mean? the app is still there or not? because if we look how the user do it, the app is not there anymore, and with the terminate command, the app still there…

@KazuCocoa Looks like that there is some difference between terminate app though command and terminate via what the user do with the move of the app up from the recent applications, even though that both of them at the status command show the same thing = app_not_runing, still there is difference in the communication of the application, if the application is terminated via the command, the communication (for example with bluetooth from the application) still runing and working, and if the user terminate it from the recent apps, the communication stopes, so what can be the difference?
I saw it on the IBeacon communication with the bluetooth.