我一直在使用页面对象模式和 WebdriverIO 并尝试声明一个将在子页面中继承的选择器。我都试过了
function Page() {
this.loader = function() {
return $("div[class*='loading'] svg");
}
}
还有这个
Page.prototype.loader = function() {
return $("div[class*='loading'] svg");
}
当我从子页面调用此函数时,例如
checkoutPage.loader.waitForVisible(5000, true);
我收到“checkoutPage.loader.waitForVisible”不是函数”错误。如何为基本页面声明 getter,以便可以从任何子页面调用它?
最佳答案
当您调用 checkoutPage.loader.waitForVisible(5000, true)
时,您实际上返回的是整个 loader
函数而不是元素。
将其更改为 checkoutPage.loader().waitForVisible(5000, true);
并且您的第一个示例应该可以正常工作。
关于javascript - 从 WebdriverIO 中的基本 pageobject 页面调用方法时出现 "is not a function"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48093428/