【发布时间】:2015-07-07 04:02:58
【问题描述】:
有没有办法实现量角器测试用例,比如登录场景,一次而不是每次需要用户登录的测试?我知道使用页面对象可以更轻松地测试登录,但是最好只登录一个人然后运行我的所有测试然后将用户注销一次然后为每个“it”测试块执行此操作。
【问题讨论】:
标签: angularjs protractor angularjs-e2e
有没有办法实现量角器测试用例,比如登录场景,一次而不是每次需要用户登录的测试?我知道使用页面对象可以更轻松地测试登录,但是最好只登录一个人然后运行我的所有测试然后将用户注销一次然后为每个“it”测试块执行此操作。
【问题讨论】:
标签: angularjs protractor angularjs-e2e
// if you want to login and logout before every 'it' statement:
var loginPage = require('./login.js');
describe('this test spec', function() {
beforeEach(function() {
loginPage.login();
});
afterEach(function() {
loginPage.logout();
});
it('should log in and out with the first test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
it('should log in and out with the second test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
});
或
// if you want to login before every 'spec' file and stay logged in:
// in protractor.conf.js
// in exports.config
onPrepare: function() {
var blahBlah = require('./login.js');
blahBlah.login();
}
describe('this test spec', function() {
it('should log in before the first test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
it('and stay logged in for the second test', function() {
expect(loginPage.isLoggedIn()).toBe(true);
});
});
【讨论】: