angularjs - Protractor - Page Object is not updating when the DOM elements are changed -
i testing spa built angular.js , im using page objects pattern write tests. in app have number of lists updated. example there list of attachments update when ever attachments added/removed. add attachment have modal window , when upload file , click ok. file uploads , lists update.
i have written 2 page objects, 1 upload modal window , other 1 preview of attachment list. in tests first current count of attachments click on button activate modal window , attach file. take count of attachments in preview page , compare incremented 1. tests fails. page object not updated , still shows attachment count 2.
test
it('should attach file when file selected , ok button pressed.', function () { var currentfilecount = viewmeetingtabpage.getmeetingattachmentcount(); viewmeetingpage.clickaddattachmentbutton(); addattchmentpage.attachfile(); addattchmentpage.clickconfimattachfilebutton(); currentfilecount.then(function (curcount) { viewmeetingtabpage.getmeetingattachmentcount().then(function (newcount) { expect(newcount).tobe(curcount + 1); //expect(viewmeetingtabpage.getmeetingattachmentname()).tobe('test-file.pdf'); }); }); });
viewmeetingtabpage
this.getmeetingattchments = function () { return element.all(by.repeater('attachment in meeting.attachmentviewmodellist track $index')); }; this.getmeetingattachmentcount = function () { return this.getmeetingattchments().count(); };
what need have somehow update page object after upload file. how can that.
this how control-flow works. executing code test queues bunch of promises. resolved in order added flow while each of them waits previous finish.
it('should attach file when file selected , ok button pressed.', function () { # queues count promise var currentfilecount = viewmeetingtabpage.getmeetingattachmentcount(); # queues other promises start # executed once 1 above finishes viewmeetingpage.clickaddattachmentbutton(); addattchmentpage.attachfile(); addattchmentpage.clickconfimattachfilebutton(); # piece of code branches-off control-flow # , gets executed after currentfilecount resolved # i.e. before clickaddattachmentbutton currentfilecount.then(function (curcount) { # that's why newcount equals curcount, # counting same number of elements # since nothing changed in meantime viewmeetingtabpage.getmeetingattachmentcount().then(function (newcount) { expect(newcount).tobe(curcount + 1); //expect(viewmeetingtabpage.getmeetingattachmentname()).tobe('test-file.pdf'); }); }); });
currentfilecount
considered setup phase test can extract beforeeach
block:
var initialfilecount; beforeeach(function() { viewmeetingtabpage.getmeetingattachmentcount().then(function(count) { initialfilecount = count; }); }); it('should attach file when file selected , ok button pressed.', function () { viewmeetingpage.clickaddattachmentbutton(); addattchmentpage.attachfile(); addattchmentpage.clickconfimattachfilebutton(); expect(viewmeetingtabpage.getmeetingattachmentcount()).tobe(initialfilecount + 1); });
since protractor patches jasmine wait between test-blocks control-flow empty, work.
keep in mind expect
patched handle promises don't need place in then
.
update:
actually, shouldn't need beforeeach
above, supposed work too:
var initialfilecount; it('should attach file when file selected , ok button pressed.', function () { viewmeetingtabpage.getmeetingattachmentcount().then(function(count) { initialfilecount = count; }); viewmeetingpage.clickaddattachmentbutton(); addattchmentpage.attachfile(); addattchmentpage.clickconfimattachfilebutton(); expect(viewmeetingtabpage.getmeetingattachmentcount()).tobe(initialfilecount + 1); });
it's called framing in webdriverjs user’s guide.
Comments
Post a Comment