angular - Should I make Protractor E2E Test completely synchronous -
brief: trying make e2e test in angular 2 synchronous
protractor wrapper around jasmine adds support promises in e2e tests, devs didn't have create lot of nested async callbacks, async hell. presume protractor encourages devs make tests synchronous.
quotation here: https://blog.liip.ch/archive/2015/01/28/angularjs-end-to-end-testing-with-protractor.html
it important note protractor entirely asynchronous, api methods return promises. under hood, protractor uses selenium’s control flow (a queue of pending promises) allow write tests in pseudo-synchronous way. protractor smart enough make work.
this how people confused this.
- dealing synchronously in protractor tests
- https://github.com/angular/protractor/issues/673#issuecomment-125599377
so, there still cases when devs should deal async methods in tests, e.g. need href attribute of link , check if has id @ end of it, must define callback attribute's value, parse , after check if has id or not.
$('a').getattribute("href").then((url) => { expect(url.substring(url.lastindexof('/'), url.length)).not.tobenan(); });
as result, test not synchronous , straightforward anymore.
question: should move method test page object , try make synchronous?
// page object getimageid() { let attribute = null; let link = element(by.css('app-image-container .edit-image a')); link.getattribute('href').then((data) => { attribute = data; }); browser.wait(() => { return attribute != null; }); return attribute; } // test synchronous expect(page.getimageid()).not.tobenan();
Comments
Post a Comment