UnhandledPromiseRejectionWarning: Unhandled promise rejection. warning is displaued in protractor console on using aync and await

Viewed 141

I have written the below code for automation using protractor.

this.promoteToOperationaltSandboxes3 = async function(){


        const allMainPanel =  element.all(by.className('tropos-appbox-main-panel col-md-12'));
        console.log(typeof allMainPanel);

        console.log('In the wait function , number of the main panels is '+allMainPanel.length);
const allLitags = await allMainPanel[0].all(by.className('dropdown-menu ng-scope')).all(by.tagName('li'));
        console.log('In the wait function , number of the litags is '+allLitags.length);
}

i am calling this function in one of my spec file like this.

await appsPage.promoteToOperationaltSandboxes3();

On executing this function even the browser is not opening and giving the erorr as ;

Message: TypeError: Cannot read property 'all' of undefined Stack: TypeError: Cannot read property 'all' of undefined

Also, in the logs i can see the message as :

In the wait function , number of the main panels is undefined.

can anyone help me in resolving these issue and help me in handling the promise better.

1 Answers

you should change the allMainPanel to get the index there first:

const allMainPanel =  element.all(by.className('tropos-appbox-main-panel col-md-12')).get(0);  

then the allLitags as well, maybe into 2 separate variables:

const allLitags = allMainPanel.all(by.className('dropdown-menu ng-scope'));
const liElement = await allLitags.all(by.tagName('li'));
Related