Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specflow.json - Converting app.config to specflow.json

I searched online and there doesn't seem to be much info on this besides the info on the SPecFlow official site. But the site only gives high level information

Basically I want to update my current app.config file to a specflow.json file

Just wondering what's the best/correct approach to do this? and also, if there is any additional code I need to add to make this work I would be unaware off?

Current App.config:

<configuration>
    <configSections>
        <section name="specFlow" type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
    </configSections>

    <specFlow>
        <unitTestProvider name="MsTest" />
    </specFlow> 


    <appSettings>
        <add key="TestURL" value="https://test.com" />
        <add key="UATURL" value="https://test.com"/>
        <add key="PRODURL" value="https://test.com" />
        <add key ="BrowserType" value = "chrome" />
    </appSettings>

    <connectionStrings>
        <add name="DataBaseName" connectionString=""/>
        <add name="DataBaseName" connectionString=""/>
    </connectionStrings>

</configuration>

Current specflow.json

 {
  "bindingCulture": {
    "language": "en-us"
  },
  "language": {
    "feature": "en-us"
  }

I would assume something like this?

{
  "bindingCulture": {
    "language": "en-us"
  },
  "language": {
    "feature": "en-us"
  },

  "stepAssemblies": [
    { "assembly": "" }
  ],


  "appSettings": [
    {
      "key": "TestURL",
      "value": ""
    },
    {
      "key": "UATURL",
      "value": ""
    },
    {
      "key": "PRODURL",
      "value": ""
    },
    {
      "key": "BrowserType",
      "value": "Chrome"
    }
  ],


  "connectionStrings": [
    {
      "connectionString": "",
      "name": ""
    }
  ]

Also how would I call this in my tests? previously I would use the following:

var url = ConfigurationManager.AppSettings[“TestURL”];

1 Answers

The specflow.json file contains only the configuration for SpecFlow. That's the reason why nothing about it is in the documentation. But we should probably make this clear.

You have to put your appSettings and ConnectionString in a separate configuration file. Depending on what you are using, you can keep them in the app.config, put them in an appsettings.json file or something else. That is something I can't answer because it depends 100% on your used solution.


Full disclosure: I am one of the developers of SpecFlow and SpecFlow+

like image 195
Andreas Willich Avatar answered Sep 14 '25 04:09

Andreas Willich