Search code examples
javascriptselenium-webdriverprotractorcucumberjs

ExpectedConditions is throwing error in Protractor


I want to implement ExpectedConditions in my framework but it is throwing some error which i'm not able to understand. can someone help me in this.

Step Definition

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();
});

page object

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

Error Log

 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)

The application i'm using is non angular applicatio.. i reviewed solutions provided in the others questions and they said like need to use browser.ignoreSynchronization=true but i tried both browser.waitForAngularEnabled(); and browser.ignoreSynchronization=true, both are not working.


Solution

  • Have you tried changing the locator definition from function to a variable?
    Also you don't have to use await twice in the expected conditions line.
    Try the following:

    Page Object

    // 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 (Here you could try with visibilityOf or presenceOf)

    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);
    });