有没有办法告诉 WebdriverIO 在 React 应用程序中等待后台任务

Is there a way to tell WebdriverIO to wait for background tasks in react app

我正在 Node.js

中使用 WebdriverIO 框架测试反应网格

在我的例子中,我单击了反应网格中的分页按钮,它异步拉取数据并在 UI 上呈现数据。我需要等待此操作完成才能继续我的端到端测试。

简单来说,Angular + Protractor 组合有一个 waitForAngular()。 [ 或 getAllAngularTestabilities() ]

React + WebdriverIO 是否有类似的东西,以便我可以确保我测试的是最新数据?

it('should wait until text has changed', () => {
    browser.waitUntil(
        () => $('#someText').getText() === 'I am now different',
        {
            timeout: 5000,
            timeoutMsg: 'expected text to be different after 5s'
        }
    );
});

唯一的选择是等待某些条件,

() => $('#someText').getText() === 'I am now different' 是一个 lambda 函数,returns 单行语句。你也可以使用普通函数:

it('should wait until text has changed', () => {
    browser.waitUntil(
        () => { return $('#someText').getText() === 'I am now different'},
        {
            timeout: 5000,
            timeoutMsg: 'expected text to be different after 5s'
        }
    );
});

测试等待文本等于预期测试,等待的最长时间为 5 秒(5000 毫秒)