browser-UI-test

0.23.3 · active · verified Tue Apr 21

browser-UI-test is a JavaScript framework designed for headless browser-based UI testing, primarily focused on visual regression. It allows developers to define UI test scenarios using simple `.goml` script files, which are then executed in a headless browser environment, typically leveraging Puppeteer. After script execution, the framework takes a screenshot of the page and compares it against an expected baseline image, failing the test if differences are detected. The package is currently at version 0.23.3, and its development seems active, with Docker images being pushed on merges to the main branch. This tool differentiates itself by its `.goml` script-based, declarative approach to UI interactions and its integrated screenshot comparison functionality, aiming for ease of use for quick UI checks rather than complex end-to-end testing suites like Playwright or Cypress.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic `.goml` script for UI interactions and then programmatically execute it using the `runTest` function in a Node.js environment. It includes setup for screenshot comparison and error handling.

/* my-first-test.goml */
// Go to a simple web page
go-to: "https://example.com"

// Assert the title of the page
assert-title: "Example Domain"

// Click on a link and then assert new page title
click: ("a")
assert-title: "IANA — Example domains"

// Take a screenshot and compare it (default behavior if no explicit assert fails)
// If the page changes visually, this test will fail on subsequent runs.


/* run-test.js */
import { runTest } from 'browser-ui-test';
import path from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function executeTest() {
  const testFilePath = path.join(__dirname, 'my-first-test.goml');
  console.log(`Running test: ${testFilePath}`);

  try {
    const result = await runTest(testFilePath, {
      // Optional arguments, e.g., to output screenshots to a specific folder
      'failure-folder': path.join(__dirname, 'test-failures'),
      'screenshot-folder': path.join(__dirname, 'test-screenshots'),
      'save-expected': true // Set to true initially to generate expected screenshots
    });
    if (result.success) {
      console.log('Test passed successfully!');
    } else {
      console.error('Test failed:', result.error);
    }
  } catch (e) {
    console.error('An error occurred during test execution:', e);
  }
}

executeTest();

view raw JSON →