locked
CodedUi Tests App.Config Problems: loading wrong files RRS feed

  • Question

  • Hi,

    I used a setup for remote tests ( 1 controller, some agents, 1 visual studio).

    Till now I have one App.config file located on the same directory level with the csproject file.

    I added it to the deployed files in the test settings.

     

    I accessed the app config via:

    ConfigurationManager.AppSettings["key"];

    That worked some time.

     

    Now I want to have different testsettings with different App.config files to deploy.

    I created a subfolder for each App.config file and added them to the different testsettings.

     

    Now when I tried to run the test runs with the different test settings.

    But they are still reading the info from the old App.config.

    Where is the problem with this? How can I find a fix for that?

    Friday, September 21, 2012 7:37 AM

All replies

  • Hello Live,

    Thank you for posting in the MSDN forum.

    Based on your description, I create two different App.config files in different folders located on the same directory level with the csproject file. I also have two testsettings files. I deployed them into different testsettings. Then I run the test and the test can run with deploying corresponding App.config.

    So I would like to know if you selected correct Active Test Settings when you run with different testsettings. Please check it.

    In addition, you can try to disable the old testsettings and run with the new testsettings including new App.config to check if the new App.config can be deployed and read successfully.

    A useful article, see Can a unit test project load the target applicaion’s app.config file?

    A perfect blog wrote by Nilesh about Uint Test Application Configuration Settings, see

    http://nileshgule.blogspot.com/2010/09/unit-test-application-configuration.html

    I hope it can help you.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 1:08 AM
    Moderator
  • I do the same as you describe. Don't know where the problem is.

    One additional Question:
    Is It possible to move the Test-settings files to another Folder?
    When I do so, it seems that they are copied in the solution (but not on file system layer).

    Also in the test settings I realized that the SetUp and CleanUp scripts are linked as absolut path and not like the Deployment settings as relative path. Is there a way to change this?(a Visual Studio 2010 Update?, other changes)?

    Monday, September 24, 2012 10:03 PM
  • Hello Live,

    Glad to receive your reply.

    I have added a new folder in the solution items and put the testsettings file into it. But when I plan to select active test settings, it does not occur in the options and I can’t find and select it. Can you do that successfully?

    In addition, if you want to deploy an item as absolute path, you can deploy items for a single test using the DeploymentItem attribute, please see: How to: Configure Test Deployment

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, September 25, 2012 10:00 AM
    Moderator
  • Hello Live,

    Glad to receive your reply.

    I have added a new folder in the solution items and put the testsettings file into it. But when I plan to select active test settings, it does not occur in the options and I can’t find and select it. Can you do that successfully?


    I think we have the same problem.
    In Visual Studio I add a new Folder to the Solution Items and copy a existing testsettings file there. I can open the file by double clicking it. But when I want to select it(or edit it) via [Test]-->[Select/Editi TestSettings] I dont see the new file.

    In addition, if you want to deploy an item as absolute path, you can deploy items for a single test using the DeploymentItem attribute, please see: How to: Configure Test Deployment

    Best regards,


    The Deploying via test settings works fine (except for the app.config).
    But I DON'T like the absolute path for the SetUp/CleanUp scripts in the test settings.
    There I would prefare a relative path like the deployment.
    Otherwise Working together on one Test Solution in a team or on different machines is a pain

    Tuesday, September 25, 2012 3:06 PM
  • I'm realy curiouse whats up with the App.Config.

     

    I now tested around, and realized that it no matter what I'm selecting in the Test Settings.

    The CodedUITests are not using the App.config that is selected as Deployment Item in the Test Settings.

     

    I verified that it is coping the App.config file from an other directory.

    To Understand here Is a hierarchy.

     

    sys1.testsettings

    sys2.testsettings

    sys3.testsettings

    sys4.testsettings

    ...

    +---Settings

    ¦   +---System1

    ¦   +---System2

    ¦   +---System3

    ¦   +---System4

    ...

     

    Within the System folders there are some files: "App.config" & "Steup.bat" which are used in the sys*.testsettings files.

    The BAT file is used as Setup script.

    The App.config is added to the deployment data.

     

    No When I run a Coded UI Test on System 1 I want to select Test settings "sys1.testsettings" so that the coded UI tests use the correct App.config for them selves.

    They are NOT for the Application under Test!

     

    But in my case no matter what settings I use (sys 1, sys4) always the values from the app.config from the system 3 folder is showing in the CodedUI.

     

    So what’s the Problem and how can I solve this?

    Tuesday, September 25, 2012 7:36 PM
  • Hello Live,

    Based on your description, are all system folder on the same directory level with the csproject file? Are you running your tests remotely on a rig?

    Can you always see the config file in the same system folder is deployed in the test results folder?

    If so, you can try to remove the system3 folder to check if the same App.config file always will be deployed. Also you can add a system folder with another App.config file to check if the config file in system3 folder still is deployed no matter which settings you select.

    In addition, if you are running Coded UI test on a rig, the test agent must be configured to run as an interactive process.

    If no help, you can run your scenario locally rather remotely with the same Visual Studio to check if it helps.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, September 26, 2012 8:29 AM
    Moderator
  • Hello Live,

    Based on your description, are all system folder on the same directory level with the csproject file? Are you running your tests remotely on a rig?


    No, the settings folder is on the same level with the csproject file.
    Yes, I’m running the tests remotely, because the test application usually can’t be started on “normal” PCs.

    In addition, if you are running Coded UI test on a rig, the test agent must be configured to run as an interactive process.


    This is done and wors great.

    If no help, you can run your scenario locally rather remotely with the same Visual Studio to check if it helps.


    This is due to the requirements for the test application a little bit complicated, but I will try to get it runnning.

    If so, you can try to remove the system3 folder to check if the same App.config file always will be deployed. Also you can add a system folder with another App.config file to check if the config file in system3 folder still is deployed no matter which settings you select.


    When I delet the app.config file from system3 (or the folder) the following error message is shown in :
    Error 1 Unable to copy file "Settings\System3\App.config" to "bin\Debug\CodedUITestProject.dll.config". Could not find file Settings \ System3\App.config'.
    There is no matter which settings I select, always the settings from system 3 are used.

    Can you always see the config file in the same system folder is deployed in the test results folder?


    This might be a good hint for searching the problem (in connect with the error message)!
    Is it usually needed to add the App.config for the CodedUITests to the Deployment Items?

    In the TestResult folder Out I found a file “App.config” which is exactelly the file I want to use to configure my CodedUITests.
    But I also found a file “CodedUITestProject.dll.config” which is the App.config file from system3.
    Also when I search on the test machine I can find these two files
    In folders like C:\Users\USER\AppData\Local\VSEQT\QTAgent\17c7d821-12bc-474c-9b13-565c411dd3fc\Machine-Test-01\Deployment

    So the question is why the coded UI files use the CodedUITestProject.dll.config file as source for ConfigurationManager.AppSettings[]?
    And why is the app.config from system3 is used as CodedUITestProject.dll.config?

    Wednesday, September 26, 2012 10:59 AM
  • Hello Live,

    “Is it usually needed to add the App.config for the CodedUITests to the Deployment Items?”

    If you want to deploy a file using a test settings, you need to add the file to the directory you are using to run your test.

    For detailed information, you can see: Can a unit test project load the target applicaion’s app.config file?

    For more information about how to deploy files and directories for individual tests using properties and the DeploymentItem attribute, see : How to: Configure Test Deployment.

    If you want to use different test settings and different App.config, you can create a new test settings and deploy the new App.config file in it, then you select the new test settings as active test settings.

    So you must make sure that you have deployed different App.config with different system folder.

    In the TestResult folder Out I found a file “App.config” which is exactelly the file I want to use to configure my CodedUITests.
    But I also found a file “CodedUITestProject.dll.config” which is the App.config file from system3.

    Do you mean that the exact App.config file can be deployed when you select different testsettings?

    But a file “CodedUITestProject.dll.config” is always deployed no matter what you select.

    Am I right?

    As far as I know that if the dll's name was MyDll.dll, then the config file should be MyDLL.dll.config.

    And ConfigurationManager.AppSettings property gets the AppSettingsSection data for the current application's default configuration. It seems that you can get CodedUITestProject.dll.config when you use ConfigurationManager.AppSettings[].

    In addition, there is a good example about App.config file and how to read it in the following link:

    http://www.nileshgule.com/2010/09/unit-test-application-configuration.html

    I accessed the app config via:

    ConfigurationManager.AppSettings["key"];”

    Is the key different in different App.config file? And when you select different test settings, do you set the key again according to different App.config? If you don’t, you can try to change it with the different App.config to make sure that you can access a different App.connfig and read it.

    I hope it can help you.


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, September 27, 2012 1:59 AM
    Moderator
  • OK. Maybe there is a misunderstood.

    I don’t want to read/deploy/change/test the App.Config of the Application under Test,

    I want to configure the Tests (Coded UI Tests) I’m running depending on what system I’m running them.

    This should be done by the Test settings files.

     

    I have 4 different Systems (Machines) where I want to run my tests (remote test runs).

    Each of the System need different values in there Tests. I want to read them from the App.config of the Coded UI Tests (not the app.config of any other .Net application)

    The file app.config in the different setting/system folders contains the same keys but with different values.

    As far as I know that if the dll's name was MyDll.dll, then the config file should be MyDLL.dll.config.

    And ConfigurationManager.AppSettings property gets the AppSettingsSection data for the current application's default configuration. It seems that you can get CodedUITestProject.dll.config when you use ConfigurationManager.AppSettings[].

    Yes. I can only access CodedUITestProject.dll.config (CodedUITestProject is the name of the project) with ConfigurationManager.AppSettings[].

    And exactly that is the problem. Visual Stuido is only using the App.config file from System3 as “CodedUITestProject.dll.config” and this is NOT changing when I use another test setting (selecting it “Test->slect testsettings->system1” or passing it via command line using MSTest).

    The blog only shows how to add a Link to another project, but this is not necessary. (there is no other project in my solution)

     

    Is there a way to read a App.Config file from another path? That is different from the Projects name? Instead of “CodedUITestProject.dll.config” I want to read from “NewApp.config”.

    Thursday, September 27, 2012 11:10 AM
  • Hello Live,

    I suggest that you can create another test project with multiple folder having different App.config file. Then you can select different testsettings to run to check if the correct App.config can be used and see if the CodedUITestProject.dll.config still occurs and is used.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    Saturday, September 29, 2012 5:15 AM
    Moderator
  • Hello Live,

    I suggest that you can create another test project with multiple folder having different App.config file. Then you can select different testsettings to run to check if the correct App.config can be used and see if the CodedUITestProject.dll.config still occurs and is used.

    Ok, I'll give that a try.
    But one question more: How does a normal (non test) project is using (creating) the App.config (project.dll.config) file? How is decided what file is used?

    Friday, October 5, 2012 8:00 AM
  • Hello Live,

    Sorry for my delay.

    About App.config, I find some articles that you can reference and check if they help.

    http://stackoverflow.com/questions/594298/c-sharp-dll-config-file

    http://social.msdn.microsoft.com/Forums/en/csharpide/thread/a17a45f1-6d64-4ba2-bbfe-0da48981c3dc

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Sirisha M Friday, November 30, 2012 7:17 AM
    Tuesday, October 9, 2012 6:44 AM
    Moderator
  • Hello Live,

    About the App.config and Project.dll.config issue,   I did some research and find some threads. Please see:

    http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/aeabbb52-3607-4209-8301-36d644d701cc

    As Dhopton and Michael said above, what specific for Unit Test Framework is that we allow you to use
    .config file per test assembly: if you have myTestAssembly.dll, we will look for myTestAssembly.dll.config.

    In addition, you also can see the following thread:

    http://social.msdn.microsoft.com/Forums/en-US/vststest/thread/3e520735-8ced-4092-b681-38b69e0db534/

    Best regards,




    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us



    Tuesday, October 16, 2012 10:40 AM
    Moderator