--- title: "Testing Two-Step Verification with Email Testing | Autify Guide" slug: "how-to-test-two-step-verificat" description: "Secure Verification Testing: Utilize Autify's Email Testing for Two-Step Authentication. Start a Free Trial!" updated: 2023-01-17T02:34:09Z published: 2023-01-17T02:34:09Z canonical: "help.autify.com/how-to-test-two-step-verificat" --- > ## Documentation Index > Fetch the complete documentation index at: https://help.autify.com/llms.txt > Use this file to discover all available pages before exploring further. # How to Test Two-Step Verification Using the Email Testing feature Two-step verification is often used when logging into or creating a user account for a web application. The user interacts with the browser, opens the email containing the verification code, and enters it in the appropriate field on the browser. This is a complicated process, making automating the test quite challenging. With Autify, you can๐Ÿ˜‰ In this article, you will learn how to automate a two-step verification (2SV) test by using Autify's [Email Testing](/v1/docs/email-test) feature and a [JS Step](/v1/docs/what-is-js-step). ## Prerequisites To automatically test an email-based 2SV process where the security code is sent to the user's email address, the application under test (AUT) and Autify environment must meet the following prerequisites. ### Prerequisites for the application under test (AUT) - The AUT must allow you to specify the email address Autify's Email Testing feature issues to the target account (domain: testmail.autify.com). - The AUT's verification process must issue an authentication code via email. ### Prerequisites for Autify - The [Email Testing](/v1/docs/email-test) feature must be available. - **If the Email Test feature is available**, you will see an email icon on the Autify Recorder, as shown below. You are ready to start recording! ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_19.46.37.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) - **If the Email Test feature is unavailable**, the email icon will not be displayed on the Autify Recorder, as shown below. In this case, please request a trial by contacting us via the [contact form](https://autify.com/contact). We will set up the Email Testing feature for you to try out๐Ÿ‘ ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-11_15.24.52.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) - If using a fixed email address, the email address must be created in advance. - You can create a fixed email address on the Workspace Settings Page. If you would like to know more about the difference between a *fixed email address* and a *random email address*, both of which can be used in the Email Testing feature, please see [**this** **article**](/v1/docs/how-to-use-random-email-addres). - Refer to the following rule of thumb to decide which type of email to use: - Testing a 2SV process where the same member logs in every time โ†’ *Fixed* email address - Testing a 2SV process where a user registers using a unique email address each time โ†’ *Random* email address ## What will the Scenario look like? Below is an example of a completed Scenario. The following actions are performed in each step: - **Step 2**: Enter the email address issued by Autify's Email Testing feature. - **Step 5-8**: Open the email in a new window. In Step 8, a JS Step is used to get and return the 2SV code. - **Step 11**: Enter the 2SV code returned in Step 7 into the 2SV form. - **Step 12-13**: Proceed with the 2SV process and confirm that it is successful. ### Scenario Details Page ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.16.17.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) ### Test Result Page ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.10.21.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.10.39.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) In Step 11, you can see that the 2SV code obtained in Step 8 has been entered. ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.14.58.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) ## How to create the Scenario Now, let's take a look at how to create the Scenario shown above. The process can be divided into two stages: - Record the Scenario - Edit the recorded Scenario ### Record the Scenario 1. Create the Scenario. Record the actions until the web application sends the email containing the 2SV code. Open the email address on the Autify Recorder and click on the "Copy to Clipboard" icon to copy the target email address. ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.22.44.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.24.27.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) Return to the web application and enter the copied email address into the email address field. Go ahead and record the first step of the verification process. ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.27.24.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) 1. After you've recorded the step where the 2SV email is sent out, open a new window to open the email. This window must be separate from the window you are currently interacting with. (URL is optional.) ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.29.21.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) 2. In the new window, click on the appropriate email address on Autify Recorder, and open the email containing the 2SV code. ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.34.17.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) 3. Add the *Element Should Be Visible* [assertion](/v1/docs/list-of-assertions) to confirm that the email's 2SV code is visible. Also, check the CSS selector for that element (we will use it later in a JS Step. For more information on how to check CSS selectors, please see [this article](/v1/docs/how-to-get-css-selectors)). Then, close the window. ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.48.39.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) 4. Return to the verification form window. Enter the 2SV code shown in the email to the form, and continue recording. ### Edit the recorded Scenario After recording, we need to prepare a JS Step to receive a dynamic 2SV code via email. 1. Insert a JS Step right after the step that opens the 2SV email. ![](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/zndsk-Screenshot_2022-03-10_20.49.48.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) 2. In the JS step, return the character string obtained from the email. A sample code is shown below. Please replace with content that follows the structure of the email. ``` /** * Locate the element */ var selector = ""; var element = document.querySelector(selector); /** * Stop process if it does not exist */ if (!element) { throw new Error('Error: cannot find the element with selector(' + selector + ').'); } /** * Return text content */ return element.textContent; ``` In the step where the 2SV code is entered, change the input value to "Other step's result" and enter the value returned from the JS Step. ![ScreenShot2021-06-24at8.37.22_en](https://cdn.document360.io/a099d8a2-cfd2-42ca-9906-68b4a337f4a5/Images/Documentation/ScreenShot2021-06-24at8.37.22_en.png?sv=2026-02-06&spr=https&st=2026-11-11T14%3A22%3A56Z&se=2026-11-11T15%3A22%3A56Z&sr=c&sp=r&sig=IxLfiqRhrVSRycQGM2hIc1JpwpwJHdaanqv1fm%2FQxGA%3D) That's it! Autify can now receive an email that contains a unique verification code and enter it into the form! We hope this article has helped you understand how to automate tests that involve an email-based two-step verification using Autify. If you have any questions about email testing and authentication, feel free to get in touch with our support team๐Ÿ˜Š ## Further reading - [Testing various authentication methods](/v1/docs/testing-various-authentication)