### How to generate a random email within Leapwork?

### Overview

When it comes to testing, data is the key, and it is undeniable that data preparation is a time-consuming phase of software testing. Often, users need some disposable random email as part of test data so that they can use it in their workflows. Unfortunately, creating or storing such a random email address requires a lot of manual effort and time.

Leapwork offers [Generator blocks](/content/product/documentation/building-blocks/generators/index.html) that can be used for generating some random text or numbers. And with the combination of such blocks, any test data can be created. Users may also create [sub-flows](/content/product/documentation/sub-flows/index.html) (reusable components) for generating specific kinds of test data. In this example, we will prepare an email generator sub-flow that can provide random emails with different possible combinations.

### Use Cases

#### **Scenario 1**: I need to create a sub-flow that generates an email with some domain as input.

In this scenario, the random text should be concatenated before some arbitrary domain to make a valid email address.

So we can make use of a Generate Password block as it can generate any random text. Also, a random domain, e.g., [xyz.com](https://xyz.com/) or [gmail.com](https://gmail.com/), etc., should be appended to make it in a valid email address format. Please refer to the below screenshot for the details of the blocks.

This is how the sub-flow will appear in the main flow where it will be used.

#### **Scenario 2**: I need to create a sub-flow that generates an email with a specific domain as input.

In addition to what we've created in the first scenario, we need to supply domain as an input, so it will require to be made as a parameter/input to the sub-flow. And the randomly generated text should be concatenated before the domain to make it a valid email address. Please refer to the below screenshot for the details of the blocks.

This is how the sub-flow will appear in the main flow where it will be used.

#### **Scenario 3**: I need to create a sub-flow that generates an email of a given length with a specific domain as input.

We need to improvise the above scenario where we also parameterize the text's length in this scenario. Again, adding a value input block (rename to Length) to the existing sub-flow serves the purpose.

The main flow looks as below:

### Quick Start

#### **Setup**

1. Download the attached Example.zip file.
2. Import the attached use case, [Example.zip](https://support.leapwork.com/hc/article_attachments/4406270458514/Example.zip), in the Leapwork Studio. Please refer: [How to Export and Import automation flows](https://support.leapwork.com/hc/en-us/articles/115003873052-How-to-Export-and-Import-automation-flows)
3. Open the use case with the title, "Use Case - Random Email Generator."
4. Check the sub-flow with the title, "Email Generator."
5. This sub-flow is available to be used across any flow. For example, if you right-click on the blank canvas and choose Add Building Block (or press Ctrl+N), the above sub-flow can easily be found in the sub-flows category menu item.

Note: The Sub-flow can be used across the various flows, so it is readily available after the import within any test case.

#### **Configuration and Use**

After the flow has been imported, you can move the sub-flow to a preferred location, such as a common utility folder. Please refer: [Organizing Daily Work in Leapwork](https://support.leapwork.com/hc/en-us/articles/360015100539-Best-Practices-Organizing-Daily-Work-in-Leapwork).

For any clarification, please get in touch with our [Priority Support](mailto:prioritysupport@leapwork.com).

**Attachments:**

[Example.zip](https://leapworkaps.file.force.com/sfc/dist/version/download/?oid=00D7Q000003Qjj6&ids=0687Q000004sBd6&d=%2Fa%2F7Q000000cBl4%2FM5s5KuMLdKqeCzmJhH9sexPcZX0JU4BlMB.LFZffAVw&asPdf=false)
