递归函数未在量角器黄瓜中执行

时间:2018-11-01 10:46:10

标签: javascript promise 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);
    });

1 个答案:

答案 0 :(得分:0)

您缺少返回值,否则,fillRowRepeaterData的调用方将不会等待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) {...});

resolve(和reject)由新的Promise的构造函数公开,但您(很正确)没有创建新的Promise。