Features

k6 Browser Testing

k6 is an open-source tool designed to do easy load testing against websites. With the k6 browser module, 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, targetting 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.

macOS

Copy code
brew install k6

Windows

Copy code
winget install k6 --source winget

Linux

Copy code
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.

Copy code
K6_BROWSER_WS_URL="wss://cloud.testingbot.com/?key=...&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:

Copy code
K6_BROWSER_WS_URL="wss://cloud.testingbot.com/?key=...&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
Copy code
import { browser } from 'k6/experimental/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 = browser.newContext();
  const page = context.newPage();

  try {
    await page.goto('https://test.k6.io/my_messages.php');

    page.locator('input[name="login"]').type('admin');
    page.locator('input[name="password"]').type('123');

    const submitButton = page.locator('input[type="submit"]');

    await Promise.all([page.waitForNavigation(), submitButton.click()]);

    check(page, {
      header: (p) => p.locator('h2').textContent() == 'Welcome, admin!',
    });
  } finally {
    page.close();
  }
}

K6_BROWSER_WS_URL

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

Copy code
const capabilities = {
	browserName: 'chrome',
	browserVersion: 'latest',
	platform: 'VENTURA'
}
`K6_BROWSER_WS_URL="wss://cloud.testingbot.com/?key=...&secret=...&capabilities=${encodeURI(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.