代码之家  ›  专栏  ›  技术社区  ›  Jonathan

对象不是构造函数量角器Java脚本

  •  0
  • Jonathan  · 技术社区  · 7 年前

    我一直收到这样一条消息,说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
    

    量角器控制台消息 enter image description here

    新建页面。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();
    

    已更改为模块。导出=新建页面;//这项工作现在我得到了 enter image description here

    2 回复  |  直到 7 年前
        1
  •  2
  •   Ayush Gupta    7 年前

    你的 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;
    
        2
  •  1
  •   alecxe    7 年前

    Failed: newPageObj Object not defined

    这是因为 的范围 newPageObj 变量 -目前仅在 beforeAll . 在更高级别声明变量:

    var newPage = require('./newPage.js');
    
    var newPageObj;
    
    describe('Get Payroll Information', function() {
        beforeAll(function() {
            newPageObj = new newPage();
        });
    
        // ...
    });