开发者

application configuration file in C# question

I am using selenium with c# to write automated tests for a website. I am still learning selenium and c#, and getting into issues here and there. I am not sure what would be a good approach. Would app.config file in c# be a good idea to store all xpaths of objects in the website? Or is it not a good idea to store hundreds of these object definitions in an xml file like app.config. Also, right now, I have:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="Machine" value="localhost"/>
  </appSettings>
 </configuration>

and, I am using a method in my class to get the values from this app.config file:

    public string GetAppConfig(string key)
    {
        return ConfigurationManager.AppSettings[key].ToString();
    }

Is this a good way to retrieve values from app.config. Or is there a better way to do it?

Thanks in advance for your help. I am really confused to as what I should be doing to store xpaths. I do not want to do something like:

Selenium.Click(\\id="...."\)

because that would be difficult to change if the xpaths开发者_开发百科 change in the website later.


Use the built in ConfigurationManager where possible, avoid rolling your own if you don't need to. You can make this helper class static so it can be called direct without creating a new instance.

Note that in your code, if the key doesn't exist it will throw an exception, depending on your requirements you may want to catch it?


You could use the config file for this, but would have to deal with unessessary xml.

Personally I would just write a simple file parser that reads key=property (line by line):

Can .NET load and parse a properties file equivalent to Java Properties class?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜