我正在使用页面对象文件(login.po.js)和测试规范文件(test.spec.js)创建webdriver.io自动化,但是当我调用它时似乎无法识别该对象它在测试规范文件(test.spec.js)上,显示错误LoginPage.username.setValue is not a function
。
下面是我的代码:
login.po.js
var LoginPage = {
username: { get: function () { return $('#email'); } },
password: { get: function () { return $('#password'); } },
form: { get: function () { return $('#login'); } },
flash: { get: function () { return $('#flash'); } },
submit: { value: function() {
this.form.click();
} }
};
module.exports = LoginPage;
test.spec.js
var LoginPage = require('../page/login.po');
const userObj = {
user: '[email protected]',
password: 'password',
}
var assert = require('assert');
describe('login form', () => {
it('should deny access with wrong creds', function () {
LoginPage.username.setValue('username');
LoginPage.password.setValue('password');
LoginPage.submit();
browser.pause(5000);
expect(LoginPage.flash.getText()).to.contain('Your username is invalid!');
});
it('should allow access with correct creds', function () {
LoginPage.username.setValue(userObj.user);
LoginPage.password.setValue(userObj.password);
LoginPage.submit();
browser.pause(5000);
expect(LoginPage.flash.getText()).to.contain('You logged into a secure area!');
});
});
运行时出现的错误是:
1) login form should deny access with wrong creds
LoginPage.username.setValue is not a function
TypeError: LoginPage.username.setValue is not a function
at Context.<anonymous> (D:\MyTest00\specs\test.spec.js:31:28)
at Context.executeSync (D:\MyTest00\node_modules\@wdio\sync\build\index.js:56:18)
at D:\MyTest00\node_modules\@wdio\sync\build\index.js:82:70
2) login form should allow access with correct creds
LoginPage.username.setValue is not a function
TypeError: LoginPage.username.setValue is not a function
at Context.<anonymous> (D:\MyTest00\specs\test.spec.js:45:28)
at Context.executeSync (D:\MyTest00\node_modules\@wdio\sync\build\index.js:56:18)
at D:\MyTest00\node_modules\@wdio\sync\build\index.js:82:70
非常感谢您的协助,如果您还在我的代码中发现其他问题,请帮助我进行纠正,非常感谢
更改login.po.js中的最后一行代码>
exports.LoginPage = LoginPage;
显示错误:
中的第一行代码:1) login form should deny access with wrong creds Cannot read property 'setValue' of undefined TypeError: Cannot read property 'setValue' of undefined at Context.<anonymous> (D:\MyTest00\specs\test.spec.js:20:28) at Context.executeSync (D:\MyTest00\node_modules\@wdio\sync\build\index.js:56:18) at D:\MyTest00\node_modules\@wdio\sync\build\index.js:82:70 2) login form should allow access with correct creds Cannot read property 'setValue' of undefined TypeError: Cannot read property 'setValue' of undefined at Context.<anonymous> (D:\MyTest00\specs\test.spec.js:28:28) at Context.executeSync (D:\MyTest00\node_modules\@wdio\sync\build\index.js:56:18) at D:\MyTest00\node_modules\@wdio\sync\build\index.js:82:70
编辑test.spec.js
var LoginPage = require('../page/login.po').LoginPage
仍然显示错误:
1) login form should deny access with wrong creds
LoginPage.username.setValue is not a function
TypeError: LoginPage.username.setValue is not a function
at Context.<anonymous> (D:\MyTest00\specs\test.spec.js:31:28)
at Context.executeSync (D:\MyTest00\node_modules\@wdio\sync\build\index.js:56:18)
at D:\MyTest00\node_modules\@wdio\sync\build\index.js:82:70
2) login form should allow access with correct creds
LoginPage.username.setValue is not a function
TypeError: LoginPage.username.setValue is not a function
at Context.<anonymous> (D:\MyTest00\specs\test.spec.js:45:28)
at Context.executeSync (D:\MyTest00\node_modules\@wdio\sync\build\index.js:56:18)
at D:\MyTest00\node_modules\@wdio\sync\build\index.js:82:70
我正在使用页面对象文件(login.po.js)和测试规范文件(test.spec.js)创建webdriver.io自动化,但是当我调用它时似乎无法识别该对象它在测试规范上...
请查看我所做的更改。进出口有问题