普通量角器测试方案可以实施一次吗?

时间:2015-06-01 18:12:50

标签: angularjs protractor angularjs-e2e

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

1 个答案:

答案 0 :(得分:1)

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

OR

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