1

I have a custom tag defined in my Hook.cs file like

 [BeforeScenario("AfterUpgradeTag")]
 public void BeforeScenarioAfterUpgrade()
 {
  // Code execution here
 }

What I want to do is I want to change its method definition like

 [BeforeScenario("AfterUpgradeTag")]
 public void BeforeScenarioAfterUpgrade(bool flag)
 {
  if(flag)
  // Code execution here
  else
  //Do a clean up 
 }

And I want to use this in feature file as something like

@AfterUpgradeTag(bool val = false)

I have searched alot for this. I want to know is this possible using Specflow or if there are any alternatives

SandyRocks
  • 269
  • 4
  • 15
  • Tags are typically used in feature files, and SpecFlow does not support this kind of usage. What would the flag ever be set to `false`? Maybe if we know more about what you are trying to accomplish we can come up with some sort of answer. – Greg Burghardt Jan 23 '20 at 12:11

2 Answers2

1

I am not sure if you can pass parameters like that in feature file but you can utilize tags to achieve your goal

In feature file do this

 @upgrade @false
  Scenario: testing upgrade

In binding class

 public static ScenarioContext _scenarioContext;

and binding class constructor

 public BindingClass(ScenarioContext scenarioContext)
        {

            _scenarioContext = scenarioContext;

        }

and your BeforeScenario method is defined like this in the class BindingClass

[BeforeScenario("upgrade")]
        public void BeforeScenarioUpgradeFalseorTrue()
        {
            if (BindingClass._scenarioContext.ScenarioInfo.Tags.Contains("false"))
            {
                log.Info("upgrade is false..");
            }

            if (BindingClass._scenarioContext.ScenarioInfo.Tags.Contains("true"))
            {
                log.Info("upgrade is true..");
            }
        }

when you want to pass true in feature file just do

 @upgrade @true
  Scenario: testing upgrade
user1207289
  • 3,060
  • 6
  • 30
  • 66
-1

You can follow the documentation from specflow to achieve this.

Sud
  • 166
  • 12