How can I verify if a checkbox is selected using TestCafe?

Viewed 67
import { Selector } from 'testcafe';

fixture("TestCafe Example")
    .page("http://devexpress.github.io/testcafe/example");

test("Fill out and submit form", async t => {

    await t.typeText("#developer-name", "Harun Jonuzi");
    //I Want to verify if these Checkboxes are Selected
    await t
        .click("#remote-testing")
        .click("#reusing-js-code")
        .click("#background-parallel-testing");


    await t.click("#macos");

    const preferredInterface = Selector("#preferred-interface");
    await t
        .click(preferredInterface)
        .click(preferredInterface.find("option").withText("JavaScript API"));
        

    const submitButton = Selector("#submit-button");
    await t
        .expect(submitButton.hasAttribute("disabled")).notOk();

    await t.click(submitButton);

    const headerInfo = Selector("#article-header");
    await t.expect(headerInfo.innerText).eql("Thank you, Harun Jonuzi!");
})

My question is commented out on the 6th line of the code as you can see it. I am trying o figure out how to add an assertion to verify that the checkboxes are actually checked, but I am new to TestCafe, just wanted to see If I can get some help from here.

1 Answers

You can use the checked property of the DOMNodeState Object, for example:

await t
    .click("#remote-testing")
    .expect(Selector('#remote-testing').checked).eql(true);
Related