Simulating SMS Messages and Phone Calls on Android while Automation

text-messaging

     Our mobile devices are, well, mobile! We can send and receive various kinds of communication through them, including text/SMS messages.  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.

Simulating SMS Messages:

       Sometimes, SMS messages might be an integral part of the user experience of our own apps. This is certainly true for messaging apps themselves, but you could imagine a variety of other applications that tie into the SMS world. How can we have Appium send a text message to the emulator so we can see the app verification behavior at work? The answer is to use the aptly-named sendSMS command:

driver.sendSMS(“555-555-5555”, “Your message here!”);

 

        And that’s really it. Simply supply the two String parameters (“from” phone number and message). Well, there is one more requirement for this whole scenario to work: you have to be testing on emulators, since the sendSMS command is not available for real devices. So to prove to Appium that we’re running an emulator and not a real device, it’s currently required to send in the avd capability with the name of the emulator you’re running the test on. If that emulator is already up and running, Appium will simply use it as is. If it’s not up and running, then Appium will start it for you. If you don’t provide this capability, Appium will complain when you try to use the sendSMS command that it only works on emulators.

Simulating Incoming Phone Calls:

       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.

     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.CALLGsmCallActions.CANCELGsmCallActions.ACCEPT, or GsmCallActions.HOLD. Each of these defines an action the emulator will take with respect to the particular phone number that has called.

Basically, to initiate a call to the emulator, we first make a call like this:

driver.makeGsmCall(“1234567890”, GsmCallActions.CALL);

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:

driver.makeGsmCall(“1234567890”, GsmCallActions.ACCEPT);

At this point the call will be active, and will remain active until we choose to end it:

driver.makeGsmCall(“1234567890”, GsmCallActions.CANCEL);

        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 his/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.

        Please try to use above actions if required in your automation scripts. Recommend to use latest java-client 6.1.0

Reference: Appium Pro

make it perfect !

Automation for Non-Functional Testing – Mobile Network Connectivity

161

     Most of the time I thought Automation only possible for functional testing. Now, Appium supports non-functional testing like testing of connectivity while automation script execution. Here, I would like to show the capability of Appium to do connectivity testing of Android Native applications. The connectivity testing includes:

  • WiFi
  • Mobile Data
  • Airplane

     HasNetworkConnection interface support setting the connectivity while test script execution. If you are declared the driver as WebDriver then you need to cast the driver with HasNetworkConnection interface. Following are the different connectivity testing actions:

Set WiFi connection on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.WIFI);

Set Mobile Data connection on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.DATA);

Set Airplane mode on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.AIRPLANE);

Set both WiFi and Mobile Data on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.ALL);

Turn-off both WiFi and Mobile Data on mobile native Android
((HasNetworkConnection) driver).setConnection(Connection.NONE);

To understand the current connectivity on mobile native Android
((HasNetworkConnection) driver).getConnection();

     Try to use all the above actions in your Automation scripts whenever you automate mobile native Android.

make it perfect !