我们是否应该为 Protractor 中基于页面对象模式的测试中的可重用方法编写回调/ promise ?
例如 .. 我有下面的测试代码和页面对象,它工作正常没有问题。但是我应该为页面类中的可重用方法添加回调吗?
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;
最佳答案
是的,你可以。
通过简单地返回值或 promise :
goHome: function() {
browser.get('/home');
return browser.getTitle();
},
并且应该在“it” block 内的规范级别解决它们,如下所示:
it('Page should have a title', function() {
expect(Page.goHome()).toEqual('Home Page');
});
关于javascript - Protractor 中可重用方法的回调/ promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39141600/