智能查询断言是否等待客户端功能?

Does the smart query assertion wait for client functions?

我有一个 clientFunction 作为我的页面对象的一部分来检索样式个别规则:

getStyleRule(ruleName: string): Promise<string> {
    declare var selector: Selector;
    return ClientFunction(() => 
       selector().style.getPropertyValue(ruleName), {
       dependencies: { selector: this.selector, ruleName }
    })();
}

然后在我的测试中,我将鼠标悬停在一个元素上并期待样式更改:

await t.hover(someSelector);
await t.expect(pageObject.getStyleRule('width')).eql('100%')

这似乎在 Chrome 68 上一直失败,但如果我将 speed: 0.5 添加到悬停动作,它就会通过。这让我相信智能查询不会重试其值来自客户端函数的断言。

或者,我调用 clientFunction 的方式可能有问题...

1) TestCafe 等待并自动重新评估 ClientFunctions 返回的结果;以下测试证明了这一点:

import { ClientFunction } from 'testcafe';
 
fixture('Client Function')
    .page('http://example.com');
 
function clientFunction():Promise<any> {
    return ClientFunction(() => false)();
}
 
test('Reevaluate', async t => {
    await t.expect(clientFunction()).ok({ timeout: 30000 });
});

您将在重新评估断言时看到 'Waiting for an assertion execution' 消息。

2) 您不必使用 ClientFunction 来检索元素的样式属性;您可以简单地使用 Selector 的 getStyleProperty 方法。

https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/dom-node-state.html#members-specific-to-element-nodes

3) 如果不先与您的页面进行交互,我无法确定,但我猜悬停动作执行得太快以至于无法被您页面上的脚本识别。这种情况下可以设置悬停动作前的测试速度,然后在悬停动作后通过t.setTestSpeed方法恢复:

await t
    .setTestSpeed(0.5)
    .hover(...)
    .setTestSpeed(1.0)

https://devexpress.github.io/testcafe/documentation/test-api/test-code-structure.html#setting-test-speed