Custom JavaScript actions

JavaScript Steps

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

Advanced JavaScript assertions

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.

  1. Record a regular assertion to the input.

  2. Change its type to "Custom Javascript assertion"

  3. Enter custom JS code that checks the placeholder of the element, for example if (element.placeholder === 'Username') { return true } else {return false}

Make an API request from a custom Javascript code

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.

const response = await fetch('https://reqres.in/api/users', { 
    cors: 'no-cors'
});
const json = await response.json();
return json.data[0].email; //return the first user email

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:

Last updated