2

I need to get a value from excel file when status column value is “Y” and I wanted to return the value from Name Column to the calling function and excel sheet contains the data is as follows

Name Number status YYYY 1234 N XXXXX 3456 Y

Function I have written like this

var Excel = require(‘exceljs’);

var workbook = new Excel.Workbook();
var selectStatus = ’’;

module.exports = function() {
    return actor({
        trimSelectName: function() {
            workbook.xlsx.readFile("E:/testData.xlsx")
                .then(function(sheetName) {
                    // use workbook
                    i = 1;
                    try {
                        var workSheet = workbook.getWorksheet("trim");
                        workSheet.eachRow({
                            includeEmpty: false
                        }, function(row, rowNumber) {
                            if (i == 1) {
                                i = 0;
                            } else {
                                currRow = workSheet.getRow(rowNumber);
                                console.log("Name :" + currRow.getCell(1).value + ", Number :" + currRow.getCell(2).value +
                                    "Select Status :" + currRow.getCell(3).value);
                                selectStatus = currRow.getCell(3).value;
                                if (selectStatus == "Y") {
                                    return selectStatus;
                                }


                            }

                        });
                    } catch (Error) {
                        console.log(Error);
                    }

                });

        },
    });

};

But I am trying to the print value from the calling function, I am always getting it as undefined

Calling function:

const selected = trimDataSelection.trimSelectName();

Could you please let me know where could be the issue?

Paul Vincent Beigang
  • 2,700
  • 2
  • 13
  • 28
Sudhakar
  • 21
  • 2
  • 1
    CodeceptJS is a framework for unit testing websites. Can you explain how it relates to this? – JLRishe Nov 13 '19 at 13:49
  • @JLRishe is an acceptance test framework, not a unit test framework. The question relates because the author want to implement this as a CodeceptJS step, spot the "actor" in the code. See https://codecept.io/pageobjects#actor. – Paul Vincent Beigang Nov 13 '19 at 13:58

1 Answers1

1

As I see your function returns actor object, I assume you are using steps_file generated by codeceptjs which is used to extend "I" object in order to add your custom functions. So if you want to invoke your custom function from scenario you should call it like this:
const selected = I.trimSelectName()

aefluke
  • 178
  • 1
  • 5