Protractor repeat specs

独自空忆成欢 提交于 2019-12-11 23:57:40

问题


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:


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.



来源:https://stackoverflow.com/questions/34811825/protractor-repeat-specs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!