Anu7
Anu7

Reputation: 77

How to access and read app setting keys from QTAgentService.exe.config from code

I need to read and set the key "ControllerConnectionPeriodInSeconds"'s value from QTAgentService.exe.config file (this file is located in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE).

Read about ControllerConnectionPeriodInSeconds here: https://msdn.microsoft.com/en-us/library/ff934570.aspx

I cant seem to find any ways to get the above value in code. System.Configuration.ConfigurationManager.AppSettings doesnt help here either.

Any help will be much appreciated !

Thank You!

Upvotes: 0

Views: 267

Answers (1)

Ryanman
Ryanman

Reputation: 880

Anu,

You have a couple options here. If you're running your tests on an agent, you'll want to modify the config on the agent machine.

You can do this from a CodedUI test, or really any test for that matter with C# libraries. If you need to modify it permanently, I'd just do it manually. If you need to set specific values for individual tests, you can do so in there.

You'll want to use the directory libraries and probably some helper method/class to actually change the config file. The specifics of that are way too intense for an SO answer, but here's an example of how you can load a file at the beginning of a test:

string path = Path.GetFullPath("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\QTAgentService.exe.config");
browserWindow = BrowserWindow.Launch(new Uri(path));

Rather than getting the current directory, you can hardcode it or better yet define that string("C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE") in your app.config. Then you'll have to use probably the C# XML parser and XPath to modify the value you want. I have some example code on my GitHub, but it's pretty straightforward.

Good luck! I've had to do some crazy stuff in CodedUI testing as well.

Upvotes: 0

Related Questions