第一页对象
/* save the file in 'pages/loginPage'
var LoginPage = function(){
};
/*Application object properties*/
LoginPage.prototype = Object.create({}, {
userName: {
get: function() {
return browser.driver.findElement(By.id('userid'));
}
},
userPass: {
get: function() {
return browser.driver.findElement(By.id('password'));
}
},
submitBtn: {
get: function() {
return browser.driver.findElement(By.id('btnSubmit'));
}
}
});
/* Adding functions */
LoginPage.prototype.login = function(strUser, strPass) {
browser.driver.get(browser.baseUrl);
this.userName.sendKeys(strUser);
this.userPass.sendKeys(strPass);
this.submitBtn.click();
};
module.exports = LoginPage;
让我们在测试中使用我们的第一页目标文件。
var LoginPage = require('../pages/loginPage');
describe('User Login to Application', function() {
var loginPage = new LoginPage();
beforeAll(function() {
loginPage.login(browser.params.userName, browser.params.userPass);
});
it('and see a success message in title', function() {
expect(browser.getTitle()).toEqual('Success');
});
});