简体   繁体   English

Testcafe expect 如果使用 await 则通过,但如果方法链接则不通过

[英]Testcafe expect passes if await used but not if methods chained

Take this Testcafe code:拿这个 Testcafe 代码:

test
    .page('https://testsite.com')
    ('button hidden after clicked', async t => {
        await t
            .expect(await Selector('button.cc-banner__button-accept').visible).ok({ timeout: 5000 })
            .setNativeDialogHandler(() => true)
            .click(await Selector('button.cc-banner__button-accept'))
            .expect(await Selector('button.cc-banner__button-accept').visible).notOk({ timeout:1000 });

The above fails when Testcafe runs.当 Testcafe 运行时以上失败。

However, the code below passes:但是,下面的代码通过了:

test
    .page('https://testsite.com')
    ('button hidden after clicked', async t => {
        await t
            .expect(await Selector('button.cc-banner__button-accept').visible).ok({ timeout: 5000 })
            .setNativeDialogHandler(() => true)
            .click(await Selector('button.cc-banner__button-accept'));
        await t
            .expect(await Selector('button.cc-banner__button-accept').visible).notOk({ timeout:1000 });

Why is this?为什么是这样? Any ideas?有任何想法吗?

JS evaluates the real element value for Selector at the time of chain compiling. JS 在链式编译时为Selector计算真实的元素值。 (JS works in this way). (JS以这种方式工作)。 It means that the first test you evaluate calculates await Selector('button.cc-banner__button-accept').visible for the whole chain only once and then this value is used for checking.这意味着您评估的第一个测试计算await Selector('button.cc-banner__button-accept').visible对整个链只有一次,然后这个值用于检查。 Since you get the value only once, the test fails as expected.由于您只获得一次值,因此测试如预期的那样失败了。 You should remove await inside, before Selector inside assertions, as you can see in CLI warnings.您应该在断言中的Selector之前删除内部的await ,如您在 CLI 警告中所见。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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