量角器重复规格 [英] Protractor repeat specs
问题描述
我有这样的情况
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'
]
}
但是量角器不会多次使用change_user.js. 我必须创建change_user_1.js和change_user_2.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?
最好的问候
推荐答案
据我所知,您不能两次调用同一脚本.我们遇到了类似的问题,这是我要解决的问题-使用 jasmine-data-provider
,创建单独的套件而不是脚本,然后使用数据提供程序遍历它们.这是我要遵循的步骤-
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 -
- 安装
jasmine-data-provider
npm软件包. - 创建两个
describe
套件,一个用于choose_user
,另一个用于change_user
. - 使用
jasmine-data-provider
将多个数据传递给这些描述套件. -
choose_user
-describe
每次运行时,change_user
-describe
也会在其旁边运行.
- Install
jasmine-data-provider
npm package. - Create two
describe
suites, one forchoose_user
and the other forchange_user
. - Pass multiple data to these describe suites using
jasmine-data-provider
. - Each time a
choose_user
-describe
runs, achange_user
-describe
also runs next to that.
这是示例代码-
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
});
});
此脚本应运行choose_user
和change_user
规范3次,然后您可以继续执行管道中的其余脚本.
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.
希望有帮助.
这篇关于量角器重复规格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!