Search code examples
c#command-linespecflow

How to pass Command line argument to specflow test scenario


I am trying to run my specflow test scenarios from command line and im wondering is it possible to pass any command line argument to my specflow scenario.

My scenario is like this:
Scenario: Test Connection to my server
Given Get server ipaddress
When I press connect
Then I should get connected

When i say "Get server ipaddress" then i am able to read command line argument. Is it possible??

Or anyone have any other solution or suggestion. Thank you in advance.


Solution

  • i'd use the .net configuration system - put your server connection strings into the connectionstrings settings element (or if you have a religious objection to putting something non-database there, use appsettings) and read from your settings. if you want to have different config files for different environments, use config transformations to create different configuration. this will allow you to keep everything in the project and not have to depend on setting up environment variables for your application. you can script creating transformed config files using the command line transform execution tool.

    i have done something similar to use config files with my specs hitting web pages to switch which driver i'm using for selenium webdriver and wound up just copying my specs assemblies multiple times with different config files so i can run from different directories to execute different browsers. you could do something similar for desire to connect to different machines or just spit out different config files and swap those in and out of your execution directory (or just manually change config when you want to execute something different).

    you should also get the obligatory "that scenario isn't really a bdd scenario and should be more a story about a business capability than the technical scenario you have there to use bdd tools like specflow the way they were intended" statement for this to be a complete answer.