Automating Cmd+Shift+H (home Key) button press in iOS using appim with Java

I’ve launched the app I want on the iOS (iPhone 6) simulator. Now I want to be able to press the home button (on the simulator) and navigate to other apps. How do I do that in Java?

2 Likes
public void pressHomeButton() {
	String simulatorAppName = "Simulator";
	try {

		String[] args = { "osascript", "-e", "tell application \"System Events\" \n tell application \""
				+ simulatorAppName
				+ "\" to activate \n tell application \"System Events\" to keystroke \"h\" using {command down, shift down} \n end tell" };
		Process process = Runtime.getRuntime().exec(args);
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
		String lsString;
		while ((lsString = bufferedReader.readLine()) != null) {
			System.out.println(lsString);
		}

		try {
			Thread.sleep(200);
		} catch (Exception e1) {
		}
	} catch (Exception e) {
	}
}

Although its stale post, just thought to add a snippet here to help other folks on Mobile automation forum.

Please see my answer for “launching the home screen in is simulator” here http://stackoverflow.com/questions/43233505/with-appium-how-to-click-the-home-button-or-launch-the-home-screen-in-ios-simu/43371922#43371922