|
1 | 1 | --- |
2 | | -title: "How to automate SMS based Two Factor Authentication(2FA)" |
| 2 | +title: "How to automate SMS based two factor authentication(2FA)" |
3 | 3 | metadesc: "Coming soon..." |
4 | 4 | noindex: true |
5 | 5 | order: 5.2 |
6 | 6 | page_id: "How to automate SMS based Two Factor Authentication(2FA)" |
7 | 7 | search_keyword: "Web Application, Recorder, Testsigma Tutorials" |
8 | 8 | warning: false |
| 9 | +contextual_links: |
| 10 | +- type: section |
| 11 | +- name: "Contents" |
| 12 | +- type: link |
| 13 | + name: "Prerequisites" |
| 14 | + url: "#prerequisites" |
| 15 | +- type: link |
| 16 | + name: "Steps to automate SMS based OTP verification" |
| 17 | + url: "#steps-to-automate-sms-based-otp-verification" |
| 18 | + |
9 | 19 | --- |
10 | 20 |
|
11 | 21 | --- |
12 | 22 |
|
13 | | -### Coming soon... |
| 23 | +## **Prerequisites** |
| 24 | + |
| 25 | +<li>A Testsigma account. If you do not have one already, <a href="https://testsigma.com/signup">sign up for a free trial</a></li> |
| 26 | +<li>Understanding of creating and running test cases.</li> |
| 27 | +<li>Provisioned phone numbers.</li> |
| 28 | +<li>Familiarity with regular expressions. If not, refer to <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions">Regex guide - MDN Docs.</a></li> |
| 29 | +<br> |
| 30 | + |
| 31 | + |
| 32 | +## **Steps to automate SMS based OTP verification** |
| 33 | + |
| 34 | + |
| 35 | +### **Step 1: Record elements** |
| 36 | + |
| 37 | +<p> |
| 38 | + |
| 39 | +Before moving on to the test case, you must capture elements on the login screen of your application. <em>For more information on how to record elements using Testsigma chrome recorder extension, refer to</em> |
| 40 | +<li><a href="https://testsigma.com/docs/elements/web-apps/record-multiple-elements/">Web application </a></li> |
| 41 | +<li><a href="https://testsigma.com/docs/elements/android-apps/record-multiple-elements/">Android</a> </li> |
| 42 | +<li><a href="">iOS</a></li> |
| 43 | +</p> |
| 44 | + |
| 45 | +### **Step 2: Configuring your phone number** |
| 46 | +<p> |
| 47 | +Testsigma provides you with a valid mobile phone number on request, with which you can author any test case that requires a valid phone number.</p> |
| 48 | + |
| 49 | +[[info | NOTE:]] |
| 50 | +| The 2FA testing (email and phone number) is offered as part of the enterprise plan. The feature is available for the below mentioned countries & supported for SMS OTP.<br>Australia, Canada, USA, Czech Republic, Denmark, Hungary, Indonesia, Mexico, Netherlands, Romania, Slovakia, Sweden, United Kingdom. For other regions, contact sales. |
| 51 | + |
| 52 | +To view the phone numbers allocated to your account, navigate to **Settings> Phone numbers**. |
| 53 | +<br> |
| 54 | + |
| 55 | +### **Step 3: Create a test case** |
| 56 | + |
| 57 | +If you are not familiar on how to create a simple test case, refer to <a href="https://testsigma.com/docs/test-cases/manage/add-edit-delete/#creating-a-test-case">create a testcase</a>. |
| 58 | +<br> |
| 59 | + |
| 60 | +### **Step 4: Create a test step to enter the phone number to which the OTP will be sent** |
| 61 | + |
| 62 | +We will enter the phone number provided by Testsigma using the Phone Number test data type, using a test step. |
| 63 | +<ol> |
| 64 | +<li>In your test case, add a test step to enter the phone number in the phone number field on your application page.</li> |
| 65 | +<li>Clear the <kbd>< test data > </kbd> placeholder and select the <kbd>%|Phone Number| </kbd> test data type from the suggestions list. An overlay showing the list of available phone numbers (allocated to your account) would open up.</li> |
| 66 | +<li>Select one of the numbers from the list. This is the number where the OTP SMS will be sent.</li> |
| 67 | +<li>Next, use the NLP <em>Click on SendOTP</em></li> |
| 68 | +</ol><br> |
| 69 | + |
| 70 | + |
| 71 | +### **Step 5: Create a test step to fetch the OTP from the SMS received on the Phone number** |
| 72 | + |
| 73 | +We will use the test data generators available in Testsigma to fetch the OTP from the phone number selected in the previous step. |
| 74 | +<ol> |
| 75 | +<li>Add a test step to enter the OTP code in the OTP Field</li> |
| 76 | +<li>Clear the <kbd>< test data > </kbd>placeholder and select the <kbd>!|Function|</kbd> test data type </li> |
| 77 | +<li>Search and select the test data generator function !|PhoneNumberFunctions - getOTP|</li> |
| 78 | +<li>Enter the following arguments for the function and create the test step. |
| 79 | +<ul> |
| 80 | +<li><strong>Regex</strong>: The Regex command specifies the format of the OTP i.e alphanumeric or pure number or pure alphabetical etc. For example: for an OTP which is a number with a length of 4 to 8, we can use the regular expression <kbd>\d{4,8}</kbd>.</li> |
| 81 | +<li><strong>Phone number</strong>: This field specifies one of the pre-configured phone numbers, in this case its +12082045810</li> |
| 82 | +<li><strong>Timeout</strong>: Duration of the wait time for the OTP to be generated</li> |
| 83 | +</ul> |
| 84 | +</li> |
| 85 | +Once these values are passed the PhoneNumberFuntion will use the parameters to read the generated OTP. |
| 86 | +The below GIF depicts the method to automate email based OTP verification in real time using a sample application: |
| 87 | +</ol> |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +<img src="https://s3.amazonaws.com/static-docs.testsigma.com/new_images/advanced/sms-based-two-factor-authentication-2fa/sms_automation.gif" alt="sms based 2fa automation"> |
| 92 | +--- |
0 commit comments