Browser script test

Browser testing simulates the paths that users might take through web applications by playing back Node.js based test scripts through browsers to monitor and measure the performance of users' websites.

Instana® supports browser testing for Synthetic PoP Helm chart 1.0.15 or later. Instana uses a new playback engine to run these tests. You must upgrade your Synthetic PoP version to 1.0.15 or later to enable the browser playback engine. Instana browser testing supports Browser Simple test and Browser Script test.

Instana Synthetic browser testing supports Selenium documentation-based APIs and expands browser testing functions with over 30 browser testing APIs.

In addition, Instana Synthetic introduces a set of global variables and APIs to make browser testing easier, maintainable, and secure.

Using this feature, script developers can focus on test logic instead of installing browsers and drivers, opening, and closing browsers, and releasing resources.

Prerequisites

Instana supports browser testing for Synthetic PoP Helm chart 1.0.15 or later.

Instana uses a new playback engine to run these tests. You must upgrade your Synthetic PoP version to 1.0.15 or later to enable the browser playback engine.

To check the version of the Synthetic PoP Helm chart, run the following command:

helm list -n <namespace>

To verify that the new playback engine for browser testing is enabled, run the following command:

kubectl get pod -n <namespace> | grep browserscript
synthetic-pop-browserscript-playback-engine-8589bb6cbf-dh7sb   1/1     Running   0          13m

Supported runtimes and capabilities

  • Instana Synthetic browser testing supports Chromium, Mozilla Firefox, and Node.js runtime.

    • Mozilla Firefox 115.4.0esr
    • Instana supports two versions of Chromium:
      • 113.0.5672.0 when isNewEngine is false.
      • 138.0.7204.183 when isNewEngine is true.
    • Node.js v22 with the CommonJS module system. Instana Synthetic does not support ESM.
    • selenium-webdriver 4.29.0
  • Instana Synthetic browser testing supports Selenium-based APIs and over 30 browser test APIs.

  • Instana Synthetic browser testing supports to analyze and collect metrics like response time and response size.

  • Instana Synthetic browser testing includes recordings, screenshots, browser logs, console logs, and HTTP Archive (HAR) format in test results.

Browser script test types

With Instana Synthetic, you can create the following browser script tests:

Browser scripts

Browser scripts are Node.js based and include both single and bundled scripts.

Browser scripts: Single browser testing script

You can write everything in a single script. Usually, this way can meet most users' needs. See the following example:

(async function () {
  console.log("Access IBM website");
  await $browser.get("https://www.ibm.com/us-en");

  console.log("Accept all cookies");
  const cookies = await $browser.waitForAndFindElement(
    $driver.By.id(`truste-consent-button`),
    30000
  );
  await cookies.click();
})();

Browser scripts: Bundled browser testing scripts

If the business logic is complex, do not contain everything in a single script. Use multiple script files for better maintenance, code reuse, and version control in GitHub.

You can use bundled scripts in a compressed file.

  1. Write multiple scripts with shared libraries. See the following example:

    // bundled/mytest.js
    const assert = require("assert").strict;
    let { testIBM } = require("./lib/myscript.js");
    console.log("Start to test");
    testIBM();
    // bundled/lib/myscript.js
    async function testIBM() {
      console.log("Access IBM website");
      await $browser.get("https://www.ibm.com/us-en");
    
      console.log("Accept all cookies");
      const cookies = await $browser.waitForAndFindElement($driver.By.id(`truste-consent-button`), 30000);
      await cookies.click();
    };
    module.exports = {
      testIBM
    };
  2. Package multiple scripts into a .zip file. See the following example:

    Compress scripts into .zip file with the root (top-level) folder bundled and the main file bundled/mytest.js.

    zip -r bundledtest.zip bundled

    Or package all scripts into .zip file with the main file mytest.js.

    zip -r bundledtest.zip *

Playwright scripts

Instana supports Playwright scripts for browser-based Synthetic tests. You can use Playwright to define scripted interactions with web applications, such as navigation, user actions, and validations.

Playwright scripts run in a browser context to simulate user workflows and verify application behavior.

Playwright scripts provide modern browser automation with enhanced capabilities and memory optimization. Playwright offers:

  • Browser automation through a promise-based API
  • Automatic waiting for page elements and actions before execution
  • Retry mechanisms for supported operations
  • Configurable HTTP Archive (HAR) recording modes
  • Configurable browser log limits
  • Error reporting and debugging information

You can use the Playwright script test format.

Test format is a structured script using the Playwright test framework that is automatically transformed for execution. See the following example:

const { test, expect } = require('@playwright/test');

test('IBM website test', async ({ page }) => {
  await page.goto('https://www.ibm.com/us-en');
  await page.click('#truste-consent-button');
  await expect(page).toHaveTitle(/IBM/);
});

Using Playwright scripts

To use Playwright scripts in Synthetic monitoring, complete the following steps:

  1. On the Instana UI, go to Synthetic monitoring, create a Synthetic test.
  2. Select test type as Browser script.
  3. Enter or paste the Playwright script.
  4. Configure test parameters such as location and execution frequency.
  5. Save and run the test.
Note:
  • Scripts must follow supported Playwright syntax.
  • Instana converts test format scripts to execution format during runtime.
  • Use stable and unique selectors to ensure consistent execution.

Browser script testing and debugging

Instana Synthetic provides a Node.js command-line application, synthetic-browser-script, to help users develop, test, or debug your browser testing scripts locally.

The synthetic-browser-script application is now available in GitHub and the npmjs site.

  • It is a local runner for Instana Synthetic to help you with your Synthetic browser testing.

  • It comes with many Instana Synthetic examples, which helps you to write your own browser tests quickly.

You can use the synthetic-browser-script local runner in the following cases:

  • You need a local runner to test and debug your browser scripts with the CLI.

  • You need an npm package that provides all the Instana Synthetic browser testing APIs.

  • You need the "code completion" or "code hinting" in Visual Studio Code for all the browser testing APIs.

  • You need an open full browser to complete your test actions and prove the quality of your scripts.

  • You need to reproduce your test failures locally to help debug the root cause.

  • You need to learn from examples of browser testing APIs and then write your own browser tests based on these examples.