Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Getgauge Taiko SetConfig

From Leeroopedia
Knowledge Sources
Domains Browser_Automation, Testing
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for modifying Taiko's runtime configuration parameters provided by the Taiko library.

Description

The setConfig function (defined in lib/config.js at lines 30-47) allows users to override Taiko's default configuration values at runtime. The configuration system is built around a defaultConfig object (lines 1-29) that defines all recognized configuration keys with their initial values. Some defaults are influenced by environment variables: TAIKO_NAVIGATION_TIMEOUT sets the navigation timeout, TAIKO_RETRY_TIMEOUT sets the retry timeout, TAIKO_HIGHLIGHT_ON_ACTION controls action highlighting, and TAIKO_BROWSER_PATH can influence Firefox-specific defaults.

When setConfig(options) is called, it iterates over each key in the provided options object. For each key, it performs two validations: first, it checks that the key exists in the defaultConfig object using Object.prototype.hasOwnProperty; if the key is unrecognized, it throws an error listing all allowed configuration keys. Second, it performs a type check using typeof comparison between the existing default value and the provided value; if the types do not match, it throws an error stating the expected and received types. Only after both checks pass is the value assigned to the internal configuration.

The companion getConfig(optionName) function (lines 49-61) retrieves configuration values. When called with a specific key name, it returns that key's current value. When called without arguments, it returns a shallow copy of the entire configuration object.

Usage

Use setConfig at the beginning of your test suite or before specific test scenarios to tune Taiko's behavior. Common use cases include:

  • Increasing timeouts for slow or heavily loaded applications.
  • Enabling observe mode during debugging to visually follow test execution.
  • Disabling waitForNavigation for single-page applications that do not trigger traditional page navigations.
  • Enabling highlightOnAction for visual debugging of element interactions.

Code Reference

Source Location

  • Repository: Taiko
  • File: lib/config.js
  • Lines: L1-29 (defaultConfig), L30-47 (setConfig), L49-61 (getConfig)

Signature

const setConfig = (options: {
  navigationTimeout?: number,
  observeTime?: number,
  retryInterval?: number,
  retryTimeout?: number,
  noOfElementToMatch?: number,
  observe?: boolean,
  waitForNavigation?: boolean,
  waitForEvents?: string[],
  ignoreSSLErrors?: boolean,
  headful?: boolean,
  highlightOnAction?: boolean,
  blockAlignment?: string,
  inlineAlignment?: string,
  useHostName?: boolean,
  secure?: boolean,
}) -> void

Import

const { setConfig } = require('taiko');

I/O Contract

Inputs

Name Type Required Description
navigationTimeout number No (default: 30000) Maximum wait time in milliseconds for page navigation to complete. Overridden by TAIKO_NAVIGATION_TIMEOUT env var.
observeTime number No (default: 3000) Delay in milliseconds inserted between actions when observe mode is enabled.
retryInterval number No (default: 100) Polling interval in milliseconds between element search retries.
retryTimeout number No (default: 10000) Maximum wait time in milliseconds for element search retries. Overridden by TAIKO_RETRY_TIMEOUT env var.
noOfElementToMatch number No (default: 20) Maximum number of elements to consider during element matching.
observe boolean No (default: false) Enable observe (slow-motion) mode for visual debugging.
waitForNavigation boolean No (default: true) Whether to wait for page navigation after performing actions.
waitForEvents string[] No (default: []) Additional browser events to wait for after actions (e.g., 'DOMContentLoaded', 'networkIdle', 'firstMeaningfulPaint').
ignoreSSLErrors boolean No (default: true) Whether to ignore SSL certificate errors during navigation.
headful boolean No (default: false) Whether the browser is running in headful (visible) mode.
highlightOnAction boolean No (default: true) Whether to visually highlight elements before performing actions on them.
blockAlignment string No (default: "nearest") Vertical alignment when scrolling elements into view.
inlineAlignment string No (default: "nearest") Horizontal alignment when scrolling elements into view.
useHostName boolean No (default: false) Use hostname instead of IP for browser connection.
secure boolean No (default: false) Use secure WebSocket connection to browser.

Outputs

Name Type Description
return void The function modifies the internal configuration in place and returns nothing.
Error (invalid key) Error Thrown when an unrecognized configuration key is provided. Message includes the list of allowed keys.
Error (type mismatch) Error Thrown when the provided value's type does not match the default value's type.

Usage Examples

Increase Timeouts for Slow Applications

const { setConfig } = require('taiko');

// Double the navigation timeout and retry timeout
setConfig({
  navigationTimeout: 60000,
  retryTimeout: 20000,
});

Enable Observe Mode for Debugging

const { setConfig } = require('taiko');

// Slow down execution and increase observe delay
setConfig({
  observe: true,
  observeTime: 5000,
});

Configure for Single-Page Applications

const { setConfig } = require('taiko');

// Disable navigation waiting for SPAs that use client-side routing
setConfig({
  waitForNavigation: false,
});

Enable Visual Highlighting

const { setConfig } = require('taiko');

// Highlight elements before clicking/typing for visual feedback
setConfig({
  highlightOnAction: true,
});

Wait for Specific Browser Events

const { setConfig } = require('taiko');

// Wait for first meaningful paint after navigation
setConfig({
  waitForEvents: ['firstMeaningfulPaint'],
});

Error Handling for Invalid Configuration

const { setConfig } = require('taiko');

// This throws: "Invalid config unknownKey. Allowed configs are navigationTimeout, observeTime, ..."
try {
  setConfig({ unknownKey: 'value' });
} catch (e) {
  console.error(e.message);
}

// This throws: "Invalid value for navigationTimeout. Expected number received string"
try {
  setConfig({ navigationTimeout: 'slow' });
} catch (e) {
  console.error(e.message);
}

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment