gpt4 book ai didi

testing - 在 Testcafe 中,如何等待同一选择器的第二个元素出现?

转载 作者:行者123 更新时间:2023-12-04 16:57:31 25 4
gpt4 key购买 nike

我有一个场景,其中多个元素相同 className一个接一个出现(这取决于服务器响应)。

我试图实现的是仅在同一选择器的 2 个元素存在后才通过测试,但目前,测试似乎失败了,因为它不断识别 1 个元素,然后直接失败而无需等待第二个元素。

这是我的代码(从外部调用 count 参数,例如 2)-

import { Selector } from 'testcafe';

export const validateMsg = async (t, headlineText, count = 1) => {
const msgHeadline = Selector('.myClassName').withText(headlineText).exists;

const msgHeadLineExists = await t
.expect(msgHeadline.count)
.gte(count, `Received less than ${count} desired messages with headline ${headlineText}`);
return msgHeadLineExists;
};


我认为这是因为我正在检查是否 msgHeadline存在,它在渲染时看到第一个元素,然后立即失败。我想等第二个。

有任何想法吗?

最佳答案

只需删除 .exists从您的选择器它返回 bool 值,然后调用 .count 将失败测试。

const msgHeadline = Selector('.myClassName').withText(headlineText);

const msgHeadLineExists = await t
.expect(msgHeadline.count)
.gte(count, `Received less than ${count} desired messages with headline ${headlineText}`);
return msgHeadLineExists;

你可以在这里阅读更多
https://devexpress.github.io/testcafe/documentation/test-api/selecting-page-elements/selectors/using-selectors.html#check-if-an-element-exists

关于testing - 在 Testcafe 中,如何等待同一选择器的第二个元素出现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56762342/

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