[英]Recursive function not getting executed in protractor-cucumber
我想在转发器组件中填充一组数据。 我正在传递需要填充数据的行数,然后从json传递一行的所有列的数据[此数据将在多行中重复]
在某些行(例如10行)之后有分页功能,然后在移动到中继器的下一页后,我必须继续在后续页中输入数据。
我面临的问题:
通过json作为步骤定义的论据不起作用[必须传递硬编码值,我想在_.each中传递rowRepeaterData]
尽管所有的Promise正在异步运行,但数据会在第一页中正确填充,promise.all等待Promise被解决。 递归函数再次被调用并可以正常工作,但是promise.all不会等待并且应用程序被关闭,而我可以看到promise失败了,因为元素不可用。
this.fillRowRepeaterData= function(rowRepeaterData,rowRepeaterVariable,rows, currentRow) { var counter = currentRow, //activity=JSON.parse(rowRepeaterData), promises = []; while (counter < rows) { _.each(rowRepeaterJson.individualIncludedExcludedWCApp, function (item) { var element = ('.rowRepeater-' + rowRepeaterVariable + ' .' + 'row' + counter + ' .formFieldComponent-' + item.locator); promises.push(commonUtilitiesObject.waitFor(by.css(element)).then(function () { console.log('Inside Promise...'); if (item.fieldType === 'dropdown') { return formUtil.makeSelectionFromSearchableDropdown(item.value, element); } else if (item.fieldType === 'textInputBox') { return formUtil.sendText(by.css(element), item.value); } })) }); counter++; if (counter % 10=== 0){ break; } } return Promise.all(promises).then(function (resolve) { var nextPageButton = '.rowRepeater-' + rowRepeaterVariable + ' .pagingContainer .nextPageButton'; if (counter < rows){ commonUtilitiesObject.click(by.css(nextPageButton)).then (function(){ this.fillRowRepeaterData(rowRepeaterData, rowRepeaterVariable, rows, counter); }.bind(this)); } else { console.log('Final resolve'); resolve(true); } }.bind(this)); }.bind(this);
JSON: { "individualIncludedExcludedWCApp" : [ {"fieldType":"textInputBox","locator":"locationNumber", "value":1}, {"fieldType":"textInputBox","locator":"excludedName", "value":"TestRowRepeater"}, {"fieldType":"textInputBox","locator":"excludedDateOfBirth", "value":"01/01/2018"}, {"fieldType":"textInputBox","locator":"excludedTitle", "value":"Partner"}, {"fieldType":"textInputBox","locator":"excludedOwnershipPercentage", "value":50}, {"fieldType":"textInputBox","locator":"excludedDuties", "value":"Testing of row repeater"}, {"fieldType":"textInputBox","locator":"excludedRemuneration", "value": 12500} ] }
this.When(/^user fills data in the "([^"]*)" rows of the "([^"]*)" row repeater$/, function (rowNumber,rowRepeaterVariable){ var rowsToFillData = rowNumber, rowRepeaterData = 'rowRepeaterJson.' +rowRepeaterVariable; return rowRepeaterUtil.fillRowRepeaterData(rowRepeaterData,rowRepeaterVariable,rowsToFillData,0); });
您缺少返回值,否则,fillRowRepeaterData的调用方将不会等待promise.all promise.all(...).then(...)
的异步内容完成。
if (counter < rows) {
return commonUtilitiesObject.click(by.css(nextPageButton)).then(function() {
^^^^^^
return this.fillRowRepeaterData(rowRepeaterData, rowRepeaterVariable, rows, counter);
^^^^^^
}.bind(this));
} else {
...
}
而且, resolve
是胡说八道。 .then()
回调公开数据,而不是函数。
Promise.all(promises).then(function(this_would_be_an_array_of_data_delivered_by_the_promises_passed_to_Promise.all) {...});
新的Promise的构造函数公开了resolve
(和reject
),但是您(正确地)没有创建新的Promise。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.