Passing Node.JS run params via Travis CI API

70 views Asked by At

I'm trying to setup a nice and customizable testing environment for my company using TestRail + Travis CI + a Selenium-based testing app. I want to be able to use the Travis CI Api v3 to trigger the Node.JS app to run. Ideally I'd be able to specify an email / password in the API request that the Node app will use to do all the tests with. I'm going to use TestRail's UI Script to trigger the Travis CI Api with the correct params.

Currently I have lots of scripts in the package.json file that runs the tests in certain environments. The conf.js file parses these params and sets up the application accordingly.

"test:susa:prod:b2c": "node node_modules/protractor/bin/protractor ./conf.js --disableChecks=flag --params.region=susa --params.run=prod  --params.app=b2c --params.conf=headlesschrome",
"test:susa:qa:admin": "node node_modules/protractor/bin/protractor ./conf.js --disableChecks=flag --params.region=susa --params.run=qa --params.app=corp --params.conf=headlesschrome",
"test:susa:prod:corp": "node node_modules/protractor/bin/protractor ./conf.js --disableChecks=flag --params.region=susa --params.run=prod --params.app=admin --params.conf=headlesschrome"

It would be really nice if I could also pass these params in via the Travis CI Api also.

1

There are 1 answers

2
Sergey Pleshakov On

Never worked in Travis but I can imagine it's same as Jenkins.

So what I'd do in Jenkins from bottom to top:

  • make sure protractor can accept parameters (any: email, password, env, userrole if needed). One way is what you're doing with --params.var flag. Limitation though, you can't make config file configurable, since variables become available when the browser launches. Another way is https://stackoverflow.com/a/66128729/9150146 Limitation, the approach is different to set an environment variable in different OS

  • set up a configurable job in CI tool. This job needs to have parameter inputs - dropdowns, text fields, check box - whatever is applicable. The job would pass these parameters to protractor and eventually shell script would run node process. For example:

protractor config.js --params.user="${USERNAME}" --params.password="${PASSWORD}"

Essentially what you want to do is several tasks (layers) and you just need to properly identify them and then solve one by one