How to perform OTP-based authentication using Testsigma?


Two-factor authentication (2FA), sometimes also referred to as two-step verification or dual-factor authentication, is a security process in which users provide two different authentication factors to verify themselves. This process is done to better protect both the user's credentials and the resources the user can access. Two-factor authentication provides a higher level of security than authentication methods that depend on single-factor authentication in which the user provides only one factor -- typically, a password or passcode. Two-factor authentication methods rely on a user providing a password, as well as a second factor, more often an OTP that gets sent to a user's mobile device.


Writing Automated Tests for OTP authentication in Testsigma takes few clicks with absolutely no need for coding knowledge or any third-party framework access. 


Here is a use case for automating OTP Based Authentication.


Use Case :


Login to Salesforce 

  1. Enter your username and password
  2. Salesforce sends an OTP to the registered mobile number 
  3. Retrieve this OTP and enter it into the verify input field in Salesforce for user authentication




Follow the below steps to test your OTP functionality.


1. log in to your Testsigma Account


2. Upload your mobile application 


3. Create a simple test case to understand how to use the getOTP custom function


4. Enter the NLP " Enter test data in UI Identifier field"




5. Delete test data from the NLP and choose the custom function option. From the right-side panel, search for getOTP and choose the custom function.





6. Click on the custom function getOTP on the right-side panel





7. Enter the regular expression depending on the length of the OTP field in your test case. For example: for an OTP which is a number with a length of 4 to 8, we can use the regular expression \d{4,8}.


Choose the phone number from the dropdown. 


In the timeout, enter time in seconds for the getOTP function to poll or wait.



8. Click create test step


9. Now add test steps around the recently created step as shown in the screenshot


            These steps should:

  •   Enter a username to sales_username field 
  •   Enter the password to the sales_password field
  •   Click on Login
  •   Enter OTP from custom function to an input field





------------------------------------------------------------------------------------------------------


Automating an OTP generation step



If the specific phone number needs to be used in a test case, use the phone number option available in the Testsigma NLP to enter the specific phone number to your test case.


------------------------------------------------------------------------------------------------------


Note :


1. It is highly recommended that users perform both, OTP generation and retrieval in the same test case. This is to ensure that the right OTP gets picked up by our Testsigma servers


2. Wait for the test to finish polling while the SMS can be retrieved and parsed by our Testsigma Algorithms


3. Ensure that you pick up the right phone number from Testsigma UI