【问题标题】:Can Common Protractor Test Scenarios be Implemented Once?通用量角器测试场景可以实现一次吗?
【发布时间】:2015-07-07 04:02:58
【问题描述】:

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

【问题讨论】:

    标签: angularjs protractor angularjs-e2e


    【解决方案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);
        });
    });
    

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-24
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 2014-10-20
    • 1970-01-01
    相关资源
    最近更新 更多