Hi,
There as been couple request to read SMS received, mainly SMS containing some kind of verification code (OTP). This is my attempt to do so in a more standard way (without having to write code for each native messaging app).
For Android
- I picked one random SMS Popup App from play store and extracted the apk. You can access it in here: SMSPopup.apk
I implemented a class where you can install the SMS reader app, enabled it, read SMS and uninstall it. The class is available in here: ExtractCode.java
I did not spent time checking if SMSPopup was already installed or not, so I uninstalled it every time, so that the enable process works without problems. But I left the instructions in comments on how to do it, if you want to spent time doing it.
-
The way I called the methods in the small example I did was:
AppiumDriver driver = Drivers.getDriver(device);
ExtractCode eCode = new ExtractCode(driver);
eCode.installSMSAPK();
eCode.configureSMSAPK();
String mySMS = eCode.returnSMS();
eCode.uninstallSMSAPK();
For iOS
I don't have any MAC in here or have tried this in a long time, so I'll just post how I did it, when I needed it.
- In iPhone go to Settings
- Go to Notifications
- Tap on Messages
- Select Alerts on Alert style when unlocked section
- Make sure options Show Previews is enabled
SMS will be received in a dialog like it appears in the image below, and you should be able to read the SMS and close the dialog before proceeding your tests (attention: any received SMS will trigger this dialog, so take than into account on your tests).
Hope any of this can help someone.