简体   繁体   中英

Does the smart query assertion wait for client functions?

I have a clientFunction as part of my page object to retrieve style individual rules:

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

And then in my test I hover an element and expect a style change:

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

This seems to fail consistently on Chrome 68, but if I add speed: 0.5 to the hover action it passes. This leads me to believe the smart query does not retry assertions whose value comes from client functions.

Alternatively, I may be doing something wrong with the way I'm calling the clientFunction...

1) TestCafe awaits and automatically re-evaluates results returned by ClientFunctions; the following test prove it:

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

You will see the 'Waiting for an assertion execution' message while the assertion is being re-evaluated.

2) You don't have to use a ClientFunction to retrieve style properties of an element; you can simply use Selector's getStyleProperty method.

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

3) I can't be sure without interacting with your page first, but I guess that the hover action is executed too fast to be recognized by the scripts on your page. In this case you can set the test speed before the hover action, and then restore it after the hover action with the t.setTestSpeed method:

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

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

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