0

I want to fill a set of data in a repeater component. I am passing number of rows in which data needs to be filled and then passing data from json for all the columns of a row [this data will be repeated in mulitple rows]

There's pagination feature after some set of rows say 10 and then I have to continue entering the data in subsequent pages after moving to the next page in the repeater.

Issues I am facing:

  • Passing json as a arguement from step definition is not working [Had to pass hard coded value, I want to pass rowRepeaterData in _.each]

  • Data gets filled correctly in the first page though all the promises are working async, promise.all waits for the promises to get resolved. Recursive function gets called again and works fine but promise.all doesn't waits and application gets closed while I can see promises failing afterwards as elements are not available.

    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);
    });
Roamer-1888
  • 19,138
  • 5
  • 33
  • 44
AnuragT
  • 23
  • 3

1 Answers1

0

You have missing returns, without which fillRowRepeaterData's caller will not wait for the asynchronous stuff in promise.all(...).then(...) to complete.

if (counter < rows) {
    return commonUtilitiesObject.click(by.css(nextPageButton)).then(function() {
    ^^^^^^
        return this.fillRowRepeaterData(rowRepeaterData, rowRepeaterVariable, rows, counter);
        ^^^^^^
    }.bind(this));
} else {
    ...
}

Also, resolve is a nonsense. A .then() callback exposes data, not a function.

Promise.all(promises).then(function(this_would_be_an_array_of_data_delivered_by_the_promises_passed_to_Promise.all) {...});

resolve (and reject) are exposed by a new Promise's constructor but you are (quite correctly) not creating a new Promise.

Roamer-1888
  • 19,138
  • 5
  • 33
  • 44
  • You shouldn't need `new Promise()`. With it, you have, in all probability, introduced the [explicit Promise construction anti-pattern](https://stackoverflow.com/questions/23803743/) – Roamer-1888 Nov 02 '18 at 18:33