---
title: Run K6 Browser tests with TestingBot in the cloud
description: Use k6 browser tests to run on a cloud-based browser grid.
source_url:
  html: https://testingbot.com/support/k6-browser-testing
  md: https://testingbot.com/support/k6-browser-testing/index.md
---
# k6 Browser Testing

k6 is an open-source tool designed to do easy load testing against websites. With the [k6 browser module](https://grafana.com/docs/k6/latest/using-k6-browser/), you can connect to a CDP-compatible browser grid such as TestingBot. Simply configure your k6 test to use the TestingBot grid, and instantly get access to a high capacity cloud of browsers.

With this integration, you can run tests in parallel, targeting different browsers, versions and operating systems. Each test comes with logs, screenshots and a video.

## Setup

To get started, please make sure you [install k6](https://k6.io/docs/get-started/installation/).

### macOS

    brew install k6

### Windows

    winget install k6 --source winget

### Linux

    sudo gpg -k
    sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
    echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
    sudo apt-get update
    sudo apt-get install k6

## Example

Next, let's run a sample browser test using k6 on the TestingBot browser grid. Please see the example below.

To connect to the TestingBot CDP grid, you will need to specify a `K6_BROWSER_WS_URL` environment variable. This needs to contain the URL to the TestingBot grid, together with the credentials and (url-encoded) capabilities.

    K6_BROWSER_WS_URL="wss://cloud.testingbot.com/?key=API_KEY&secret=API_SECRET&capabilities=%7B%22browserName%22%3A%22chrome%22%2C%22browserVersion%22%3A%22latest%22%7D"

To run the example below, you can use the following command in your terminal:

    K6_BROWSER_WS_URL="wss://cloud.testingbot.com/?key=API_KEY&secret=API_SECRET&capabilities=%7B%22browserName%22%3A%22chrome%22%2C%22browserVersion%22%3A%22latest%22%7D" K6_BROWSER_ENABLED=true k6 run k6_sample.js

**k6\_sample.js**

    import { browser } from 'k6/browser';
    import { check } from 'k6';
    
    export const options = {
      scenarios: {
        ui: {
          executor: 'shared-iterations',
          options: {
            browser: {
              type: 'chromium',
            },
          },
        },
      },
      thresholds: {
        checks: ['rate==1.0'],
      },
    };
    
    export default async function () {
      const context = await browser.newContext();
      const page = await context.newPage();
    
      try {
        await page.goto('https://test.k6.io/my_messages.php');
    
        await page.locator('input[name="login"]').type('admin');
        await page.locator('input[name="password"]').type('123');
    
        const submitButton = page.locator('input[type="submit"]');
    
        await Promise.all([page.waitForNavigation(), submitButton.click()]);
    
        const header = await page.locator('h2').textContent();
        check(page, {
          header: header == 'Welcome, admin!',
        });
      } finally {
        await page.close();
      }
    }

### K6\_BROWSER\_WS\_URL

To construct the `K6_BROWSER_WS_URL`, you'll need to urlencode the capabilities:

    const capabilities = {
      browserName: 'chrome',
      browserVersion: 'latest',
      platformName: 'VENTURA'
    }
    const url = `wss://cloud.testingbot.com/?key=API_KEY&secret=API_SECRET&capabilities=${encodeURIComponent(JSON.stringify(capabilities))}`

## Test Results

You can find the results of your k6 browser test in your terminal.

The TestingBot member area will contain a list of all k6 tests, together with logs, screenshots and a video of each test.

### Looking for more help?

Have questions or need more information? Reach out via email or Slack.

[Email us](https://testingbot.com/contact/new)[Slack Join our Slack](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
