Testcafe 查找元素

Testcafe find element

我用 TestCafe 做了我的第一个基本自动化测试。

import { Selector } from 'testcafe';

fixture `Ordner erstellen`
    .page `https://ifoerster.com/`;

test('New Test', async t => {
    await t
        .typeText(Selector('#email'), 'xxx', {
            caretPos: 0
        })
        .typeText(Selector('#password'), 'xxx', {
            caretPos: 0
        })
        .click(Selector('span').withText('Login'))

        //Find testref here
        .click(Selector('.np-top-section-tab.folder'))
        .click(Selector('.np-folder.new-category'))
        .typeText(Selector('[class^="ReactModal__Content ReactModal__Content--after-ope"]').find('.cl-input.cl-input-header'), 'testref')
        .click(Selector('.cl-button.cl-button.cl-button-animated'))
        .click(Selector('.np-folder-name[title="testref"]'))
        .click(Selector('.np-bottom-path-section').find('span').withText('Home'))
        .click(Selector('div').withText('testref').nth(9).find('.np-folder-fave'))
        .click(Selector('span').withText('testref'))
        .click(Selector('.cl-folder-delete'))
        .click(Selector('.cl-button.cl-button.cl-button-animated'))
        .click(Selector('.cl-popup-close'));
});

现在我试着找到元素

.click(Selector('.np-folder-name[title="testref"]'))

位置//Find testref here。 If/Once 发现,我不想在 //Find testref here 之后执行新类别步骤。

我的问题是,我如何才能在网页上找到一个元素,我能否添加一个 if 函数作为一个步骤来在找到元素时忽略步骤?比如 if 函数或类似函数?

在这种情况下使用条件逻辑:

await t
        .typeText(Selector('#email'), 'xxx', {
            caretPos: 0
        })
        .typeText(Selector('#password'), 'xxx', {
            caretPos: 0
        })
        .click(Selector('span').withText('Login'))

        const testFefElement = Selector('.np-folder-name[title="testref"]');

        if (await testFefElement.exists) {
            // condition is true
        }
        else {
            // condition is false
        }