如何使用TestCafe选择是否选择复选框?

发布于 2025-02-06 11:06:41 字数 1061 浏览 1 评论 0 原文

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!");
})

我可以看到我的问题在代码的第六行上发表评论。 我正在努力弄清楚如何添加断言以验证复选框实际上检查了,但是我是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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋檐 2025-02-13 11:06:41

您可以使用检查 ,例如:

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

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

await t
    .click("#remote-testing")
    .expect(Selector('#remote-testing').checked).eql(true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文