I'm using PageObjects in Protractor tests. Structure looks like this,
- e2e
- specs
- base.po.ts // Base PageObject class
- Login
- login.e2e-spec.ts // contains describe, it blocks etc. and
Expect conditions.
- login.po.ts // Interacts with page elements
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.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.