LogoLogo
BugBug HomepageContact SupportLoginSign up free
  • Documentation
  • Tutorial for beginners
  • Best practices
  • BugBug App FAQ
  • Quick Start
    • What is test automation?
    • Start for free
    • Create your first project
    • Install Chrome extension
    • Create and run the tests
  • Creating Tests
    • Your first test
    • Independent tests
    • Duplicating tests
    • New test from here
  • Recording tests steps
    • BugBug overlay
    • Recording clicks
    • Recording hover
    • Recording keyboard typing
    • Recording assertions
    • Recording drag & drop
    • Record from here
    • Re-recording steps
    • Recording pop-up window actions
    • Using keyboard shortcuts
  • Editing tests
    • Grouping steps
    • Components
    • Manually editing steps
    • Actions
    • Assertions
    • Tabs & iframes
    • Variables
    • Local variables
    • Profiles
    • Custom JavaScript actions
  • Running tests
    • Running the tests
    • Statuses
    • Run (locally)
    • Run and pause here
    • Run in cloud
    • Schedules
    • Parallel runs
    • Running via API
    • Test your local build or protected web page using ngrok
  • Preventing failed tests
    • Waiting conditions
    • Smart click
    • Smart scroll
    • Selectors
    • Timeout
    • Delay / Sleep
    • Project settings
  • Debugging Tests
    • Runs history
    • Screenshots
    • Debug in Chrome
    • Breakpoint (run step-by-step)
  • Organizing tests
    • Naming your tests
    • Searching tests
    • Suites
    • Components
    • Projects
  • Workflow Tips
    • Edit & Rewind
    • Changing the test screen size
    • Multiple environments
    • Testing registration & login
    • Integrating with build systems
    • Mobile version testing
  • Collaboration
    • Organizations
    • Inviting team members
    • Alerts
      • Sending email notification
      • Sending webhook
      • Sending Slack message
      • Sending Teams message
  • Integrations
    • CLI
    • Zapier
    • Slack
    • GitHub
    • Bitbucket
    • Gitlab
    • Trello
    • Jira
  • Your account
    • Account settings
    • Edit your name and email
    • Forgot password
    • Manage Subscriptions
    • Account FAQ
  • Troubleshooting
    • Prohibited behaviors
    • Updating Chrome extension
    • Clear cookies and site data for BugBug
    • Testing basic auth password protected websites
    • Common selectors issues
    • CAPTCHA in automation testing
    • Cloud tests sometimes failing
    • IPs list of cloud runners
    • VPN or a Firewall
    • A/B tests
    • Report a bug
  • IN-DEPTH GUIDES
    • Beginners tutorial to automation testing
    • XPath Selectors without coding
    • Tech Leader's Guide to Automation Testing
    • Test automation guides
  • FREE TOOLS
    • BugBug Testing Inbox
    • Example SaaS App
    • No-code XPath Selector Builder
  • Other links
    • BugBug Homepage
    • Pricing
    • Terms & conditions
    • Privacy Policy
Powered by GitBook
On this page
  • JavaScript Steps
  • Advanced JavaScript assertions
  • Make an API request from a custom Javascript code

Was this helpful?

  1. Editing tests

Custom JavaScript actions

PreviousLocal variablesNextRunning the tests

Last updated 2 years ago

Was this helpful?

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.

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

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.

We listed several ideas on what you can achieve with API requests via code:

Use API request to
Example use case

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

Remember! You can also use in your custom 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 or in an assertion.

Learn more in the full

Fetch Web API documentation
variables
custom javascript variable