Join the webinar on ‘Using HeadSpin APIs to Manage Applications’ on July 23rd.
Automating Physical Buttons on iOS Devices

Automating Physical Buttons on iOS Devices

May 8, 2019
 Jonathan Lipps Jonathan Lipps
Jonathan Lipps

Sometimes there's an automation feature of apparently little utility, but it's fun all the same. For some reason, Apple decided to allow automation of the physical buttons on an iPhone. Well, some of them: the home button, and the volume up and down buttons. I'm still trying to think of actually useful cases for automating these buttons, but in the meantime, let's look at how to use them.

Check out: How Can You Prioritize Automated Functional Test Scenarios?

They're accessible as one of Appium's mobile: methods, like many other non-standard extensions to the WebDriver protocol. Here's an example of how to press the home button:

driver.executeScript("mobile: pressButton", ImmutableMap.of("name", "home"));

In other words, there's a single parameter name, and it takes one of three values:

  • home
  • volumeup
  • volumedown

The only catch is that the volumeup and volumedown buttons can only be automated on a real device, not a simulator (for some bizarre reason, since simulators do have virtual volume buttons that can be clicked).

Make your iOS app automation testing easier. Know more!

Pressing the home button is a good way to get out of your app and back to the home screen. Pressing it twice will navigate back to the first home screen. And pressing it twice in quick succession should open up the app switcher. Unfortunately, even with all my attempts at different timing, I couldn't actually get the app switcher to launch. Nor could I get it to launch manually by clicking the simulator button myself, so it's possible that the simulator's home button recognition is itself not reliable.

Test your apps on real devices and get accurate results. Learn more!

Anyway, if any of you readers have an idea of an interesting use case for automating these physical buttons, please do let me know! And you can also check out a full code sample on GitHub if you want to see the command in context.

Share this

Automating Physical Buttons on iOS Devices

4 Parts


Perfect Digital Experiences with Data Science Capabilities

Utilize HeadSpin's advanced capabilities to proactively improve performance and launch apps with confidence
popup image