当调用for for循环时,不会调用另一个js文件中的函数

时间:2018-03-26 15:59:07

标签: node.js for-loop protractor

我在另一个js文件“Login.js”中有一些函数,当我在for循环中调用那些函数时,它们没有执行。如果我没有循环调用它的工作正常。任何帮助将不胜感激。我的specs.js下面的脚本

it('and Login to MSIX', function () {
 var workbook = new excelData.Workbook();
    var converted;
    var data = [];
    workbook.xlsx.readFile('./tests/e2e/TestData/Testcase_data_v1.xlsx').then(function () {
var worksheet = workbook.getWorksheet('Reports');
browser.waitForAngular();
    for (i = 2; i <= 4; i++) {
      for (j = 1; j <= 5; j++) {
          var cellvalue = worksheet.getRow(i).getCell(j).value;
          var converted = JSON.stringify(cellvalue);
          data.push(converted);
      }
      username = data[0];
      password = data[1];
      userType =  data[2];

    });
    browser.waitForAngular();
    // call login scripts
    login.fillUsername(username);
    login.fillPassword(password);
    login.clickSignup();
    browser.waitForAngular();
    login.clickPrivacy();
    browser.waitForAngular();
    console.log("User " + username + " with user type "+userType+" logged in successfully");
    data = [];
  };
  });
});

1 个答案:

答案 0 :(得分:0)

最后,我使用以下代码进行了此操作。

var excelData = require('exceljs');

module.exports = function() {
    return new Promise(function (resolve, reject) {
        var workbook = new excelData.Workbook();
        var converted;
        var data = [];
        workbook.xlsx.readFile('./tests/e2e/TestData/Testcase_data_v1.xlsx').then(function () {
            var worksheet = workbook.getWorksheet('Reports');
            var rowno = worksheet.rowCount;
            var colno = worksheet.columnCount;
            console.log(rowno, colno);
            for (var i = 2; i <= 4; i++) {
                for (var j = 1; j <= 5; j++) {
                    var cellvalue = worksheet.getRow(i).getCell(j).value;
                    data.push(cellvalue);
                }
            }
            return resolve(data);
        });
    });
}

在specs.js中我做了如下

var exRead = require('./readExcel');

describe('MSIX Smoke', function () {
  var userList = [];

  beforeAll(function(done) {

    browser.get('url');  //Dev url
    expect(browser.getTitle()).toEqual('title');
    exRead().then(function(excelData) {
      userList = prepData(excelData);
      done();
    });

  });