NewWorld
NewWorld

Reputation: 764

Using external file for suite names in protractor

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?

Upvotes: 0

Views: 1386

Answers (1)

AdityaReddy
AdityaReddy

Reputation: 3645

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,

Upvotes: 4

Related Questions