Protractor repeat specs

2019-09-09 18:17发布

I have a case like this

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    specs: [
        'test/scenarios/user/login.js',
        'test/scenarios/user/choose_user_1.js',
        'test/scenarios/user/change_user.js',
        'test/scenarios/user/choose_user_2.js',
        'test/scenarios/user/change_user.js',
        'test/scenarios/user/choose_user_3.js',
        'test/scenarios/user/logout.js'
    ]
}

But protractor doesn't reuse change_user.js more than once.. I have to create change_user_1.js and change_user_2.js to get what I want.. Is there a way to deactivate this behavior, or I should do my tests differently?

Best Regards

1条回答
成全新的幸福
2楼-- · 2019-09-09 18:25

As far as i know, you cannot call same script twice. We had similar issue and here's what I did to fix it - Use jasmine-data-provider, create separate suites instead of scripts and loop through them using data provider. Here are the steps that i would follow -

  1. Install jasmine-data-provider npm package.
  2. Create two describe suites, one for choose_user and the other for change_user.
  3. Pass multiple data to these describe suites using jasmine-data-provider.
  4. Each time a choose_user - describe runs, a change_user - describe also runs next to that.

Here's a sample code -

var dp = require('../node_modules/jasmine-data-provider'); //Install the npm package and provide its path

//Data provider object to store data that script uses
var objectDataProvider = {
    'Test1': {user1: 'user_1'},
    'Test2': {user1: 'user_2'},
    'Test3': {user1: 'user_3'},
};

//Jasmine Data Provider function automatically loops through the tests - Test1, Test2, Test3
dp(objectDataProvider, function (data) {

    describe('choose_user Test:', function(){
        //Choose User specs that's applicable for one user
        //To use the objectDataProvider data use - data.user1 all the time
    });

    describe('change_user Test:', function(){
        //Change User specs that's applicable for one user
    });

});

This script should run choose_user and change_user specs 3 times and then you can continue execution with rest of the scripts in pipe.

Hope it helps.

查看更多
登录 后发表回答