Creating a JS File in Bruno Premium

Bruno provides the ability to create JavaScript tests where you can modularize common code and reuse the tests across different requests or collections.
This can be especially helpful in complex scripting scenarios where the same test will be run across multiple requests, or you’re looking to leverage data that lays outside of Bruno.
Create a New Script
You can generate a JS File by:
- Right clicking on any collection or folder
- Select
New Script
from dropdown.
- Enter name and select Create
Import the Function(s)
Once your JS File has been created, you can now import the functions into any Script
tab across your resources.
Here:
getUserById
finds and returns a user object from the users array based on the provided id.bru.setVar()
sets theval
variable to the id of the fetched user.- In the url
{{val}}
is replaced with value (e.g., 2), resulting inhttps://reqres.in/api/users/2
.
When the requests are run, you will see the script being invoked.