Arr*_*ght 3 automated-tests typescript reactjs react-virtualized testcafe
我正在使用react-virtualized来获取一长串(1000 多个)项目列表以供选择。我正在尝试设置一个端到端测试,需要单击当前未渲染的元素之一。
通常,我会简单地使用类似的东西:
await t.click(
ReactSelector('ListPage')
.findReact('ListItem')
.nth(873) // or .withText(...) or .withProps(...)
)
Run Code Online (Sandbox Code Playgroud)
但由于只渲染了 s 的一小部分ListItem,TestCafe 无法找到所需的元素。
我一直在试图弄清楚如何使用 TestCafe 的ClientFunction滚动列表容器,以便ListItem呈现所需的内容。
但是,我遇到了一些问题:
Selector并ClientFunction修改DOM元素的scrollTop?或者我是否必须直接通过 DOM 重新查询元素?ListItems 的高度不同,滚动位置不是索引x项目高度的简单计算。如何在此函数中不断更新/滚动,直到所需的内容Selector可见?小智 5
有没有办法将Selector共享到ClientFunction中并修改DOM元素的scrollTop?
有一种方法可以Selector放入Client Function. 请参考TestCafe 文档中的示例。
如何在此函数中不断更新/滚动,直到所需的选择器可见?
您可以使用 TestCafeexist属性来检查元素是否已呈现。以下示例演示了该方法:
import { Selector } from 'testcafe';
fixture`Getting Started`.page('https://bvaughn.github.io/react-virtualized/#/components/List')
test('Test 1', async t => {
const dynamicRowHeightsInput = Selector('._1oXCrgdVudv-QMFo7eQCLb');
const listItem = Selector('._113CIjCFcgg_BK6pEtLzCZ');
const targetItem = listItem.withExactText('Tisha Wurster');
await t.click(dynamicRowHeightsInput);
while (!await targetItem.exists) {
const currentLastRenderdItemIndex = await listItem.count -1;
const currentLastRenderdItemText = await listItem.nth(currentLastRenderdItemIndex).textContent;
const currentLastRenderdItem = await listItem.withExactText(currentLastRenderdItemText);
await t.hover(currentLastRenderdItem);
}
await t
.hover(targetItem)
.click(targetItem);
await t.debug();
});
Run Code Online (Sandbox Code Playgroud)
为了滚动列表容器,我使用了hover最后一个渲染listItem为目标元素的操作。
| 归档时间: |
|
| 查看次数: |
584 次 |
| 最近记录: |