常见的量角器测试场景能否实现一次?

Can Common Protractor Test Scenarios be Implemented Once?

有没有办法实现一个量角器测试用例,比如登录场景,一次而不是每次需要用户登录的测试?我知道使用页面对象可以更轻松地测试登录,但如果只登录一个人然后 运行 我所有的测试然后将用户注销一次然后为每个 'it' 执行它会很好测试块。

// 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);
    });
});