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

evaluate(javascriptFunction [,...args])

This method is used to run custom JavaScript in the browser application page. This is useful as an escape hatch and in order to implement interactions that are not available out of the box with Testim or in order to interact with the page JavaScript.

Note: this method does not support closures and both the function and the return value must be serializable:

  • javascriptFunction {function} a JavaScript function to evaluate
  • args {any[]} arguments to pass to the function, must be serializable
  • returns: Promise which fulfills with the element's return value (in JavaScript).
// ✅ get the page's html content
const allHtml = await evaluate(() => document.body.outerHTML);
expect(allHtml).to.equal('<html>...</html>'); 
// ✅ call a custom function
const result = await evaluate(() => window.someFunction());

// ❌ pass a function and not a string
await evaluate('window.someFunction()');
// ❌ do not use closures
const foo = '15';
await evaluate(() => window[foo]());

Full Example:

'use strict';

const expect = require('chai').expect;
const { go, evaluate, test } = require('testim');

test("evaluate", async () => {
    await go('http://jsbin.testim.io/quh/1');
    const ten = await evaluate((ron) => ron, 10);
    expect(ten).to.equal(10);
    const string = await evaluate((benji) => benji, "benji");
    expect(string).to.equal("benji");
    const boolean = await evaluate((elad) => elad, true);
    expect(boolean).to.equal(true);
    const object = await evaluate((obj) => obj, {x: 3});
    expect(object).to.deep.equal({x: 3});
});

Updated 26 days ago

evaluate(javascriptFunction [,...args])


Suggested Edits are limited on API Reference Pages

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