我正在构建针对页面对象模式的 angularjs Protractor e2e 测试。我在将脚本转换为页面对象时遇到了麻烦。
这是我的conf.js
// conf.js
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['employee.js']
}
这是我的employee.js
// spec.js
var EmpPageObject = require('./EmpPageObject.js');
describe('Protractor Demo App', function() {
it('should have a title', function() {
var empPageObject = new EmpPageObject();
empPageObject.get();
empPageObject.setName('mee');
empPageObject.setPassword('123');
});
});
这是我的EmpPageObject.js
var EmpPageObject = function() {
var nameInput = element(by.model('login.user_name'));
var passwordInput = element(by.model('login.password'));
var addButton = element(by.css('.btn'));
this.get = function() {
browser.get('http://');
};
this.setName = function(name) {
nameInput.sendKeys(name);
};
this.setPassword = function(password) {
passwordInput.sendKeys(password);
};
addButton.click();
};
但是,我的脚本失败并出现以下错误。
Failures:
1) Protractor Demo App should have a title
Message:
Failed: EmpPageObject is not defined
这可能是一个愚蠢的问题。但是,我找不到错误,因为这是我的第一次测试。 :)
最佳答案
看起来您是从这里复制粘贴代码的 https://github.com/angular/protractor/blob/f9c8a37f7dbec1dccec2dde0bd6884ad7ae3f5c7/docs/tutorial.md
describe('Protractor Demo App', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
这是 Protractor
尝试获取资源并检查 - 它是否有标题。
该函数返回 true 或 false 进行测试。在您的情况下,函数返回undefined
,它等于 false,测试失败,您会收到错误消息。
关于javascript - Protractor 页面对象错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40374069/