【发布时间】:2016-08-25 09:32:31
【问题描述】:
我们是否应该为 Protractor 中基于页面对象模式的测试中的可重用方法编写回调/承诺?
例如 .. 我有以下测试代码和页面对象,它工作正常,没有问题。但是我应该为页面类中的可重用方法添加回调吗?
describe('This is a test suite for Login cases',function(){
beforeEach(function() {
LoginPage.goHome();
LoginPage.doLogin();
});
afterEach(function() {
LoginPage.doLogout();
});
it('Scenario1_Login_VerifyFirstName',function(){
//Some Test step
});
页面类:
var Login = {
PageElements: {
emailInput: element(by.css('.email')),
passwordInput: element(by.css('.password')),
loginForm: element(by.css('.form')),
logout: element(by.linkText('LOG OUT'))
},
goHome: function goHome() {
browser.get('/signin');
browser.driver.manage().window().maximize();
},
doLogin: function doLogin() {
this.PageElements.emailInput.sendKeys(UserName);
this.PageElements.passwordInput.sendKeys(Password);
this.PageElements.loginForm.submit();
},
doLogout: function doLogout() {
browser.wait(EC.elementToBeClickable(this.PageElements.profileLink));
this.PageElements.profileLink.click();
this.PageElements.logout.click();
}
};
module.exports = Login;
【问题讨论】:
-
除非您有特定原因,否则您不需要添加回调
-
@SureshSalloju 现在我们只有 webdriverJs 命令,它们由于 ControlFlow 而被链接起来。但是如果我们有非 webdriverjs 操作怎么办。另外,是否可以在没有回调的情况下返回值?
标签: javascript node.js protractor pageobjects