none
How can I add a datasource to an xmlfile in app.config? RRS feed

  • Question

  • I have tried below code. its not working for me. can you please help me here to resolve it using config file.

    TestCase-

            [TestMethod]
            [DataSource("ClassSectionDataSource")]
           
            public void SC_SmokeTest_US_ViewMemberAccount()
            {
                //Test code
            }

    App.config FIle-

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>


      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="" culture="neutral" />
            <bindingRedirect oldVersion=".....0.0.0" newVersion="...0.0.0" />
          </dependentAssembly>
        </assemblyBinding>


        <configSections>

          <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>

        </configSections>

        <connectionStrings>

          <add name="ClassSectionConString" connectionString="D:\\..\\..n\\ServiceCloud Tests\\...\\QA4\\TestCloudData.US.xml" providerName="Microsoft.VisualStudio.TestTools.DataSource.XML"/>

        </connectionStrings>

        <microsoft.visualstudio.testtools>

          <dataSources>

            <add name="ClassSectionDataSource" connectionString="ClassSectionConString" dataTableName="SmokeTestData" DataAccessMethod="Sequential"/>

          </dataSources>

        </microsoft.visualstudio.testtools>
      </runtime>
    </configuration>


    Please help me here.

    Saturday, January 11, 2020 5:14 AM

Answers

  • Hi udpatil96,

    Thank you for feedback.

    The <configSections>,<connectionStrings>,<microsoft.visualstudio.testtools> should be under <configuration> instead of <runtime>, and we don't <runtime>, so we could remove it.

    The whole config file is like:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions" />
        </configSections>
        <connectionStrings>
          <add name="ClassSectionConString" connectionString= "D:\TestAutomation\TestAutomation\ServiceCloud Tests\ServiceCloudData\QA4\ServiceCloudData.US.xml" providerName="Microsoft.VisualStudio.TestTools.DataSource.XML"/>
     </connectionStrings>
    <microsoft.visualstudio.testtools>
        <dataSources>
          <add name="ClassSectionDataSource" connectionString="ClassSectionConString" dataTableName="SmokeTestData" dataAccessMethod="Sequential"/>
        </dataSources>
      </microsoft.visualstudio.testtools>
    </configuration>

    Look forward to your reply.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by UdayPatil96 Wednesday, January 15, 2020 7:10 AM
    Wednesday, January 15, 2020 6:59 AM

All replies

  • Hi udpatile96,

    Welcome to MSDN forum.

    According to your description, you should modify the configSections to this:

        <configSections>
            <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions" />
        </configSections>

    And the relative path seems to be wrong in <ClassSectionConString>, if the file is in your output path, please change it like this:

    <add name="ClassSectionConString" connectionString= ".\test.xml" providerName="Microsoft.VisualStudio.TestTools.DataSource.XML"/>

    Any feedback will be expected.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, January 14, 2020 8:21 AM
  • Hi Dylan,

    Thank you for your reply.

    I am using VS 2017.

    I have made changes in config file as you said. but same issue not working.

    please find below changes i have done in config file.
    please check my relative path i have given.
    i have checked both way -
                                           1. starting with \\ 
                                           2. starting with \       
             
    i am giving here complete path of that xml file. please correct me if i am doing wrong.

    i have commented my old code.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>


      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
          </dependentAssembly>
        </assemblyBinding>


        <configSections>

          <!--<section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed"/>-->

          <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions" />
        
        </configSections>

        <connectionStrings>

          <add name="ClassSectionConString" connectionString="D:\\TestAutomation\\TestAutomation\\ServiceCloud Tests\\ServiceCloudData\\QA4\\ServiceCloudData.US.xml" providerName="Microsoft.VisualStudio.TestTools.DataSource.XML"/>

          <!--<add name="ClassSectionConString" connectionString= ".\test.xml" providerName="Microsoft.VisualStudio.TestTools.DataSource.XML"/>-->

        </connectionStrings>

        <dataSourceSettingsName></dataSourceSettingsName>

        <microsoft.visualstudio.testtools>

          <dataSources>

            <add name="ClassSectionDataSource" connectionString="ClassSectionConString" dataTableName="SmokeTestData" DataAccessMethod="Sequential"/>

          </dataSources>

        </microsoft.visualstudio.testtools>
      </runtime>
    </configuration>

    I am getting below error while running the TC

    Message: Data Source 'ClassSectionDataSource' can not be found in test configuration.

    I have took the reference from- \\social.msdn.microsoft\\Forums\\en-US\\ce0846a9-0522-401e-b004-48025c41375b\\how-can-i-add-a-datasource-to-an-xmlfile-in-appconfig?forum=vststest

    please make change in URL. here unable to give me direct url.

    • Edited by UdayPatil96 Wednesday, January 15, 2020 7:02 AM
    Wednesday, January 15, 2020 6:45 AM
  • Hi udpatil96,

    Thank you for feedback.

    The <configSections>,<connectionStrings>,<microsoft.visualstudio.testtools> should be under <configuration> instead of <runtime>, and we don't <runtime>, so we could remove it.

    The whole config file is like:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>
            <section name="microsoft.visualstudio.testtools" type="Microsoft.VisualStudio.TestTools.UnitTesting.TestConfigurationSection, Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions" />
        </configSections>
        <connectionStrings>
          <add name="ClassSectionConString" connectionString= "D:\TestAutomation\TestAutomation\ServiceCloud Tests\ServiceCloudData\QA4\ServiceCloudData.US.xml" providerName="Microsoft.VisualStudio.TestTools.DataSource.XML"/>
     </connectionStrings>
    <microsoft.visualstudio.testtools>
        <dataSources>
          <add name="ClassSectionDataSource" connectionString="ClassSectionConString" dataTableName="SmokeTestData" dataAccessMethod="Sequential"/>
        </dataSources>
      </microsoft.visualstudio.testtools>
    </configuration>

    Look forward to your reply.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by UdayPatil96 Wednesday, January 15, 2020 7:10 AM
    Wednesday, January 15, 2020 6:59 AM
  • Thank you so much Dylan. Its working for me now.
    • Edited by UdayPatil96 Wednesday, January 15, 2020 7:11 AM
    Wednesday, January 15, 2020 7:10 AM