Reputation: 147
In the app.config file of my Selenium-Specflow-Nunit framework I have a key to set customer value (e.g. Walmart, Amazon, BestBuy, etc). To run my test against each of these customers I need to change the key value in app.config file everytime. That means I can't run the test for all customers at one run and controlled from my Specflow scenario.
Wondering is there a way to drive and control the customer key value of config file from the test?
Upvotes: 0
Views: 585
Reputation: 147
Used the below code
public void ModifyAppConfig(string customer, string env)
{
var config = ConfigurationManager.AppSettings;
config.Set("CUSTOMER", customer);
config.Set("Environment", environment);
ConfigurationManager.RefreshSection("connectionStrings");
}
Upvotes: 1
Reputation: 6528
One way I do this is to create a method like this:
(untested)
[TestMethod]
public void InitAppConfig(string customerValue)
{
var config = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~");
config.AppSettings.Settings.Remove("Customer");
config.AppSettings.Settings.Add("Customer", customerValue);
config.Save();
ConfigurationManager.RefreshSection("connectionStrings");
}
Upvotes: 1