How to Press the iOS Simulator Home Button via Squish

Last edited on

Use Case

You test an iOS app with Squish, but you need to:

The steps described below are for pressing the home button, but you can also use image search to click the "Allow" button of a system dialog for example.

Since Squish for iOS automates the iOS app from within the simulator, it is sandboxed just like the app itself. Therefore it cannot access controls that run in macOS (e.g. outside of the simulator) such as the fake iPhone frame that shows the simulator screen. So we need to gain access to the macOS screen!

Prepare a Dummy Application

The trick is to start a native macOS application via Squish while the iOS app is running. That one is used just as a dummy to get access to the macOS desktop. If you have it, you can use the SquishAddressBook example from squish_dir/examples/mac, otherwise you can just create an empty Cocoa App in Xcode and use that. Don't add anything else, the empty NSView is sufficient!

Register the dummy application as an AUT:

  1. Open the Server Settings dialog in the IDE

  2. Select "Manage AUTs" on the left

  3. Select "Mapped AUTs" on the right

  4. Press the "Add..." button and configure the dummy app. (Here, we're using "SquishAddressBook" as the AUT.)

Now we're going to use Squish's image search feature to click things anywhere on the screen. Start both applications in an otherwise empty test case:

def main():
    iosCtx = startApplication("Elements")

    testSettings.setWrappersForApplication("SquishAddressBook", ["Mac"])
    macCtx = startApplication("SquishAddressBook")

Set a breakpoint on the snooze() line/command, then execute the test. Once you hit the breakpoint, press the Record (red dot) button in the IDE menu bar and choose Insert→mouseClick(<image>) from the control bar. Follow the instructions and select the simulator's home button circle as the image to search for.

If Squish doesn't react after the home button got pressed (e.g. if you want to record reopening the app from the iOS home screen):

You may need to first open your app again in the simulator (to allow networking), then press "Insert->mouseClick(<image>)" and then click the home button again to select the proper image.

Almost done!

If you run this test for the first time, the image search for the home button might fail. That is because the simulator window's grey/black color changes when the window is focused. Wait for the "Image Not Found" error and then choose "Adjust Search Parameters". Squish will automatically try to be less strict to find the home button in more shades of grey.


When employing this approach, you have two AUTs in Squish. You need to explicitly tell Squish on which application to operate by setting the active application context. This can be done like this: