Difficulty in reading settings.json file
AnsweredI have recently moved to .net 5 and finding difficulty in reading settings.json file. The settings.json file is being searched in test results folder rather than in the main folder.
I have tried this as well but did not help.
https://github.com/SpecFlowOSS/SpecFlow/issues/1668
I store all urls and other data in a settings.json file
And also have an another file to read data from settings.json file like below :
namespace SpecFlowProjectSample.SettingsNS
{
public static class SettingsUtil
{
public static T GetObjectFromJsonFile<T>(string filename)
{
string json = File.ReadAllText(filename);
var deserializedObject = JsonConvert.DeserializeObject<T>(json);
return deserializedObject;
}
}
}
And in each of the step defnition file where I need data from settings.json file, I use this
private readonly Settings settings;
public Calsteps()
{
settings = SettingsUtil.GetObjectFromJsonFile<Settings>("settings.json");
}
So, my issue here is, when I try to read the settings.json file in string json = File.ReadAllText(filename); , it is searching settings.json file in another folder(Test results folder) than the main folder(SpecFlowProjectSample) where my project exists.
This works in mstest but not with specrunner.Could you help me in fixing this issue.
-
hey Minnal Ponnuswamy, Sujatha,
I would suggest to save this hassle you can use our SpecFlow.Actions.Configuration plugin.
You will see that inside of SpecFlowActionJsonLocator we are searching for the config in various different directories to handle the event where the file could be in several different locations.
You could also easily copy this code into your project to handle finding your file, take a look at this method
Hopefully this helps you :)
Let me know otherwise!
0
Please sign in to leave a comment.
Comments
1 comment