Using external file for suite names in protractor

左心房为你撑大大i 提交于 2019-12-25 07:13:36

问题


I need some help to parameterize my test suites.

I want to create a Json file Suites.json and define suites in this file

module.exports = {
Suites: 
Smoke: 'File1.spec.js','File2.spec.js',
Main: 'File1.spec.js','File2.spec.js','File3.spec.js'
}

Now i want to use this Json file in protractor.conf.js I imported JSON file:

var SuiteFile = require('../Suites.json')

Now if i want to us in my actual Conf file, i am not sure how to use it.

Should i just say:

suites: SuitesFile

Can someone please confirm?


回答1:


Yes, it is definitely possible to do something like this. Please refer my blog post for more info

Step 1: Create a js file with suites

module.exports = {
suitesCollection: {
    smoke: ['File1.spec.js','File2.spec.js',],
    sanity: ['File1.spec.js','File2.spec.js','File3.spec.js'],
    demo: ['demo.js']
}
}

Step 2: Import the js file and point the exports.config.suites to use the info from this file

var suitesFile = require('./suites.js');

exports.config = {
    suites: suitesFile.suitesCollection,

UPDATE: In case there is a need to use Json feed for suites, please refer below

Step 1: Create a JSON file with Key-Value pairs of suites

{
  "smoke": "demo.js,demo2.js",
  "sanity": "demo2.js,demo.js,demo3.js",
  "demo": "demo.js"
}

Step 2: Import the JSON and edit the config file accordingly. In case you want the suite names also generated, create a custom function to iterate the JSON and build suites

var suitesJson = require('./suites.json');

    exports.config = {
    suites: {
    smoke: suitesJson.smoke.split(","),
    sanity: suitesJson.sanity.split(","),
    demo: suitesJson.demo.split(",")
},

OR In case you need to completely construct Suites object out of JSON (when you dont even know suite names)

Protractor Config File

var suitesJson = require('./suites.json');
var suitesAll = {}
for(var myKey in suitesJson) {
    suitesAll[myKey] = suitesJson[myKey].split(",");
}
    exports.config = {
    suites: suitesAll,


来源:https://stackoverflow.com/questions/39758088/using-external-file-for-suite-names-in-protractor

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