vendredi 28 août 2020

C# = Read from appsettings.json file to launch application - for test automation

I am using specflow for test automation and I want to read from a appsettings.json file to launch browser

Previously I used and appconfig file for this nut specflow does not support it anymore

So basically I want to read from this:

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


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

I want to be able to pass the key pair value as a parameter for this method

 public static void LoadApplication(string url)
        {
            DriverContext.Driver.Url = url;
          
        }

Previously I used something like this:

var url = ConfigurationManager.AppSettings["TestURL"];
           DriverContext.Driver.Url = ConfigurationManager.AppSettings["TestURL"];

Just wondering what is the best approach to to this?

Aucun commentaire:

Enregistrer un commentaire