I'm using PageObjects in Protractor tests. Structure looks like this,
I'm returning Promises from methods inside PageObject file. And then inside spec file in it blocks i've Expect conditions.
A sample code is like,
// login.e2e-spec.ts
it('should logout', () => {
console.log('---- step 1 ----');
page.logout().then(function () {
console.log('---- step 4 ----');
expect(page.inDom(page.getLoginButton())).toBe(true);
});
console.log('---- step 5 ----');
});
// login.po.ts
public logout() {
const that = this;
return new Promise(function (fulfill = null, reject = null) {
that.clickIfElementIsAvailable(that.welcomeModelCancelButtonElement);
that.waitForVisibility(that.sideBarOpenerElement).then(function () {
console.log('---- step 2 ----');
that.sideBarOpenerElement.click();
that.waitForVisibility(that.logoutButtonElement).then(function () {
console.log('---- step 3 ----');
that.logoutButtonElement.click();
fulfill();
}, reject);
}, reject);
});
}
After execution, all the tests pass and i get following output in log.
---- step 1 ----
---- step 5 ----
(node:2639) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'waitForElement' of undefined
(node:2639) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
3 specs, 0 failures
In practical i've multiple tests so control just moves to next tests and at the end tells that all tests passed successfully.
Now i understand that control is putting the commands in queue and moving forward. How can i handle this situation? What i'm doing wrong? Thanks.