> For the complete documentation index, see [llms.txt](https://docs.qyrus.com/web-testing/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.qyrus.com/web-testing/advanced-features/functions.md).

# Functions

A **function** is a group of steps saved under one name. Instead of rebuilding the same sign-in or search sequence in every script, you build it once and drop it into as many scripts as you like.

Functions belong to the project, not to the script they were created from, so every script in the project can use them.

## Prerequisites

* A test script with at least two steps. See [Test Scripts](/web-testing/build/creatingscript.md).

## Creating a function

1. Open the script that already contains the steps you want to reuse.
2. Click the **edit** icon at the top right of the panel on the right. This puts the step list into edit mode and adds **Start recording steps** and **Create function** to the **Actions** section.
3. Tick the steps you want in the function. **You need at least two** — **Create function** stays greyed out until you have ticked a second one.

   ![Steps selected, with Create function available](https://239974709-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FycS61vFhJMvvtnJCrDJk%2Fuploads%2Fgit-blob-528dcc1cb99688bdd29952008cd1303552d9127a%2Fadvanced-functions-01.png?alt=media)
4. Click **Create function**.
5. Give it a **Function Name \*** and a **Description \***. **Tags** are optional.

   ![The Create Function dialog](https://239974709-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FycS61vFhJMvvtnJCrDJk%2Fuploads%2Fgit-blob-d710813ed3f850d6b320eadd131ab091a371f306%2Fadvanced-functions-02.png?alt=media)
6. Click **Create Function**.

Name functions for what they do — "Sign in to QBank" tells the next person more than "Function 1".

## Using a function in a script

1. On the step where you want the function to run, choose **Functions** as the action type.
2. Two options appear: **Execute Function** and **Execute Test Case**.
   * **Execute Function** runs the steps in a function you have created.
   * **Execute Test Case** runs another whole script.
3. Choose **Execute Function**, type a description for the step, then click **Select Function** and pick the function you want.

Once selected, the function's steps are shown beneath the step so you can see what will run.

## Managing functions

All the project's functions live in one place. Go to **Project Setup** and open the **Functions** tab.

![The Functions tab in Project Setup](https://239974709-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FycS61vFhJMvvtnJCrDJk%2Fuploads%2Fgit-blob-27024837d245d5e4931c4050d4f53cc5af7abbdb%2Fadvanced-functions-03.png?alt=media)

The tab lists **Recently added functions** and **All functions (*****n*****)**, each showing the function name and its step count. Alongside them:

| Control                                      | What it does                              |
| -------------------------------------------- | ----------------------------------------- |
| **Import Function**                          | Brings in a function from a file          |
| **Export as**                                | Saves a function to XLSX or JSON          |
| **View Usage**                               | Shows which scripts use the function      |
| **Sort By**, **Date Filter**, **Created By** | Narrow a long list. **Reset** clears them |

## Editing, cloning, exporting and deleting

Click the **⋮** beside a function.

![The function menu](https://239974709-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FycS61vFhJMvvtnJCrDJk%2Fuploads%2Fgit-blob-7c159bfbfa0210104b7e68e7b16ba86cd42678e7%2Fadvanced-functions-04.png?alt=media)

| Action        | What it does                                   |
| ------------- | ---------------------------------------------- |
| **Clone**     | Duplicates the function                        |
| **Edit**      | Changes its name, description and tags         |
| **Export As** | Saves it as **Export XLSX** or **Export JSON** |
| **Delete**    | Removes it                                     |

**Edit** opens a dialog with the current values filled in. Change what you need and click **Update Function**.

![Editing a function](https://239974709-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FycS61vFhJMvvtnJCrDJk%2Fuploads%2Fgit-blob-41fd104275bdc7be738323fe1dd2a0c617b65acd%2Fadvanced-functions-05.png?alt=media)

Before you delete a function, use **View Usage** to check which scripts depend on it.

## Editing the steps inside a function

Click the function's name in the **Functions** tab to open its step list. Use the **edit** icon at the top right to change the steps, then **Save**.

## Where to go next

| To read about                               | Go to                                                                      |
| ------------------------------------------- | -------------------------------------------------------------------------- |
| Sharing functions between projects as files | [Import and Export Scripts](/web-testing/advanced-features/importsteps.md) |
| Building the steps themselves               | [Test Steps](/web-testing/build/creatingsteps.md)                          |
