Read SMS
Introduction
In certain scenarios, you might need to check the SMS messages sent by your application.
For example, One-Time Passwords (OTP) are sent to a phone number using SMS (text message) in situations like two-factor authentication.
You can read SMS messages automatically with Endtest, without using any other external service.
This functionality is available for both Web Tests and Mobile Tests and your test does not have to be executed on a mobile device.
This functionality requires real phone numbers to be assigned to your team.
We provide real phone numbers for our users. You don't have to use any external service.
If there are no real phone numbers assigned to your team, you can request one by contacting our Support Team.
This functionality is not related in any way to the phone number that you have provide for the Two-Factor Authentication (2FA) for your Endtest account.
Steps
- Make sure there is at least one phone number assigned to your team.
- Add a new step with the
Real Phone Number
option from theSet Variable
action. - Choose a name for that variable and add the phone number in the
Real Phone Number
input.
All the phone numbers assigned to your team will appear in a dropdown in the
Real Phone Number
input after you start typing.You can also find them in the Team section from the Settings page.
- The variable declared in the previous step can be used to enter that phone number in any input we want.
- Add a new step with the
Extract Latest SMS
option from theSet Variable
action. - Choose a name for that variable.
- Enter the name of the variable declared at step 3 in the
Real Phone Number
input.
You can also enter the phone number directly, but using variables is a good practice.
- The text of the SMS will be available in the variable declared at step 7.
- You can then use that variable in any step you want, even in assertions.
After the
Extract Latest SMS
step is executed, the SMS message will be automatically marked as Read and you won't be able to access it with anotherExtract Latest SMS
step.You can also read and delete SMS messages manually in the Team section from the Settings page.
Extract a value from SMS
In some cases, you might need to extract a certain value from a SMS.
There are 2 ways in which you can achieve that:
1. By using JavaScript
If you are dealing with a Web Test
, you can use a Transfer to JavaScript
step in order to copy the SMS text from that Endtest variable into a JavaScript variable.
After that, you can use an Execute JavaScript
step in order to extract the exact value that you need from that SMS text stored in the JavaScript variable and store it into a separate JavaScript variable.
And then you can copy that extracted value from the newly created JavaScript variable back into an Endtest variable by using the Extract Value from JS Variable
option from the Set Variable
action.
More details are available in the Execute JavaScript chapter.
2. By using the Endtest Utilities service
We provide an API endpoint called Utilities
where you can send API requests during your tests in order to process data.
You can call that API endpoint automatically during your test by adding a Send API Request
step.
For example, if you want to extract the OTP from a SMS message, you can use one of the following options: extractNumbersFromText
, extractTextBeforePattern
or extractTextAfterPattern
More details are available in the Utilities chapter.