Testcafe 找不到包装在迭代器中的测试
Testcafe can't find tests wrapped in iterator
我的 FAQ 页面中几乎没有扩展元素,因此我想测试所有这些元素。
在 foreach
部分编写我的 fixture and/or 测试时,终端反映错误
ERROR no test to run.
我不明白为什么
我尝试将唯一的测试包装在 foreach
中,并将所有夹具包装在测试中,结果是一样的。
fixture('check FAQ expand items').page(URL.local.faq)//.meta({ status: 'indev' })
.beforeEach(async () => {await waitForReact();
})
.before(async t => {
await waitForReact();
await list();
}).only;
faqItems.forEach( (element) => {
test(`check that ${element.getReact(({key})=>key)} is present`, async t => {
await t.expect(element.find('[expanded={true]]').exists).ok();
});
});
我希望测试咖啡馆将 运行 faqItems.length
数量的测试放入 'check FAQ expand items' fixture
I 运行 使用命令 testcafe chrome faq.test.ts
进行测试
screen shot of run test result
UPD
let faqItems: Array<Selector> = [faq.item];
async function list() {
const count = await faq.item.count;
console.log(`count = ${count}`)
for (let i = 0; i < count; i++) {
await faqItems.push( await faq.item.nth(i));
console.log(await faqItems[i].getReact(({key})=> key));
}
}
fixture('check FAQ expand items').page(URL.local.faq)//.meta({ status: 'indev' })
.beforeEach(async () => {
await waitForReact();
await list();
})
faqItems.forEach((element)=>{
test(`check that ${element.getReact(({key})=>key)} is present`, async t => {
await t.expect(element.find('[expanded={true}]').exists).ok();
});
})
result pic
首先,您的 pre-condition 部分代码不是 forEach
循环的一部分,这会给您带来麻烦。我考虑将 faqItems.forEach()
移动到 fixture
以上
faqItems.forEach( (element) => {
fixture('check FAQ expand items').page(URL.local.faq)//.meta({ status: 'indev' })
.beforeEach(async () => {await waitForReact();
})
.before(async t => {
await waitForReact();
await list();
}).only;
test(`check that ${element.getReact(({key})=>key)} is present`, async t => {
await t.expect(element.find('[expanded={true]]').exists).ok();
});
});
})
如果在 fixture
中您有一些测试不应该 运行 用于每个常见问题解答项目,然后将其移至另一个固定装置。
其次,我不确定您是否可以在此处使用 forEach
,因为 forEach
作为数组的循环和函数不适用于 async/await
。您可以使用 for...of
循环或标准 for
循环
问题是数组初始化为空。我不知道为什么但进入测试数组包含初始化数据而不是在 "BeforeAll" 中生成。这似乎是一个 testcafe 错误,但也许我太初级了,无法理解根本原因。
p.s。顺便说一句,fixture inside/outside loop.
在哪里并不重要
我的 FAQ 页面中几乎没有扩展元素,因此我想测试所有这些元素。
在 foreach
部分编写我的 fixture and/or 测试时,终端反映错误
ERROR no test to run.
我不明白为什么
我尝试将唯一的测试包装在 foreach
中,并将所有夹具包装在测试中,结果是一样的。
fixture('check FAQ expand items').page(URL.local.faq)//.meta({ status: 'indev' })
.beforeEach(async () => {await waitForReact();
})
.before(async t => {
await waitForReact();
await list();
}).only;
faqItems.forEach( (element) => {
test(`check that ${element.getReact(({key})=>key)} is present`, async t => {
await t.expect(element.find('[expanded={true]]').exists).ok();
});
});
我希望测试咖啡馆将 运行 faqItems.length
数量的测试放入 'check FAQ expand items' fixture
I 运行 使用命令 testcafe chrome faq.test.ts
screen shot of run test result
UPD
let faqItems: Array<Selector> = [faq.item];
async function list() {
const count = await faq.item.count;
console.log(`count = ${count}`)
for (let i = 0; i < count; i++) {
await faqItems.push( await faq.item.nth(i));
console.log(await faqItems[i].getReact(({key})=> key));
}
}
fixture('check FAQ expand items').page(URL.local.faq)//.meta({ status: 'indev' })
.beforeEach(async () => {
await waitForReact();
await list();
})
faqItems.forEach((element)=>{
test(`check that ${element.getReact(({key})=>key)} is present`, async t => {
await t.expect(element.find('[expanded={true}]').exists).ok();
});
})
result pic
首先,您的 pre-condition 部分代码不是 forEach
循环的一部分,这会给您带来麻烦。我考虑将 faqItems.forEach()
移动到 fixture
以上
faqItems.forEach( (element) => {
fixture('check FAQ expand items').page(URL.local.faq)//.meta({ status: 'indev' })
.beforeEach(async () => {await waitForReact();
})
.before(async t => {
await waitForReact();
await list();
}).only;
test(`check that ${element.getReact(({key})=>key)} is present`, async t => {
await t.expect(element.find('[expanded={true]]').exists).ok();
});
});
})
如果在 fixture
中您有一些测试不应该 运行 用于每个常见问题解答项目,然后将其移至另一个固定装置。
其次,我不确定您是否可以在此处使用 forEach
,因为 forEach
作为数组的循环和函数不适用于 async/await
。您可以使用 for...of
循环或标准 for
循环
问题是数组初始化为空。我不知道为什么但进入测试数组包含初始化数据而不是在 "BeforeAll" 中生成。这似乎是一个 testcafe 错误,但也许我太初级了,无法理解根本原因。 p.s。顺便说一句,fixture inside/outside loop.
在哪里并不重要