gpt4 book ai didi

javascript - 对象不是构造函数 Protractor Javascript

转载 作者:行者123 更新时间:2023-11-28 17:40:26 26 4
gpt4 key购买 nike

我不断收到这样的消息,说 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

Protractor 控制台消息 enter image description here

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;//现在我明白了 enter image description here

最佳答案

您的newPage.js正在导出一个对象,而不是函数/类/构造函数。将 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com