YuTong's Blog

Web/Load Testing

  • VSTS 2010 Feature: File Upload record/playback just works

    In VSTS2008 and VSTS2005, after a user records a simple file upload request, the user needs to manually add it to the Deployment section in the test configuration file in order to playback the Web Test successfully. In addition, the user will notice that there is only one copy of the uploaded file on the Web Server regardless of how many times the Web test is executed. Therefore, it is not easy to find out whether files are uploaded correctly during load testing. In VSTS2010, we made the following four improvements to this File Upload feature. We will go through these with a simple Web test that has one file upload request, which uploads a file named test.txt 

    1. After a user records an http Upload request, the uploaded file is automatically added to the test project by a build-in FileUpload Plug-in. As you can see, test.txt is added to the test project after recording.

    2. A new property called Generate Unique Name is added to the File Upload Parameter. By default, its value is set to true, which indicates that a unique file name will be generated before the request is sent. If it is set to false,  the file name will not be modified during test execution, which is the same as the upload behavior in VSTS2008 and VSTS2005. Note: In VSTS2010, for a upgraded Web test that contains a file upload request, the value is set to false.

    Fu1

    3. When a user runs the recorded file upload Web test, the file to be uploaded is automatically deployed. A user does not need to add it explicitly to the deployment section of  the VSTS2010 .testsettings file before test execution.

    After the sample Web test is executed, as you can see, the uploaded file is prefixed with a timestamp.  

    image

    If the server-side script does not modify the name of the uploaded file, a user should find the file "11062009091608978test.txt" on the Web Server machine.

    4. Playback of the generate coded Web test just works. As you can see in the below code, the file to be uploaded is automatically added as a deployment item.

    //------------------------------------------------------------------------------
    // <auto-generated>
    //     This code was generated by a tool.
    //     Runtime Version:4.0.20608.0
    //
    //     Changes to this file may cause incorrect behavior and will be lost if
    //     the code is regenerated.
    // </auto-generated>
    //------------------------------------------------------------------------------

    namespace TestProject1
    {
        using System;
        using System.Collections.Generic;
        using System.Text;
        using Microsoft.VisualStudio.TestTools.WebTesting;
        using Microsoft.VisualStudio.TestTools.WebTesting.Rules;

        [DeploymentItem("test.txt")]
        public class WebTest2Coded : WebTest
        {

            public WebTest2Coded()
            {
                this.PreAuthenticate = true;
            }

            public override IEnumerator<WebTestRequest> GetRequestEnumerator()
            {
                // Initialize validation rules that apply to all requests in the WebTest
                if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
                {
                    ValidateResponseUrl validationRule1 = new ValidateResponseUrl();
                    this.ValidateResponse += new EventHandler<ValidationEventArgs>(validationRule1.Validate);
                }
                if ((this.Context.ValidationLevel >= Microsoft.VisualStudio.TestTools.WebTesting.ValidationLevel.Low))
                {
                    ValidationRuleResponseTimeGoal validationRule2 = new ValidationRuleResponseTimeGoal();
                    validationRule2.Tolerance = 0D;
                    this.ValidateResponseOnPageComplete += new EventHandler<ValidationEventArgs>(validationRule2.Validate);
                }

                WebTestRequest request1 = new WebTestRequest("http://teamtestweb1/testwebsite/FileUpload.aspx");
                request1.ThinkTime = 26;
                ExtractHiddenFields extractionRule1 = new ExtractHiddenFields();
                extractionRule1.Required = true;
                extractionRule1.HtmlDecode = true;
                extractionRule1.ContextParameterName = "1";
                request1.ExtractValues += new EventHandler<ExtractionEventArgs>(extractionRule1.Extract);
                yield return request1;
                request1 = null;

                WebTestRequest request2 = new WebTestRequest("http://teamtestweb1/testwebsite/FileUpload.aspx");
                request2.Method = "POST";
                FormPostHttpBody request2Body = new FormPostHttpBody();
                request2Body.FormPostParameters.Add("__VIEWSTATE", this.Context["$HIDDEN1.__VIEWSTATE"].ToString());
                request2Body.FormPostParameters.Add(new FileUploadParameter("UploadFile", "test.txt", "text/plain", true));
                request2Body.FormPostParameters.Add("UploadButton", "Upload");
                request2Body.FormPostParameters.Add("SaveName", "test.txt");
                request2Body.FormPostParameters.Add("__EVENTVALIDATION", this.Context["$HIDDEN1.__EVENTVALIDATION"].ToString());
                request2.Body = request2Body;
                yield return request2;
                request2 = null;
            }
        }
    }

  • VSTS 2010 Feature: View Recording Log in Web Test Playback Window

    In VSTS2010, when a user records a Web test using Web Test Recorder, the recorded session result, including those for the dependant and redirected requests, is saved and can be loaded into the Web Test Result window later. So if the playback fails, for example, due to correlation (dynamic parameter detection) issues, a user can always compare the recorded result and the playback result side by side.

    In the following example, the recorded Web test contains three requests. The first one is a non-redirect request and does not contain any dependant, the second one is request that is redirected twice, and the third one is redirected once and the redirect contains some dependant requests.

    To load the recorded result in Web Test Result window, a user can run the Web test till completion and click on the Recorded Result button on the toolbar.

    image

     

    Below is the screenshot of the recorded result.

    image

    In the launched Recorded Result window, not only can a user view the recorded details, i.e. headers, cookies, query string parameters, post parameters, and the response for a selected request, the user can also perform a search or go to the recorded Web Test. With VSTS2010, only the first recorded session result will be saved at the end of recording.

  • Add Excel 2007 Spreadsheet as a Data Source

    Step1. Create Excel 2007 spreadsheet

    1)     Create a blank workbook

    2)     Populate the cells. The first row of the cell block should be the column headers.

    3)     Highlight the entire cell block including the column headers.

    4)     On the Formula menu, click on Define Name.

    5)     Specify the name and the scope.

    6)      When you are done, save the workbook.

    Step 2.  Download and install the 2007 Office Data Connectivity Components.

    Step 3.  Add the Excel date file as a data source

    1)     In the Web Test Editor, right-click the top node of the Web test and then click Add Data Source.

    2)     The New Test Data Source Wizard appears.

    3)     In the Data source name box type a name for your data source.

    4)     In the Data source type list click Database.

    5)     Click Next.

    6)     Click New Connection.

    7)     The Choose Data Source dialog box appears. If the Connection Properties dialog box appears, click on the Change button next to the data source text box. The Change Data Source dialog box appears.

    8)     In the Data source list, select <other>.

    9)     In the Data provider list, select .NET Framework Data Provider for OLE DB as the provider.

    10)  (Optional) Clear the Always use this selection check box.

    11)  Click Continue.

    12)  The Connection Properties dialog box appears.

    13)  Select Microsoft Office 12.0 Access Database Engine OLE DB Provider as the provider.

    14)  Enter the path to the .xlsx file.

    15)  Click on the Advanced… button.

    16)  The Anvanced Properties dialog appears.

    17)  Set the Extended Properties to “Excel 12.0 Xml.”

    18)  Click OK.

    19)  Under Choose from the available tables for this data source, select the check box next to each table (named range) that you want to include in the data source.

    20)  Click Finish

     

     

  • Orcas Feature: Expected HTTP Status Code

    Expected HTTP Status Code is a new Web test request property that specifies the numeric HTTP status code that indicates success for the request. The value can be set on top level requests and explicitly added dependent requests. The primary purpose of the property is to ignore certain failures on dependent requests. By default, the recorder sets this value to 0, which means any 200 or 300 level return code is a success and any 400 or 500 level status is a failure.

     

    Explicitly Added Dependents

    Parsed dependent requests collection is generated at runtime. It is the result of parsing the response of the top level page request. An explicitly added Dependent request refers to a request added by right clicking on a top-level request and selecting “Add Dependent Request”.

     

    If a dependent request is explicitly added to a request, that dependent will always be fetched according to the definition of the request. If the request fails, but matches the Expected HTTP code on the request definition, the dependent request will be marked as pass. For example, the value can be set to 404 if you expect that the request will not be found on the web server.

     

    If a dependent request is explicitly added to a request, and Parse Dependents is set to true, and a matching request is parsed, the matching dependent request will not be submitted.

     

    Redirects

    For redirected requests, if the Follow Redirects property is set to true, the Expected HTTP Status Code works against the redirected URL.

  • Orcas Beta Feature: Recorded Response URL Property and Validate Response URL Rule

    Recorded Response URL is a new Web Test Request property that captures the final URL for a request after following all redirects. The Web test recorder automatically populates this field with the appropriate value. Query string parameters are ignored in the URL. If you modify the URL of a request or set Follow Redirects to false, you may need to manually update the Recorded Response URL property.

     

    Validate Response URL is a build-in test-level validation rule and it applies to all requests in a Web test. It validates that the response URL after redirects are followed is the same as the Recorded Response URL. It is added automatically after requests have been recorded. The primary purpose of this rule is to detect redirects to an error page.

  • Orcas Feature: Test-level Validation Rules

    In VSTS 2005, users can only add request-level validation rules from Web Test Editor; while in Orcas, Web Tests have a new collection of test-level validation rules. These rules will fire on every request in the test and are a shortcut for adding the same rule to every request. By default, rules will only apply to top-level requests.

     

    A Test-level validation rule can be added by right clicking on the root node of a Web test and selecting “Add Validation Rule…” All test-level validation rules are listed under Validation Rules node in the Editor. After running a Web test, the results will be reported as if the rule were on the request.

  • How to Enable VSTS Logging?

    Normally, when a test fails to execute or is aborted, a brief error message will be displayed in the Test Result Window. For a Web test that completes with error(s), detailed information can be found in the Web Test Playback window. For a load test completes with error(s), the errors are written to the Errors table, Tests table, and sometimes also the Requests table. Under certain (rare) conditions, it is difficult to find out why VSTS or the system does not behave as expected based on the given error messages and you may turn on VSTS tracing.

    If you are running test locally, enable logging for the VSTestHost process.

    1.     Open <Program Files>\Microsoft Visual Studio 9.0\Common7\IDE\VsTestHost.exe.config file.

    2.     Add the following system.diagnostics section.

    <system.diagnostics>

        <trace autoflush="true" indentsize="4">

            <listeners>                   

               <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="c:\VSTestHost.log" />

            </listeners>

        </trace>

        <switches>

            <!-- You must use integral values for "value".  Use 0 for off, 1 for

                 error, 2 for warn, 3 for info, and 4 for verbose. -->

            <add name="EqtTraceLevel" value="3" />

        </switches>

      </system.diagnostics>

     

    3.     Specify the path to the log file and the trace level.

    If you are running test on Rig, enable logging for the Agent and/or Controller processes.

     

    1.     Under <Program Files>\Microsoft Visual Studio 9.0 Team Test Load Agent\LoadTest\, find QTAgent.exe.config for Agent process and QTController.exe.config for Controller process.

    2.     In the config file, under appSettings section, locate line <add key="CreateTraceListener" value="no" />, and  change the value from “no” to “yes”.

    3.     After you modify the config files, you need to restart the Controller and Agent.

    The log files, vsttagentprocess.log and vsttcontroller.log, will be created in the same directory as the configure files.

     


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker