我在 TestCafe 中有以下测试:
import { Selector } from 'testcafe';
const TEST_URL = process.env.TEST_URL;
fixture('/').page(`${TEST_URL}/`);
test(`users should be able to view the '/' page`, async (t) => {
await t
.navigateTo(TEST_URL)
.expect(Selector('H1').withText('All Users').exists).ok()
});
这个测试失败了:
/
✖ users should be able to view the '/' page
1) AssertionError: expected false to be truthy
Browser: Chrome 59.0.3071 / Mac OS X 10.12.5
5 |fixture('/').page(`${TEST_URL}/`);
6 |
7 |test(`users should be able to view the '/' page`, async (t) => {
8 | await t
9 | .navigateTo(TEST_URL)
> 10 | .expect(Selector('H1').withText('All Users').exists).ok()
11 |});
12 |
问题是页面没有完全加载并且没有 h1 标签(从 React 组件呈现)但我不知道如何告诉 TestCafe 等待页面加载。
我试过这个:
import { Selector } from 'testcafe';
const TEST_URL = process.env.TEST_URL;
fixture('/').page(`${TEST_URL}/`);
test(`users should be able to view the '/' page`, async (t) => {
await t.expect(Selector('H1').withText('All Users').exists).ok()
});
哪个有效,但我需要一些测试才能使用 navigateTo 所以我想知道要更改什么,以便使用 navigateTo 的测试版本也可以工作。
我试图为这样的每一行设置等待:
import { Selector } from 'testcafe';
const TEST_URL = process.env.TEST_URL;
fixture('/').page(`${TEST_URL}/`);
test(`users should be able to view the '/' page`, async (t) => {
await t.navigateTo(TEST_URL)
await t.expect(Selector('H1').withText('All Users').exists).ok()
});
但那个错误是一样的。