This is a TDK feature

This is not supported in Testim's visual editor

This method is used to check if a checkbox element is checked or not.

  • selector {string | TDKStepLocator} a CSS selector or smart locator.
  • returns: Promise that fulfills with whether or not this checkbox is checked
// ✅ check that a given checkbox is checked 😅
const isChecked = await checkbox('input[type=checkbox]');
expect(isChecked).to.equal(true); // for example with an assertion library

// ✅ same as above with a locator
const isChecked = await checkbox(l('.signed-up'));
expect(isChecked).to.equal(true); // for example with an assertion library

// ❌ no one checks the return value, not an assertion
await checkbox(l('.signed-up'));

// ❌ you have to pass a selector or locator
const checked = await checkbox();

Full Example

'use strict';

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

test("checkboxes", async () => {
    await go('');

    await click('input[type=checkbox]')
    let isChecked = await checkbox('input[type=checkbox]');

    await click('input[type=checkbox]')
    isChecked = await checkbox('input[type=checkbox]');