0

I am working on a project on Angular7 where e2e tests are written using protractor.

I have made a new feature in my project which I want to control via a functional switch. When switch is ON feature will be rendered to user and hidden when switch is OFF.

Switch will be a boolean value in my app.conf.json file. This will be read in ts file of component as a flag and flag will be used in html with *ngIf condition.

My question is, is there a way I can execute certain e2e tests based on reading the boolean value from my app.conf.json file. When value is true e2e test related to new feature are run and not run when it is false. I tried searching this on internet but no luck.

jithinkmatthew
  • 890
  • 8
  • 17
AkashSharma
  • 107
  • 1
  • 2
  • 13
  • See if [this](https://stackoverflow.com/questions/37748394/protractor-jasmine-conditional-test-cases) helps – DublinDev Mar 04 '20 at 17:06

2 Answers2

0

you can use if statement outside your 'it' spec and read your condition from json file. example :

 var cnd = require('./test.json');
if(cnd.condition){

  it('should do something', () => {

  });}

test.json:

[{"condition":"true"}]
0

You can place it in your browser params:

exports.config = {
   //...
   params: {
     myProjectConfig: require('path/to/project/config')
   }
}

Then call it in your code:

const isFeatureOn = browser.params.myProjectConfig.toggleFeature;
if (isFeatureOn) {
   //...
}
//...
Rudreshuar
  • 125
  • 6