使用剧作家获取所有TH标签和测试值
我正在使用剧作家测试页面,并且有下表。
我希望能够测试所有列的列,计数和值按正确的顺序,即产品,价格等。
我该怎么做?
这是我到目前为止尝试过的方法,尽管过度
test('the table headings are in place and in the correct order', async ({
page,
}) => {
log('looking for the table headings...');
const tableThead = page.$$('table.subscriptions > thead > tr > th');
const allThs = await page.$$eval(
'table.subscriptions > thead > tr',
(ths) => {
return ths.map((th) => {
const product = th.querySelector('th:nth-child(1)');
const price = th.querySelector('th:nth-child(2)');
const term = th.querySelector('th:nth-child(3)');
const renewalDate = th.querySelector('th:nth-child(4)');
const renewalAmount = th.querySelector('th:nth-child(5)');
const renewalType = th.querySelector('th:nth-child(6)');
const paymentType = th.querySelector('th:nth-child(6)');
const address = th.querySelector('th:nth-child(7)');
return {
product,
price,
term,
renewalDate,
renewalAmount,
renewalType,
paymentType,
address,
};
});
}
);
log('taking a screenshot...');
await tableThead.screenshot({
path: 'screenshots/subscriptions/table/table-head.png',
});
});
=========
edit 1:
I'm using playwright to test a page, and I have the following table.
I want to be able to test all the thead th columns, the count and values are in the right order, i.e. Product, Price etc.
How would I go about doing this?
Here is what I've tried so far, although overkill
test('the table headings are in place and in the correct order', async ({
page,
}) => {
log('looking for the table headings...');
const tableThead = page.$('table.subscriptions > thead > tr > th');
const allThs = await page.$eval(
'table.subscriptions > thead > tr',
(ths) => {
return ths.map((th) => {
const product = th.querySelector('th:nth-child(1)');
const price = th.querySelector('th:nth-child(2)');
const term = th.querySelector('th:nth-child(3)');
const renewalDate = th.querySelector('th:nth-child(4)');
const renewalAmount = th.querySelector('th:nth-child(5)');
const renewalType = th.querySelector('th:nth-child(6)');
const paymentType = th.querySelector('th:nth-child(6)');
const address = th.querySelector('th:nth-child(7)');
return {
product,
price,
term,
renewalDate,
renewalAmount,
renewalType,
paymentType,
address,
};
});
}
);
log('taking a screenshot...');
await tableThead.screenshot({
path: 'screenshots/subscriptions/table/table-head.png',
});
});
=======
Edit 1:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为在这种情况下,您可以使用 loacators列表,然后比较这样的内部文本:
I think for this case you can use the locators lists and then compare the inner texts like this: