Code & QA


Any application, especially a big project, always needs some data that are used as parameters or settings of the application. Obviously, during the development process and evolution of the application, these data are changed. Also, the data may vary in accordance with external circumstances, for example when an execution environment is changed. Recompiling of the code every time any changes in the application or in the testing environment or somewhere else has happened is not a good idea. In addition, not everyone and not everywhere has a possibility to rebuild the project, besides you should not allow to do it to everyone as well.

Yet the data are changed you have to manage it somehow. The current project is not unique exclusion. For example, when tests run session is over the summary report must be sent to specified email addresses. But what if starting from a day I have to send the email to one more address, or the address of the recipient have changed, or contrariwise I want to exclude someone from recipient’s list?

Recompiling the entire project for such a trifle is breaking a butterfly on the wheel. That’s why all software developers keep such kind of data in external storages where the data may be easily modified by authorized persons. Many people utilize different ways for that – databases, Excel tables, configuration files, and cloud services and so on.

I decided that the simplest and the most effective approach for storing application settings and parameters are using a configuration file. Especially it’s useful for little and middle size applications where you store just a dozen or two of parameters and using a database or a special service for a couple of lines of text is not efficient.

In C# there are special classes for managing configuration files. The classes are located in System.Configuration.dll library (System.Configuration namespace). Working with configuration files, in general, is very easy and plain. There are a lot of tutorials for that on the internet and you can study it just in an hour.

I want to show here how the configuration file is used in the project.

The first step is adding App.config file to the Tests project:



App.config file is added to the project.


I decided to keep in the configuration file the name of the application and the list of summary report email recipients. I added a new section to the configuration file as shown below

[gist id=d29f3d9a6d57835f2f1dc0a8cfcba4e5]

And made little changes to the code:

[gist id=7ab35aa6f93a6b0bf95d6a1121ab927c]

Do not forget to add the reference to System.Configuration library. As you can see handling the project data with configuration file is very easy. For example, you can define what kind of web browser to use for the tests execution.

Add a new node to the configuration file

[gist id=42e8e875ecfb1f46966a623158cd1e59]

Add the following method to BaseTest class

[gist id=5d9cfc9031a323e8f0ac5e6dbf4f9bce]

Invoke the method in Setup() method

[gist id=9168c38e436101a3901da9f8469aab90]

Now there is no need anymore to make changes to the code and to recompile the project for running tests with different browsers. All the changes are managed in the App.config file.

P.S. Keep in mind that running tests with InternetExplorer or Chome browsers requires having IEDriverServer.exe and chromedriver.exe files in the working directory (Test/bin/Debug).

The files may be downloaded from Seleniumhq site:

Event Logging
Table Of Content
Environment adjustments via Registry

Leave a Reply