Locked Dynamic Datasource (Database) for a web performance test ?

  • Monday, August 13, 2012 10:36 AM
     
     

    Hi,

    I'm trying to do a custom binding for the web performance test's datasource. Basically, I have a datasource where in the usernames and passwords are stored. The webtest have to pick the data from the datasource according to the environment that is chosen. If it is UAT environment, there are different set of data. If it is Training environment, there are different set of data. All these data come from a SQL table stored somewhere. I need to change the connection strings of this data binding according to the context parameter. Is that possible. Please let me know how do we do this without using coded webtest mode.

    Thanks in advance

All Replies

  • Monday, August 13, 2012 11:54 AM
     
     

    I'm not sure this can be done without a plug-in or making the test coded.

    How is the context parameter going to be changed from environment to environment?

    If you're trying to run the same test against different environments I would think seperate tests are needed anyway as trying to figure out which test run was against which environment might become a headache.


    Nick Sandel (Software Tester) New to C# since November 2011

  • Monday, August 13, 2012 12:23 PM
     
      Has Code

    Thanks for the reply Nick. I was trying something like the code mentioned below using a WebTestPlugin. Not able to properly cope up so as pick the right connection string according to the environment. The Context Parameter shall change as 'UAT' or 'Training' or 'Staging' environment. Depending upon the environment, i need to construct the connection string, bind it to datasource and take the values.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.VisualStudio.TestTools.WebTesting;
    namespace Utilities.TestPlugins
    {
        public class CustomDataBindingForLoadTestUsers : WebTestPlugin
        {
            public override void PreWebTest(object sender, PreWebTestEventArgs e)
            {
                if (e.WebTest.Context["EnvironmentForLoadTest"].ToString() == "UAT")
                {
                    DataSource myNewDataSource = new DataSource();
                    myNewDataSource.SetConnection("System.Data.SqlClient", "Data Source=RHWDB226B;Initial Catalog=CPNGPerfLog_UAT;Integrated Security=True");
                    myNewDataSource.Name = "LoadTest_Users_DS";
                    e.WebTest.DataSources.Add(myNewDataSource);
                    e.WebTest.AddDataSourceBinding(myNewDataSource.Name, "LoadTest_Users", "UserName", "Username");
                    e.WebTest.AddDataSourceBinding(myNewDataSource.Name, "LoadTest_Users", "Password", "Password");
                    //e.WebTest.DataSources[].SetConnection("System.Data.SqlClient", "Data Source=RHWDB226B;Initial Catalog=CPNGPerfLog_UAT;Integrated Security=True");
                }
            }
        }
    }

    Please assist.
  • Monday, August 13, 2012 1:18 PM
     
      Has Code

    Based on the code of what you want to do then the best idea would be to set 1 datasource up through the web test creation GUI in the usual way and then if it needs to change in the PreWebTest (based on the context parameter) then perhaps you could change it through this method (assuming there is only 1 datasource, use a different index if there are multiple):

    e.WebTest.DataSources[0].SetConnection(details here)
    

    This would work if all your bindings will be to the same 'shape' of data - e.g. username, password etc. I think if you wanted anything more complex with different bound fields based on the context parameter you'd need to handle that in a plug-in but it might become a bit over complicated and be simpler to just have seperate tests.

    Nick Sandel (Software Tester) New to C# since November 2011

  • Monday, August 13, 2012 1:30 PM
     
      Has Code

    Thanks Nick

            public override void PreWebTest(object sender, PreWebTestEventArgs e)
            {
                if (e.WebTest.Context["EnvironmentForLoadTest"].ToString() == "UAT")
                {
                    e.WebTest.DataSources[0].SetConnection("System.Data.SqlClient", "Data Source=RHWDB226B;Initial Catalog=CPNGPerfLog_UA;Integrated Security=True");
                }
            }

    I tried this code. But doesnot seem to work. Any errors on the code? I would request you to kindly solve my issue. Thanks in advance.

    Will this code get executed before a webtest starts or after the webtests in finished...

  • Monday, August 13, 2012 1:43 PM
     
     

    Have you tried running the code in debug mode to see if this code is being entered? How is you context parameter being decided? You'll need to watch out if you are setting the context parameter after the test has started - as I understand databinding it is all processed before the test begins so without using code to change it the datasource will be set for a test once it has began.

    The PreWebTest event should fire at the start of the test, before anything else happens. This document has some good advice, including the order in which methods execute for tests:

    http://vsptqrg.codeplex.com/releases/view/42484


    Nick Sandel (Software Tester) New to C# since November 2011

  • Monday, August 13, 2012 2:09 PM
     
     

    Nick,

    I ran the test in debug mode. Found it is properly entering the condition according to the context parameter. It is also setting the right connection. But the tables are not getting refreshed. It is fetching the data from table which is binded earlier when desigining the test.

    My scenario: I need to dynamically input the connectionstring. and according to that the table should populate the data.

    Please assist.

  • Tuesday, August 14, 2012 1:43 AM
    Moderator
     
     
    1.        Hi checkoutsree,

    Thank you for posting in the MSDN forum.

    I think that Nick’s suggestion is useful. Based on your description, now the right connection can be selected according to the context parameter, but you didn’t get the wanted table, am I right? If so, you can create a new test project and re-bind the data source to the web test. And you can create a proper web test plug-in and add it to the test project. Sometimes corrupted project settings can cause problems.  Or you can try to run “devenv.exe/SafeMode”. This can eliminate the possibility that third party packages are causing problems. Then you can run the web test to check if it can executed as you want.

    If possible, you could provide more detailed information about your web test plugin for helping to resolve the issue.

    Best regards,

    Amanda


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

  • Tuesday, August 14, 2012 4:01 AM
     
      Has Code

    Thanks for the reply Amanda.

    Yes you are right. I didn't get the wanted table after i refresh the connection.

    I tried the options you suggested but didnt work. Please find the screenshot. The Connection that i'm trying to set is setting up but it is not refreshing the tables. In fact, it didnt rebind the datasource after i changed the connection. Is there any ways to do so?

    Please help.

    EDIT: I have also tried the following code. This also didnot work.

                if (e.WebTest.Context["EnvironmentForLoadTest"].ToString() == "UAT")
                {
                    e.WebTest.DataSources[0].SetConnection("System.Data.SqlClient", "Data Source=RHWDB226B;Initial Catalog=CPNGPerfLog_UA;Integrated Security=True");
                    e.WebTest.ReloadDataTable(e.WebTest.DataSources[0].Name, e.WebTest.DataSources[0].Tables[0].Name);
                    e.WebTest.MoveDataTableCursor(e.WebTest.DataSources[0].Name, e.WebTest.DataSources[0].Tables[0].Name, 0);
                }

    Please help.


    • Edited by checkoutsree Tuesday, August 14, 2012 4:32 AM
    •  
  • Tuesday, August 14, 2012 6:50 AM
    Moderator
     
     

    Hi checkoutsree,

    Based on your code, the “Tables[0]” should mean that  you are using the first table.

    According to your screenshot, I would like to know if there is only one table in your database. If so, in this situation, you will always get the data from the only one table. You can try to add another table to the database. And you try to use “Tables[1]” in the PreWebTest method to get another table.

    If I have misunderstood anything, please let me know.

    Thanks,


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

  • Tuesday, August 14, 2012 6:56 AM
     
     

    Yes Amanda you have misunderstood it. There is only one table and I'm trying to read from the same. Ok lets leave this. Can you please atleast help in doing the following:

    1. Create a new datasource (using sql.dataclient)

    2. Read the tables

    3. Choose one of the table and associate one or more columns to a context paramter (data binding)

    I need to do the above steps @ runtime.

    Please assist.

  • Tuesday, August 14, 2012 8:01 AM
    Moderator
     
     Answered

    Hi checkoutsree,

    Sorry for misunderstanding your purpose.

    You wrote that ”associate one or more columns to a context parameter (data binding)”. Do you mean that you want to bind a data from a data source to a context parameter? If so, I have to tell you that we can’t bind a data source to a context parameter.

    The link below about binding a data source to a web performance test may be helpful:

    http://msdn.microsoft.com/en-us/library/ms404707.aspx

    Thanks,


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

  • Wednesday, August 22, 2012 6:06 AM
    Moderator
     
     

    Hi checkoutsree,

    What about your issue now? Have you resolved it?

    Would you mind letting us know the result of the suggestion?

    Thanks,


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