This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 3
Oct 2015

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?

  • created

    Oct '15
  • last reply

    Apr '17
  • 2

    replies

  • 1.6k

    views

  • 3

    users

  • 2

    likes

  • 1

    link

1 year later
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.

2 months later