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



我有一个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添加到悬停操作中,它会通过。这让我相信智能查询不会重试其值来自客户端函数的断言。

或者,我调用客户端函数的方式可能做错了......

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

在重新评估断言时,您将看到"等待断言执行"消息。  

2(您不必使用客户端函数来检索元素的样式属性;你可以简单地使用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

最新更新