cucumberjs - Using Protractor with loops to fill in a form getting data from a Cucumber.js table -


(i have seen this discussion, not sure how apply case, i’m asking new question. hope it’s not duplicate)

i testing form written in angular using protractor cucumber.js.

so tell protractor go click on title of field (which link) then, when field appears, enter text in it, move on title of next field, , on.

here step in cucumber:

when fill form following data     | field            | content           |     | first name       | john              |     | last name        | doe               |     | address          | test address | # , forth 

here’s half-hearted attempt @ step definition:

this.when(/^i fill form following data$/, function (table, callback) {     data = table.hashes();     # gives me array of objects such one:     # [ { field: 'first name', content: 'john' },...]      (var = 0; < data.length; i++){         var el = element(by.csscontainingtext('#my-form a', data[i].field));           el.click().then(function(){                 var fieldel = el.element(by.xpath("../.."))                     .element(by.css('textarea'));                 fieldel.sendkeys(data[i].content);             });         }     };     callback(); }); 

but of course, isn't working, because before protractor has time click on field name , enter necessary data field, callback function called, , cucumber moves next step.

so question is, how can i, using protractor cucumber.js, write step insert data defined in cucumber table form fields? feasible using loop?

your loop enqueuing promises, loop finishes before "clicking" or sending of keys happens. need invoke callback after promises have resolved.

i see 2 solutions (i think). keep track of promises in array, , use protractor.promise.all (see http://spin.atomicobject.com/2014/12/17/asynchronous-testing-protractor-angular/) wait array of promises finish. first save promise in var promises = [] array:

var p = el.click().then(function(){ ... }); promises.push(p) 

then outside loop:

protractor.promise.all(promises).then(callback); 

or, can rely on controlflow keep promises ordered in loop, , call callback in last iteration of loop:

var p = fieldel.sendkeys(data[i].content); if (i === data.length - 1) { // beware: want check "i" inside loop , not in promise created in loop.      p.then(callback); } 

despite text contrary, cannot promise either of these work. @ least point in right direction.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -