Thanks! We'll be in touch in the next 12 hours
Oops! Something went wrong while submitting the form.

Automating test cases for text-messaging (SMS) feature of your application was never so easy

Praful Kolhe

Full-stack Development

Almost all the applications that you work on or deal with throughout the day use SMS (short messaging service) as an efficient and effective way to communicate with end users.

Some very common use-cases include: 

  • Receiving an OTP for authenticating your login 
  • Getting deals from the likes of Flipkart and Amazon informing you regarding the latest sale.
  • Getting reminder notifications for the doctor's appointment that you have
  • Getting details for your debit and credit transactions.

The practical use cases for an SMS can be far-reaching. 

Even though SMS integration forms an integral part of any application, due to the limitations and complexities involved in automating it via web automation tools like selenium, these are often neglected to be automated.

Teams often opt for verifying these sets of test cases manually, which, even though is important in getting bugs earlier, it does pose some real-time challenges.

Pitfalls with Manual Testing

With these limitations, you obviously do not want your application sending faulty Text Messages after that major Release.

Automation Testing … #theSaviour

To overcome the limitations of manual testing, delegating your task to a machine comes in handy.

Now that we have talked about the WHY, we will look into HOW the feature can be automated.
Technically, you shouldn’t / can't use selenium to read the SMS via mobile.
So, we were looking for a third-party library that is 

  • Easy to integrate with the existing code base
  • Supports a range of languages 
  • Does not involve highly complex codes and focuses on the problem at hand
  • Supports both incoming and outgoing messages

After a lot of research, we settled with Twilio.

In this article, we will look at an example of working with Twilio APIs to Read SMS and eventually using it to automate SMS flows.

Twilio supports a bunch of different languages. For this article, we stuck with Node.js

Account Setup

Registration

To start working with the service, you need to register.

Once that is done, Twilio will prompt you with a bunch of simple questions to understand why you want to use their service.

Twilio Dashboard

A trial balance of $15.50 is received upon signing up for your usage. This can be used for sending and receiving text messages. A unique Account SID and Auth Token is also generated for your account.

Buy a Number


Navigate to the buy a number link under Phone Numbers > Manage and purchase a number that you would eventually be using in your automation scripts for receiving text messages from the application.

Note - for the free trial, Twilio does not support Indian Number (+91)

Code Setup

Install Twilio in your code base

 

Code snippet

For simplification,
Just pass in the accountSid and authToken that you will receive from the Dashboard Console to the twilio library.This would return you with a client object containing the list of all the messages in your inbox.

CODE: https://gist.github.com/velotiotech/c76123f48862b91c4e9dd189fb023c3d.js

List of other APIs to read an SMS provided by Twilio

List all messages: Using this API Here you can see how to retrieve all messages from your account.

CODE: https://gist.github.com/velotiotech/fd43c6bea073606b33c3782c02985e5a.js

List Messages matching filter criteria: If you'd like to have Twilio narrow down this list of messages for you, you can do so by specifying a To number, From the number, and a DateSent.

CODE: https://gist.github.com/velotiotech/49ca77b91f8f4091ad77e97b3f301724.js

Get a Message : If you know the message SID (i.e., the message's unique identifier), then you can retrieve that specific message directly. Using this method, you can send emails without attachments.

CODE: https://gist.github.com/velotiotech/a81f5c44ac7e7b0c0fca892c24ea0bdf.js

Delete a message : If you want to delete a message from history, you can easily do so by deleting the Message instance resource.

CODE: https://gist.github.com/velotiotech/14d32a12ea7db144c30c33e52eba8cab.js

Limitations with a Trial Twilio Account

  • The trial version does not support Indian numbers (+91).
  • The trial version just provides an initial balance of $15.50.
    This is sufficient enough for your use case that involves only receiving messages on your Twilio number. But if the use case requires sending back the message from the Twilio number, a paid version can solve the purpose.
  • Messages sent via a short code (557766) are not received on the Twilio number.
    Only long codes are accepted in the trial version.
  • You can buy only a single number with the trial version. If purchasing multiple numbers is required, the user may have to switch to a paid version.

Conclusion

In a nutshell, we saw how important it is to thoroughly verify the SMS functionality of our application since it serves as one of the primary ways of communicating with the end users.
We also saw what the limitations are with following the traditional manual testing approach and how automating SMS scenarios would help us deliver high-quality products.
Finally, we demonstrated a feasible, efficient and easy-to-use way to Automate SMS test scenarios using Twilio APIs.

Hope this was a useful read and that you will now be able to easily automate SMS scenarios.
Happy testing… Do like and share …

Get the latest engineering blogs delivered straight to your inbox.
No spam. Only expert insights.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Did you like the blog? If yes, we're sure you'll also like to work with the people who write them - our best-in-class engineering team.

We're looking for talented developers who are passionate about new emerging technologies. If that's you, get in touch with us.

Explore current openings

Automating test cases for text-messaging (SMS) feature of your application was never so easy

Almost all the applications that you work on or deal with throughout the day use SMS (short messaging service) as an efficient and effective way to communicate with end users.

Some very common use-cases include: 

  • Receiving an OTP for authenticating your login 
  • Getting deals from the likes of Flipkart and Amazon informing you regarding the latest sale.
  • Getting reminder notifications for the doctor's appointment that you have
  • Getting details for your debit and credit transactions.

The practical use cases for an SMS can be far-reaching. 

Even though SMS integration forms an integral part of any application, due to the limitations and complexities involved in automating it via web automation tools like selenium, these are often neglected to be automated.

Teams often opt for verifying these sets of test cases manually, which, even though is important in getting bugs earlier, it does pose some real-time challenges.

Pitfalls with Manual Testing

With these limitations, you obviously do not want your application sending faulty Text Messages after that major Release.

Automation Testing … #theSaviour

To overcome the limitations of manual testing, delegating your task to a machine comes in handy.

Now that we have talked about the WHY, we will look into HOW the feature can be automated.
Technically, you shouldn’t / can't use selenium to read the SMS via mobile.
So, we were looking for a third-party library that is 

  • Easy to integrate with the existing code base
  • Supports a range of languages 
  • Does not involve highly complex codes and focuses on the problem at hand
  • Supports both incoming and outgoing messages

After a lot of research, we settled with Twilio.

In this article, we will look at an example of working with Twilio APIs to Read SMS and eventually using it to automate SMS flows.

Twilio supports a bunch of different languages. For this article, we stuck with Node.js

Account Setup

Registration

To start working with the service, you need to register.

Once that is done, Twilio will prompt you with a bunch of simple questions to understand why you want to use their service.

Twilio Dashboard

A trial balance of $15.50 is received upon signing up for your usage. This can be used for sending and receiving text messages. A unique Account SID and Auth Token is also generated for your account.

Buy a Number


Navigate to the buy a number link under Phone Numbers > Manage and purchase a number that you would eventually be using in your automation scripts for receiving text messages from the application.

Note - for the free trial, Twilio does not support Indian Number (+91)

Code Setup

Install Twilio in your code base

 

Code snippet

For simplification,
Just pass in the accountSid and authToken that you will receive from the Dashboard Console to the twilio library.This would return you with a client object containing the list of all the messages in your inbox.

CODE: https://gist.github.com/velotiotech/c76123f48862b91c4e9dd189fb023c3d.js

List of other APIs to read an SMS provided by Twilio

List all messages: Using this API Here you can see how to retrieve all messages from your account.

CODE: https://gist.github.com/velotiotech/fd43c6bea073606b33c3782c02985e5a.js

List Messages matching filter criteria: If you'd like to have Twilio narrow down this list of messages for you, you can do so by specifying a To number, From the number, and a DateSent.

CODE: https://gist.github.com/velotiotech/49ca77b91f8f4091ad77e97b3f301724.js

Get a Message : If you know the message SID (i.e., the message's unique identifier), then you can retrieve that specific message directly. Using this method, you can send emails without attachments.

CODE: https://gist.github.com/velotiotech/a81f5c44ac7e7b0c0fca892c24ea0bdf.js

Delete a message : If you want to delete a message from history, you can easily do so by deleting the Message instance resource.

CODE: https://gist.github.com/velotiotech/14d32a12ea7db144c30c33e52eba8cab.js

Limitations with a Trial Twilio Account

  • The trial version does not support Indian numbers (+91).
  • The trial version just provides an initial balance of $15.50.
    This is sufficient enough for your use case that involves only receiving messages on your Twilio number. But if the use case requires sending back the message from the Twilio number, a paid version can solve the purpose.
  • Messages sent via a short code (557766) are not received on the Twilio number.
    Only long codes are accepted in the trial version.
  • You can buy only a single number with the trial version. If purchasing multiple numbers is required, the user may have to switch to a paid version.

Conclusion

In a nutshell, we saw how important it is to thoroughly verify the SMS functionality of our application since it serves as one of the primary ways of communicating with the end users.
We also saw what the limitations are with following the traditional manual testing approach and how automating SMS scenarios would help us deliver high-quality products.
Finally, we demonstrated a feasible, efficient and easy-to-use way to Automate SMS test scenarios using Twilio APIs.

Hope this was a useful read and that you will now be able to easily automate SMS scenarios.
Happy testing… Do like and share …

Did you like the blog? If yes, we're sure you'll also like to work with the people who write them - our best-in-class engineering team.

We're looking for talented developers who are passionate about new emerging technologies. If that's you, get in touch with us.

Explore current openings