Testim Documentation

Welcome to the Testim documentation. You'll find comprehensive guides to help you get started quickly, example code snippets, and tips for being more productive. You will also find details about advanced features that allow you to customize Testim to fit your environment or special testing conditions. Don't worry, we'll support you if you get stuck. Let's jump right in!

Guides    Changelog

waitForCode(code [,options])


This is a TDK feature

This is not supported in Testim's visual editor

This method polls the page every 100 (default ms) until a passed JavaScript value is true (well, truthy).

  • code {Function} a JavaScript function to evaluate.
  • returns: Promise that fulfills when the expression evaluates to true.
  • options {object}
    • pollInterval { number } how often to poll the page in milliseconds (default 100ms)

For example:

// βœ… wait for page body loaded
await waitForCode(() => document.body); // wait for page body loaded
// βœ… wait for page body loaded, check every one second
await waitForCode(() => document.body, {
  pollInterval: 10000
// βœ… poll a JavaScript variable
await waitForCode(() => window.isTestReady);

// βœ… poll a JavaScript variable
await waitForCode(() => window.isTestReady);

// ❌ wait for a promise, use `evaluate` instead
await waitForCode(() => fetch('/health'));

// ❌ pass a function and not a string
await waitForCode('window.body');

// ❌ because the code is sent to the browser - avoid closures
let foo = 'body';
await waitForCode(() => window[foo]));

Updated 3 months ago

waitForCode(code [,options])

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.