Window handling on iOS safari browser

Hi,
I am working on mobile web automation using NightwatchJS and appium.
I need to open a link on safari browser, close the tab and switch back to the previous tab. This is not working on iOS safari. The test script works perfectly on android mobile web, but not on iOS safari browser.
Could someone please help me in finding solution?
Thank you!

Hi everyone,

I am working on an iOS device, and i need to close the safari window in order to continue over principal app, i´ve tried with switch context, but the window does not close:

I am using appium 2.12, java 17, and XCUITest

Thank you!!!

Have you tried activateApp?

https://appium.github.io/appium.io/docs/en/commands/device/app/activate-app/

Use the bundle id of your application to continue over to principal app.

Hi @wreed, thank you for your answer.

finally i used the termiteApp in order to finish the app, and activeApp to start the app again, this implementation works well, however i would like to find a better implementation where i haven’t to close the app.

driver.terminateApp(“com.organization.myApp”);
driver.activateApp(“com.organization.myApp”);

I’m not understanding. You said you needed to close safari, and switch to your app. Now you are saying something different? Can you give some more details? I’m not sure what I’m missing here. Why do you need to terminate your app?

yes exactly I need to close only safari, but when using this line terminateApp(“com.apple.SafariViewService”), it closes the safari process completely with some credentials that I need, (for that reason the main idea is to give the option cancel to the safari window).

That’s why for now it works closing the app and reopening it, because when doing this process the credentials are saved and the safari window is closed.

terminateApp(“com.organization.myAPP”); closes the app and the safari window also.
activateApp(“com.organization.myAPP”); Open the app with configured credenciales

and if I only use this line: activateApp(com.organization.MyApp);, the safari window does not close.

Safari bundle id is ‘com.apple.mobilesafari’.

Thank you for your suggestion @wreed, i just tried with that bundleId, but for any reason the safari window does not close, and it stays there active.

i used this line:

driver.terminateApp("com.apple.mobilesafari");