因此,我有一个用于自动化测试的CucumberJS / PuppeteerJS解决方案。我在检查按钮时遇到问题。当列表中有更多项目要加载时,将显示一个“加载更多”按钮,而当所有项目都出现时,该按钮将不显示。
示例:10个项目的列表首先仅显示4个,然后显示“加载更多”按钮。您选择加载更多按钮,现在将显示8。您再次选择它,所有10个项目都在那里,并且“加载更多”按钮不再存在。
我有一些功能文件,它们调用了step_definition,而后者又调用了world.js中的某些函数
我有一些代码可以检查按钮是否存在:
const isElementVisible = async (cssSelector) => {
return Promise.resolve(
page.waitForSelector(cssSelector, { visible: true, timeout: settings._5000 })
).then(() => {
return true;
}).catch(() => {
return false;
});
};
这称为:
// Select Load More Agencies button if button is there
async clickButtonLoadMore() {
// check to see if element is visible
let selectorForLoadMoreButton = '[data-test-button="Load More"]';
let loadMoreVisible = await isElementVisible(selectorForLoadMoreButton);
// If button visible, select it
while (loadMoreVisible) {
await page
.click('[data-test-button="Load More"]');
loadMoreVisible = await isElementVisible(selectorForLoadMoreButton);
}
}
我的问题是,当我第三次选择“加载更多”按钮时(如上例所示),超时(在page.waitForSelector中)无法达到功能文件级别并且无法得到处理根据诺言。
✔ When the View List button is selected on the navigation pane # features/step_definitions/console_steps.js:7
✖ And click the Load More # features/step_definitions/console_steps.js:31
Error: No node found for selector: [data-test-button="Load More"]
at assert (/Users/huckcarignan/Desktop/sprint04/epay-test-automation/node_modules/puppeteer/lib/helper.js:229:11)
at DOMWorld.click
(/Users/huckcarignan/Desktop/sprint04/epay-test-automation/node_modules/puppeteer/lib/DOMWorld.js:359:5)
at <anonymous>
-- ASYNC --
at Frame.<anonymous> (/Users/huckcarignan/Desktop/sprint04/epay-test-automation/node_modules/puppeteer/lib/helper.js:108:27)
at Page.click (/Users/huckcarignan/Desktop/sprint04/epay-test-automation/node_modules/puppeteer/lib/Page.js:1021:29)
at ePayApp.clickButtonLoadMore (/Users/huckcarignan/Desktop/sprint04/epay-test-automation/features/support/world.js:777:6)
at <anonymous>
- And click the Manage Agency Data row that has the Mega Agency label # features/step_definitions/console_steps.js:11
- And click Agency Accounts # features/step_definitions/console_steps.js:15
找到选择器的前两次,但是第三次发现按钮不存在,并且选择器超时。它没有被抓住,而是去了黄瓜。
我该如何更正此错误,以使承诺能够抓住并处理超时?