简体   繁体   中英

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

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM