我不断收到这样的消息,说Newpage不是构造函数,在过去的5个小时中我全神贯注地尝试解决此问题,但没有任何进展,我查看了以下网站
How to call a function in another function in protractor

'TypeError: undefined is not a function' using Protractor
也许这是我不知道的简单事情。我要做的就是从页面目标文件中调用一个函数。仍然没有成功,任何帮助将不胜感激。

我的代码:

var newPage = require('./newPage.js');

describe('Get Payroll Information', function() {

  beforeAll(function(){
        var newPageObj = new newPage();
    });

          var EC = protractor.ExpectedConditions;
          var status;
          var clientid, weeknum, pdate;


it('Get CycleStatus, Paydate, Weeknumber, Clientid - completed', function () {
              const fs = require('fs');
              const cycle = $('#cycleStatusID'); // cycle status
              const client = $('#clientID'); // clientid
              const week = $('#companyIdBar_weekId'); // week number
              const payDate = $('#companyIdBar_processDateId');


                //------------Get PayDate --------------------------------
                              .then(() => {
                              payDate.isPresent().then(function(present){
                                if(present){
                                       payDate.getText().then(function(text){
                                         pDate = text;
                                        console.log('paydate (' + pDate + ') is displayed');
                                      });
                                          } else {
                                            console.log('pay date not present');
                                            //return;// breaks for loop like (break)
                                        }
                                      })
                                    })
                                  .then(() => {
                                      writeValueToFile(cycleStatus,clientID,weekNum,pDate);
                                  })
                                  .then(() => {
                                      newPageObj.goBack();
                                      console.log('return to support');
                                  });


                    });// master then promise

              });//spec function


量角器控制台消息
javascript - 对象不是构造函数 Protractor Javascript-LMLPHP

newPage.js代码:

newPage = function(){
    function goBack(){
      var returnbtn = $('#returnToADPClick');
      var search1 = ($$('input[id="toolbarQuickSearch"]').get(0));
      returnbtn.click();
      browser.wait(EC.elementToBeClickable(search1),20,000);
};
};
module.exports = new newPage();


更改为module.exports = new newPage; //现在我得到了这项工作
javascript - 对象不是构造函数 Protractor Javascript-LMLPHP

最佳答案

您的newPage.js正在导出对象,而不是function/class/constructor。像这样将module.exports更改为newPage

newPage = function(){
    function goBack(){
      var returnbtn = $('#returnToADPClick');
      var search1 = ($$('input[id="toolbarQuickSearch"]').get(0));
      returnbtn.click();
      browser.wait(EC.elementToBeClickable(search1),20,000);
};
};
module.exports = newPage;

关于javascript - 对象不是构造函数 Protractor Javascript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48066729/

10-10 22:34