ExpectedConditions 在 Protractor 中抛出错误

ExpectedConditions is throwing error in Protractor

我想在我的框架中实现 ExpectedConditions,但它抛出了一些我无法理解的错误。有人可以帮助我吗?

步骤定义

this.Then(/^Select Any Opty and click on New button$/, async () => {
    cmBrowser.sleep(10000);
    await cmBrowser.wait(EC.visibilityOf(await loginPO.optyList()),20000);
    var list=await loginPO.optyList();
});

页面对象

this.optyList = function () {
    // return $$("table[role='grid'] th span a");
    return element.all(by.xpath("//a/ancestor::th[@scope='row']"));
}

错误日志

 TypeError: Cannot read property 'bind' of undefined
    at ProtractorExpectedConditions.presenceOf (C:\Users\srongala\AppData\Roaming\npm\node_modules\protractor\built\expectedConditions.js:341:40)
    at ProtractorExpectedConditions.visibilityOf (C:\Users\srongala\AppData\Roaming\npm\node_modules\protractor\built\expectedConditions.js:381:30)
    at World.(anonymous) (C:\Users\srongala\Documents\My Received Files\Automation\Proc\Test_modules\step_definitions\PGS_ES.js:47:39)
    at runMicrotasks ((anonymous))
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

我正在使用的应用程序不是 angular 应用程序。我查看了其他问题中提供的解决方案,他们说需要使用 browser.ignoreSynchronization=true 但我都尝试了 browser.waitForAngularEnabled();browser.ignoreSynchronization=true,两者都不起作用。

您是否尝试过将定位器定义从函数更改为变量?
此外,您不必在预期条件行中使用两次等待。
尝试以下操作:

页面对象

// You should specify the index if using .all (with .get(index); at the end)
this.optyList = element.all(by.xpath("//a/ancestor::th[@scope='row']"));

Spec(这里你可以试试 visibilityOfpresenceOf

this.Then(/^Select Any Opty and click on New button$/,async ()=>{
    await cmBrowser.wait(EC.presenceOf(loginPO.optyList),20000);
    // or:
    await cmBrowser.wait(EC.visibilityOf(loginPO.optyList),20000);
});

visibilityOf()接受ElementFinder,不接受ElmentFinderArray,你不应该传入一个元素数组。

this.Then(/^Select Any Opty and click on New button$/, async () => {
    cmBrowser.sleep(10000);
    await cmBrowser.wait(EC.visibilityOf(await loginPO.optyList().first()),20000);
    var list=await loginPO.optyList();
});