user1493004
user1493004

Reputation: 101

How to run Specflow/Specrun feature files with dynamic values

I am very new to Specflow/Specrun and C# programming. I need help in fixing the issue I am facing.

I have a Specrun feature file which queries database. Below is the code of the feature file:

Scenario Outline: Ensure all rows are correctly inserted on in the table
    Given I am connected to "Database-XYZ"
    When I run a script to ensure all rows are inserted for <tableName> of a <schemaName>
    Then All tables have correct <columnCount> count.

This works absolutely fine. But I want to comment the second line and specify the database name at run time using the default.srprofile file.

I want to execute runtests.cmd file (from commandline) using default.srprofile file and feed the database name at run time. Is it possible to achieve this?

Upvotes: 2

Views: 1326

Answers (1)

Dazed
Dazed

Reputation: 1551

Not sure if this will help but you may want to use the app.config. I set my Database and the Environment and then call it from a step. This way you could create a call and set the database according to the environment under test by just changing the value in the app.config. You could do something like the below.

 app.config
 <add key="DatabaseTest" value="myDBConnectionString" />
 <add key="DatabaseDev" value="myDBConnectionString" />
 <add key="Environment" value="test" />

 Step:
 using System.Configuration; //make sure you have this included to use ConfigurationManager

    [Given(@"I am connected to my environment database")]
    public void GivenIAmConnectedToMyEnvironmentDatabase()
    {

     var myEnv = ConfigurationManager.AppSettings["Environment"];
     switch (myEnv)
     {
       case "test":
         var  _testDatabase = ConfigurationManager.AppSettings["DatabaseTest"];
         //create db connection 
         break;
       case "dev":
          var _devDatabase = ConfigurationManager.AppSettings["DatabaseDev"];
          //create db connection 
          break;
     }
     }

Upvotes: 2

Related Questions