This is an advanced, alternative option for Creating an API Functional Test, so make sure to start with that guide, which will then lead into this guide.
If you prefer to code rather than build your API test in the UI, then simply click the toggle to the right of the scenario name from UI mode to scripting mode ("</>").
- Write the Script
- Validate the Script
- Upload a File
- Select a Test Location
- Select a Snippet
- DNS Override
Write the Script
In this mode, you can write your test as a Taurus YAML script directly in BlazeMeter. Any changes that you will make in the editor will also show up in the UI and vice versa.
Validate the Script
While editing the script, a basic YAML syntax check is running in the background. If the script is invalid, you won't be able to switch back to the UI (the toggle will be greyed out).
Typically when this happens, an error will appear to inform you of what the problem is. In the following example, the user has removed the scenario name entirely from the script:
Once you have completed your script, click "Validate" (or "Revalidate"), found below the editor, in order to verify your script is valid via a final check.
Finally, you can download a copy of the YAML script using the button to the right of the "Validate" button.
Upload a File
Files can be used in different ways in your test scenario. For example, you can use a CSV file as a data source, provide a file for a request body, use a file as a form attachment, or run pre- and post-processing scripts.
- Click the upload file button, then select a file from your computer.
- Once a file is uploaded, click the arrow to open a drop-down menu, then click the copy button.
- You can now paste the file name in your script.
Note: When using a CSV file, only the first row of data will be used.
Here are a few examples of how this feature can be used:
- Use a file as a data source:
data-sources: # list of external data sources
- path: user-data.csv # this is full form, path option is required
variable-names: first,second # delimiter-separated list of variable names, empty by default
Use a file in a request body:
body-file: path/to/file.txt # this file contents will be used as post body
Use a file as a form attachment:
upload-files: # attach files to form (and enable multipart/form-data) - param: summaryReport # form parameter name path: report.pdf # path to file mime-type: application/pdf # optional, Taurus will attempt to guess it automatically
Use a file as a pre- or post-processing script:
- execute: before
- execute: after
Select a Test Location
Click to open the "Select Test Location" drop-down menu, where you can select a region where you want the test executed from.
Doing so will automatically add the location to the script.
Select a Snippet
You may optionally use the "Snippets" drop-down menu (which are the equivalent of using the templates scenario option of the same name when building the test via the UI). Like their templates graphical cousins, snippets are a great way to make scripting tests faster and easier, including snippets for different types of authentication.
For example, consider the following basic scenario:
Add a "Basic Auth" snippet:
And it's added to the script for you:
The DNS Override option works for Functional Tests in the exact same manner it does for Performance Tests. Check out our guide on the DNS Override for details.