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
- Common Functions
- 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).
When this happens, hover the mouse pointer over the UI button to see an error message. In the following example, the user has removed the scenario name entirely from the script:
If you see an error message saying, "Current configuration is in malformed structure" and "bad indentation", also ensure that you are using spaces and not tabs for indentation.
Once you have completed your script, click the "Validate" button below the editor to verify your script is valid. The button changes to either "Failed" or "Passed". Click "Failed" or "Passed" to re-validate the script.
Finally, you can download a copy of the YAML script using the button to the right of the "Validate" button.
Now you can run the API functional test.
The Common Functions dropdown offers some helper functions that make it easier to create certain requests. Click the Copy button to copy an example of a function that implements base64 or URL encoding, or generating a random number or string. Now you can paste the function into any field and define its arguments.
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: user-data.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: user-data.pdf # pasted 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:
Mock Services Configuration
Optionally, select a Mock Service Template that contains the transactions to load into the selected Mock Service. For more information, see Adding a Mock Service to a Test.
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.