我正在使用 protractor ,并创建了一个页面对象。
这是我的页面对象:
'use strict';
var CreateAgent = function () {
this.agentEmail = element(by.model('agent.email'));
this.janrainConsoleAgent = by.xpath(".//*[@value='ccp_agent']");
this.janrainConsoleAgentManager = by.xpath(".//* .[@value='ccp_agent_manager']");
this.saveButton = by.className('md-primary md-raised md-button md-ink-ripple');
this.addEmail = function(email){
this.agentEmail.sendKeys(email);
};
this.selectRole = function(role){
switch(role){
case 'ccp agent':
this.janrainConsoleAgent.click();
case 'ccp agent manager':
this.janrainConsoleAgentManager.click();
default:
break;
}
};
this.saveAgent = function(){
this.saveButton.click();
};
};
module.exports = CreateAgent;
该函数正在调用规范
规格如下:
var createAgent = require('../page/create_agent_page');
describe('Protractor Demo Janrain - Create Agent', function(){
it('should fill out information to create agent', function(){
createAgent.addEmail('[email protected]');
browser.sleep(3000);
createAgent.selectRole('ccp agent manage');
browser.sleep(3000);
createAgent.saveAgent();
browser.sleep(7000);
});
});
但是当我执行测试时,却给我一个错误:
Failures:
1) Protractor Demo Janrain - Create Agent should fill out information to create agent
Message:
Failed: createAgent.addEmail is not a function
Stack:
TypeError: createAgent.addEmail is not a function
我不确定页面对象或其他地方是否缺少某些内容。
希望你能帮助我,谢谢。
最佳答案
将module.exports = CreateAgent;
更改为module.exports = new CreateAgent();
。您需要创建一个CreateAgent函数的新实例,以访问该函数内的所有方法。
关于javascript - Protractor -页面对象:失败:不是函数,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42985803/