Manoj
Manoj

Reputation: 103

Testcafe: Evaluators/debugger for Selectors

Is there a better way to evaluate selectors? Currently, when TestCafe does not find a selector the error message is not helpful every time. Is there a way to evaluate/assess valid selectors or debug selectors. This will help expedite the test writing process

Upvotes: 2

Views: 550

Answers (1)

mlosev
mlosev

Reputation: 5227

At present, the best way to debug TestCafe's Selectors includes two steps:

  • find a method in chain after which the selector no longer matches any DOM element. (see the Debug Selectors help topic)
  • output the element's outerHTML value of the previous method call in the chain.
    import { Selector } from 'testcafe';

    fixture `Fixture`
        .page('https://devexpress.github.io/testcafe/example/');

    test('test', async t => {
        const selector = Selector('fieldset').addCustomDOMProperties({
            outerHTML: el => el.outerHTML
        });

        console.log(await selector.outerHTML);
    });

Upvotes: 2

Related Questions