Appium iOS- How can I go to Home screen

Im using Appium to test my iOS app on real device. During the test I need to go to the home screen (I must do so) but can’t find a way to do it.
Any suggestions?

relaunch the app by using driver.launchApp() method, you will able to go on homescreen :slight_smile:

Hope it will help.

Thanks for your answer.
I need to stay at the device home screen, launchApp method launch my app again.

1 Like

This will only launch the app again, will not unintsall and then reinstall the app.

I don’t need to launch the app, I need to be at the device home screen.
Need to do some actions in the device home screen.

Then you should use a loop according to the back button visibility, if back button is getting displayed then click on it till you reach home screen

I don’t have back button in my app.

then what you actually do manually, to go till homescreen ?

I’m working in my app and need to click on home button of the IOS device.

driver.runAppInBackground(Duration.ofSeconds(-1));
2 Likes

This will also send the app in the background then will launch, but he needs to perform some operations in the app, don’t want to relaunch the app

No it doesn’t @Shubham_Agarwal. The -1 on the duration means it will stay in the background.

@Telmo_Cardoso - Yeah I am agree with you, but I don’t think there is way to go homescreen if we don’t have back button in the application. we have to either use launchApp() or runAppInBackground(duration) and both of them sends the app in the background.

one more thing runAppInBackground(duration) method, persists the last state of the application.

Ah sorry. I was reading device home screen :smiley: not app home screen… It’s what we get for reading in diagonal.

Then its easier, he just needs to make the steps any normal user would do to go back to app home screen like you told.

Yeah … that’s the thing :slight_smile:
It was nice discussion with you @Telmo_Cardoso , Thanks :slight_smile:

Hi guys. thanks for your answers.
Actually I mean device home screen.
The scenario is that - I’m doing some actions in my app then I need to background my app and do some actions in device home screen after that I need to go back to my app, so, I can do all but going to the device home screen.
I will check your suggestion to do:
driver.runAppInBackground(Duration.ofSeconds(-1));

he he, that will work :slight_smile: I use it a lot

@Telmo_Cardoso’s solution is good for your scenario, but I think this will not permit you to perform actions on device homescreen.
@Telmo_Cardoso - do you know about this ? I haven’t perform this thing so I also excited to know.

with XCuiTest driver you can interact with native iOS,yes. I use it to enable/disable WiFi, mobile data, location, permissions, etc.

is there any possible way that we can tap on the home button of the ios device ?
I think after tapping the home button, we can perform native ios operations and can again launch the app by providing bundle id.

1 Like