# Creating a Template for Automated Tests

Templates are segments of test cases that can be saved and reused in multiple test cases. Templates allow you to save time and ensure app test consistency by creating reusable test steps for multiple test cases.

To create a template, you can create a new template while recording a test or convert an existing test case into a template. Once you've created a template, you can [insert that template](https://docs.sofy.ai/mobile-automate/inserting-a-template-into-a-test-case) into any existing test case.

#### Creating a Template from a Recorded Test

01. Log in to your Sofy account.  
02. Select **Device Lab** from the left navigation bar. 
03. Locate the device you want to test, then select **Acquire**. Note: If a device is not available, the **Acquire** button will be grayed out.
04. Click **Launch** to open the device in a new window. 
05. Wait for the app to install, then click the **Recording** tab.
06. Select the **Start Recording** red button at far right.
07. Check the **Auto-handle system dialogs** box to allow Sofy to automatically handle any system dialogs that pop up. 
08. Select how you want to start the test:
    1. **Start Fresh**: Refresh the device to its default state before testing.
    2. **Continue From Here:** Record the test from the current state of the app. 
09. Interact with the device on the left and perform the steps you want to test in your app. Each step will be recorded and listed on the right.
10. Once you’re done recording your steps, click **Stop Recording & Save Steps** at the bottom of your screen. 
11. Click **Save as Template**. 
12. Name the template, set the priority, and add a description.
13. Click **Add Tag(s)** if you want to assign tags to the template. Type the tag name in the field, then hit Enter to add the tag.
14. Select **Save as Template**.

You can find your templates under the **Templates** tab in the Automation menu.

#### Converting a Test Case into a Template

If you want to create a template from existing test cases, you can choose to either convert an entire test case into a template or choose specific tests from a test case to create a template.

1. Log in to your Sofy account.
2. Select **Automation** from the left navigation bar. 
3. Under the **Test Cases** tab, search for and select the test case you want to convert to a template. This will open the test case's edit view.
4. Select the **Create new template from test** text located in the bottom right-hand corner. 
5. In the new view, choose which steps you want to include in your template:
    1. Select the step you want to mark as the starting point for the template.
    2. Scroll through the steps and select the step you want to mark as the ending point for the template. A black border will appear around all steps included in the template.
    3. To change which steps you want to include in the template, click on the blue circle found at the starting or ending point. Drag the circle to the desired location and release to redefine which steps are included in the template. 
6. Name the template and add any additional details to identify the template, **including tags** to help organize your testing structure for re-use.
7. Click **Save**.

You can find your templates under the **Templates** tab in the Automation menu.
