Я создаю автоматизацию webdriver.io с файлом объекта страницы (login.po. js) и файлом test spe c (test.spe c. js), но, похоже, чтобы не быть в состоянии распознать объект, когда я вызываю его в тестовом файле spe c (test.spe c. 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.spe c. js
var LoginPage = require('../page/login.po');
const userObj = {
user: 'username@email.com',
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.spe c. 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
GitHub репозиторий для полного кода на это: github.com/seanray7/pageobject-webdriverio