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:
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).
@Telmo_Cardoso
could you kindly upload SMSPopup.apk to a free download site? for apkshared site have to be signup with your credit card information, could you upload the APK file to for example google drive?
thanks.
the section “For iOS” was prepared for UIAutomation.
I guess you are using XCUITest with those versions. For XCUITest I can read outside of app I’m testing, so I just open notification panel and read SMS directly from there.
I am getting the error: ava.lang.Exception: The following id was not found: net.everythingandroid.smspopup:id/popupMessageMainlayout
But i see the pop on the mobile phone running the case.
I had opened a WebApp which sent an sms and I am trying to read it.
Do i need to explicitly pass control to this pop? How?
If not, what can be wrong. Please help.
I am using the same smspopup app from playstore which you had used. It throws me the following error:
java.lang.Exception: The following id was not found: net.everythingandroid.smspopup:id/popupMessageMainlayout
while uiinspectorviewer shows me that this is present.