0

We need the ability to run a dynamic set of spec files.

// Would be ideal, but not working
exports.config = {
    specs: () => {
        /* Load list of tests to bu run from API or from CSV file
    },
......
}

Any ideas would be appreciated.

DanDuh
  • 500
  • 1
  • 5
  • 17
  • Can you help clarify with what you mean with "load list of tests to be run from API or from CSV file". Are you getting a list back from the api or a csv file and then you want to run that particular list? – Nephi Aug 29 '19 at 09:48

2 Answers2

1

I'll answer this for JavaScript, not TS, but it'll give you an idea about your options

If you're looking to use test suites predefined somewhere, then 2 ways:

1.Protractor

In your config, do something like this

exports.config = {
    // ...

    specs: function (option) {

        let suites = require("./suites.json");

        return suites[option]
    }(process.env.SUITE)

    // ...
};

Then have your suites.json

{
  "providers": [
    "tests/providers/*.spec.js"
  ],
  "users": [
    "tests/users/*.spec.js"
  ],
  "production": [
    "tests/*/expected-configs.spec.js",
    "tests/*/environment-configuration.spec.js",

    "tests/*/last-claim-filter.spec.js",
    "tests/*/diagnosis-bh-filter.spec.js"
  ],
  "sanity": [
    "tests/*/expected-configs.spec.js",
    "tests/*/environment-configuration.spec.js",
    "tests/*/info-panel.spec.js",
    "tests/*/robohelp.spec.js"
  ]
}

And then start protractor like this SUITE="production" protractor protractor.conf.js (maybe different for Windows)

Unfortunately, you can't use CSV with this approach, and it doesn't even sound feasible. By the way, I also didn't understand what you mean about starting protractor from API

2.Grunt

This is a difficult set up, so I can't give you ready-to-use answer, but this sounds like thats what you need

Grunt is a task runner. What you'd need to do is to configure a task which will be:

  • taking parameters from command line;
  • cleaning up a folder with temporary files;
  • converting you CSV file into json into the temporary folder;
  • generating other files based on your parameters, like config
  • finding the desired test suite based on the passed parameter and pass it along to protractor, before its even started;
  • start protractor;
Community
  • 1
  • 1
Sergey Pleshakov
  • 7,964
  • 2
  • 17
  • 40
0

This might be tricky, but you can try to use getMultiCapabilities configuration method:

https://github.com/angular/protractor/blob/master/lib/config.ts#L383

Idea is - your capabilities object can have specs property: specs?: string[]; It will add specs to your specs in config, but it can be used to dynamically set them. Also you might use exclude?: string[]; to dynamically exclude some test files from run.

so code might look something like this:

exports.config = {
    specs: [] // just empty, we will override it in capabilities

    // If getMultiCapabilities is specified, both capabilities and multiCapabilities will be ignored
    getMultiCapabilities: async function () {
         // For example reading specs from HTTP response
         const request = require('request-promise-native')
         const specsFromAPI = await request.get('http://some.api/specs')
         // should return array of Capabilities objects
         return [{
             browserName: 'chrome',
             specs: specsFromAPI
         }]
    }
}
Xotabu4
  • 3,063
  • 17
  • 29