Custom JavaScript actions
Last updated
Last updated
If you know how to code in JavaScript, you can overcome any limitations of BugBug features. With the power and flexibility of custom code actions, you can run any function during your tests.
Hint! You can call native JS functions, ex. you can request data via XMLHttpRequest
, or store values in localStorage
, etc.
Remember! You can also use variables in your custom code
Use JS code to add complex assertions. Run any function and if it returns true
the assertions will pass.
Example: assert if an input element has a specific placeholder text.
Record a regular assertion to the input.
Change its type to "Custom Javascript assertion"
Enter custom JS code that checks the placeholder of the element, for example
if (element.placeholder === 'Username') { return true } else {return false}
Using the custom JS you can really do anything. For example, you can request some data from your API and use this data in a custom javascript variable or in an assertion.
Here's an example of how to make a server-side request from Javascript.
Note! This is coding, so it adds complexity and more problems to solve. If you encounter cookie complications or "Access-Control-Allow-Origin” ask a developer for help or contact BugBug support. We recommend keeping things simple and finding another solution to achieve a similar goal.
Learn more in the full Fetch Web API documentation
We listed several ideas on what you can achieve with API requests via code:
Compare the data displayed in your app with the data returned from the server
Check if your currency exchange is up-to-date
Get a list of test users and their parameters from a centralized testing data file
Get a login and password for your random test user, skipping the registration process
Get the latest item from a server and its ID
Check if the most recently added product is shown on the list of search results