In the past, we've covered how to simulate receiving SMS messages on Android emulators. It is also possible to receive and interact with incoming phone calls! This might be relevant for apps that engage with the phone subsystem in some way, or it might just be a good idea to test that nothing goes wrong in your app when someone takes a call while using it.
Why rely on simulations when you have the opportunity to conduct Android apps testing on actual devices? Learn more.
(Of course, this only works on emulators; to achieve the same result on a real device, just make sure the real device has a working SIM card and trigger a call to it using one of the available phone call automation services.)
Test your apps on real devices and get accurate results. Know more.
How can we take advantage of this feature? It's made available in the Appium Java client via the driver.makeGsmCall() method. This method takes two parameters:
- A string representing the phone number which the emulator will show as calling it (this should be purely numbers, no dashes or parentheses).
- A member of the GsmCallActions enum, namely one of GsmCallActions.CALL, GsmCallActions.CANCEL, GsmCallActions.ACCEPT, or GsmCallActions.HOLD. Each of these defines an action the emulator will take with respect to the particular phone number that has called.
Check out: Automating Biometric Authentication in Android
Basically, to initiate a call to the emulator, we first make a call like this:
This will start the device "ringing". At this point it will continue to ring until we follow up with another action. We may, for example, choose to accept the call:
At this point the call will be active, and will remain active until we choose to end it:
Using this series of commands, we can simulate the entire flow of a user receiving a phone call while in our app, accepting the call, continuing to go about her business in the app while the call is active, and then ending the call. At any point in this flow, we can continue to run regular Appium commands, which is how we would check that our app continues to function normally even as the call takes place.
Also check: Batching Appium Commands Using Execute Driver Script to Speed Up Tests
That's it! Take a look at the full example below, which introduces some artificial pauses in the course of the script so you can see the action taking place (otherwise it all happens too quickly):Using this series of commands, we can simulate the entire flow of a user receiving a phone call while in our app, accepting the call, continuing to go about her business in the app while the call is active, and then ending the call. At any point in this flow, we can continue to run regular Appium commands, which is how we would check that our app continues to function normally even as the call takes place.
Continuously monitor and optimize quality of experience across applications, devices and 3rd-party interfaces with mobile app performance testing insights. Learn more.
That's it! Take a look at the full example below, which introduces some artificial pauses in the course of the script so you can see the action taking place (otherwise it all happens too quickly):
Of course, you can also have a look at the sample on GitHub.