WebdriverIO不再支持同步模式,我目前正在过渡到异步模式。到目前为止,一切正常,但我注意到我的按索引点击/选择元素的方法停止了工作,例如,这在同步模式下可以很好地工作:
get expandButtons() {return $$(faqLocators.expandButton)};
clickOnExpandButtonByIndex(index: number) {
const expandButton = this.expandButtons[index]
expandButton.waitForExist()
expandButton.click()
}但是相同的方法重写为异步模式会抛出一个错误,所以在我当前的实现中,上面的方法看起来是这样的:
async clickOnExpandButtonByIndex(index: number) {
const expandButton = await this.expandButtons[index]
await expandButton.waitForExist()
await expandButton.click()
}测试中的用法如下:
it('My test', async () => {
await expect(faqPage.arrowDownIcon).toBeDisplayed();
await faqPage.clickOnExpandButtonByIndex(0)
await expect(faqPage.arrowUpIcon).toBeDisplayed();
});上面的代码抛出了以下错误:
Cannot read property 'waitForExist' of undefined
TypeError: Cannot read property 'waitForExist' of undefined
at FAQPo.<anonymous> (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:23:28)
at step (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:33:23)
at Object.next (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:14:53)
at fulfilled (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
Cannot read property 'click' of undefined
TypeError: Cannot read property 'click' of undefined
at FAQPo.<anonymous> (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:23:28)
at step (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:33:23)
at Object.next (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:14:53)
at fulfilled (/Users/badb/IdeaProjects/my-test-project/project/apps/retail-app-e2e/src/pages/FAQ/FAQ.po.ts:5:58)
at processTicksAndRejections (internal/process/task_queues.js:97:5)我还有以下警告:
TS2532: Object is possibly 'undefined'.
TS2684: The 'this' context of type 'Element | undefined' is not assignable to method's 'this' of type 'Element'. Type 'undefined' is not assignable to type 'Element'.我在文档中读到,这是异步模式下的常见问题,但建议的解决方案在我的情况下不起作用。并且我无法单击按索引与多个元素交互。有人能解释一下如何在异步模式下实现上述方法吗?我参考了这篇文章https://webdriver.io/docs/sync-vs-async/
发布于 2021-10-07 11:16:18
const expandButtons = await this.expandButtons()
const expandButton = await this.expandButtons[index]Expand按钮是一个函数而不是数组,所以等待函数给元素数组,然后在其中调用index
https://stackoverflow.com/questions/69342878
复制相似问题