Appium iOS- How can I go to Home screen

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

on real ios devices thats not possible. For simulator I think there are scripts around to do that. But if you just want to go to homescreen you dont need to tap the home button, just use the above command.

I have one doubt, above method will send the app in the background, but only for particular period of time which we will provide and in the process of sending app into background and then launching again after the provided time, how we will perform actions on homescreen between the process?

The -1 in the duration makes that it doesn’t goes back to app automatically :wink:

Test it:

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

This change is based on appium/appium-xcuitest-driver#381, which makes possible to minimize the application under test and then return to iOS springboard (emulates clicking Home button).

From Update runAppInBackground method implementation for XCUITest by mykola-mokhnach · Pull Request #593 · appium/java-client · GitHub

2 Likes

Great :slight_smile: