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.

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

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -