我一直收到这条消息,说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
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();
答案 0 :(得分:2)
您的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;
答案 1 :(得分:1)
const getCurrentMoves = createSelector(getCurrentMoveIds, getMoveEntities, (ids, entities) => ids.map(id => entities[id])); const getCurrentMovesLoadIds = createSelector(getCurrentMoveEntities, (entities) => entities.map(entity => entity.load_id)); const getCurrentMoveLoads = createSelector(getCurrentMoveLoadIds, getLoadEntities, (ids, entities) => ids.map(id => entities[id]));
这是因为Failed: newPageObj Object not defined
变量的范围 - 目前只在newPageObj
的范围内定义。在更高级别声明您的变量:
beforeAll