gpt4 book ai didi

node.js - 如何告诉 TestCafe 在 navigateTo 方法之后等待?

转载 作者:搜寻专家 更新时间:2023-10-31 23:40:36 24 4
gpt4 key购买 nike

我在 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()
});

但错误是一样的。

最佳答案

问题出在 TEST_URL 变量中。如果它包含裸 IP 地址(例如,'xxx.xx.x.xxx'),navigateTo会将浏览器重定向到 'http://xxx.xx.x.xxx/xxx.xx.x.xxx' 因为 navigateTo 操作将此字符串视为相对字符串小路。

要解决此问题,请将协议(protocol)包含在 TEST_URL 字符串中,例如'http://xxx.xx.x.xxx'.

关于node.js - 如何告诉 TestCafe 在 navigateTo 方法之后等待?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44882015/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com