[iOS] The previous screen remains after Close application

Mobile.closeApplication() does not work correctoly with iOS.
After executing the command, the previous screen remains and the test does not work properly.

And the driver.resetApp() solution didn’t work because it also reset some of my app settings.

I saw the similer topic, but I use Mobile.startApplication, not Mobile.startExistingApplication

It works with Android emulator, but not works with iOS.

Is there any solution?


Katalon Studio : 8.4.0
OS : macOS Monterey
Mobile : iOS
Xcode: 13.4.1

@rie.ota, can you provide some video when executing the process?

@chen.lee
I attach the video.

I run the code as follows. The test is expected to fail after the CloseApplidcation in the middle, but passes because the screen continues to remain.

Mobile.startApplication('App/Coffee Timer.app', false)
Mobile.verifyElementText(findTestObject('Spy/XCUIElementTypeStaticText - Mexican'), 'Mexican')
Mobile.tap(findTestObject('XCUIElementTypeStaticText - Mexican'), 0)
Mobile.delay(5)

Mobile.closeApplication()

Mobile.delay(5)
Mobile.startApplication('App/Coffee Timer.app', false)
Mobile.tap(findTestObject('XCUIElementTypeButton - Start'), 0)
Mobile.tap(findTestObject('XCUIElementTypeStaticText - 319'), 0)
Mobile.tap(findTestObject('XCUIElementTypeButton - Stop'), 0)
Mobile.tap(findTestObject('XCUIElementTypeButton - Back'), 0)
Mobile.closeApplication()

@rie.ota

Have you ever tried with below command for IOS:

driver.terminateApp(‘com.apple.Preferences’) //change to your id
driver.resetApp()
driver.quit()

I see that it works from my side.

@loc.nguyen Thank you for the solution! But as I mentioned in the top comment, my app does not work well with driver.resetApp() since it seems to reset too much…

@rie.ota , beside the resetApp, we have other one driver.terminateApp(‘com.apple.Preferences’)

I guess that you need to put below code to close the application:

driver.terminateApp(‘com.apple.Preferences’) //change to your id
driver.resetApp()
driver.quit()

Please help to let me know after inputting 3 line code together but still cannot close the app

1 Like

Ah sorry, I missed that one line! It’s worth a try. I will let you know the results.

We just tested on the iphone 11 simulator and the closeApplication() closes the app successfully. From the video, it looks like you are using an iPad simulator, can you tell us which model is it in the video?

1 Like

@chen.lee
In the video, I use iPad mini (6th gen).
The same behavior occurred on iPhone SE (3rd, 2nd). (Both are simulators)

@loc.nguyen
hmm, sorry but the following code can close the app but also reset some of my app settings…
Same as the first comment.
If the simulator is manually operated and task-killed, the settings are not reset.

driver.terminateApp(‘com.apple.Preferences’) //change to your id
driver.resetApp()
driver.quit()

@rie.ota As I read your first comment, the application is still keeping when you want to close it. For now, we are able to close it. Correct? Could you please help to let me know more information: From your side, you expected that after closing, system resets some configuration to default (current behavior) and you want to keep the configuration? It is right?

@loc.nguyen
Sorry for the confusion.

The first problem is that closeApplication does not work well and the screen remains as shown in the video.

To solve this, I want to task kill the application.
However, I would like to keep the authentication information and app settings.

driver.terminateApp(‘com.apple.Preferences’) //change to your id
driver.resetApp()
driver.quit()

The above code can close the app, but seems to reset some of my app settings together for some reason.

Hi @rie.ota ,

Here is the link of Appium about above method: Terminate App - Appium Not sure it support your case.
But I think that if you want to close the application without reset some configuration you can create your own script to close:

  • Enable iphone assistive touch
  • Using Katalon to click/double click on the touch assistive
  • Swipe to close the application

We reproduced your execution and since you put startApplication() after the closeApplication(), the app will still continue because there is a default boolean value for uninstallAfterCloseApp parameter in startApplication() that is set to false. You can read more about this here.

If you need to close the app and start it again, then you would need to set uninstallAfterCloseApp parameter to true but it will reset all actions and start from the beginning. It’s the expected behavior. Here is the recording of the process:

2 Likes

@chen.lee
I am sorry I have not communicated well what I want to achieve.

What I want to achieve is to restart the app without resetting it.
For example, I want to task kill an app that logs in and runs after authentication and go back to the pre-login screen. Of course, do not reset the authentication information.

For the CofeeTimer app in the video, I want to return to the menu screen immediately after launch with a single closeApplication.
See in the video, the closeApplication step does not even close the app screen, is this as expected?

With the Android simulator does what I want with a single line of closeApplication. The application is task-killed by closeApplication and returns to the login screen when the application is launched again.
From memory, iOS used to work as well.
Now when I run close Application, I’m still on the screen after login, not pre-login screen.

I want to realize what I would call a task kill on a real device.

Thank you! All of that behavior can be achieved with a single sentence of closeApplication in Android, and I think iOS used to be the same way, but I guess not…

Anyway, I will try to create my script. Thank you!!

1 Like

@loc.nguyen
Sorry for the delay, but I was able to achieve what I wanted to do with this command: driver.terminateApp.

Thank you!!

2 Likes