Upload loadtest problem solved

Aug 20, 2012 at 3:49 PM

Hi,

I have created a working version of the Upload load test which runs fine now against SharePoint 2010 in Visual Studio 2010 Ultimate. Below is the code of UploadRandomDocument.cs. All you have to do is to replace this code. You can then edit the .csv configuration files. Just make sure you edit the UploadLibraries.csv file in a way like this:

site,library,listid
/,Shared%20Documents,%7b2D40D060-B206-49CE-938B-FBE5A6FB5775%7d

If you get the GUID of the Upload Document button (right mouse button -> copy shortcut), make sure to replace "{" by "%7b" and "}" by "%7d". Do not replace "-" by "%2d". Use the example above.

Here is the working code of UploadRandomDocument.cs

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


    [DeploymentItem("Config\\Config.xml")]
    [DataSource("ConfigXml", "Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\Config.xml", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, "Config")]
    [DeploymentItem("Config\\Users.csv")]
    [DataSource("Users", "Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Users.csv", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, "Users#csv")]
    [DeploymentItem("Config\\UploadDocs.csv")]
    [DataSource("UploadDocs", "Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\UploadDocs.csv", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, "UploadDocs#csv")]
    [DeploymentItem("Config\\UploadLibraries.csv")]
    [DataSource("UploadLibraries", "Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\UploadLibraries.csv", Microsoft.VisualStudio.TestTools.WebTesting.DataBindingAccessMethod.Sequential, "UploadLibraries#csv")]
    [DataBinding("ConfigXml", "Config", "UrlRoot", "ConfigXml.Config.UrlRoot")]
    [DataBinding("Users", "Users#csv", "password", "Users.Users#csv.password")]
    [DataBinding("Users", "Users#csv", "username", "Users.Users#csv.username")]
    [DataBinding("UploadDocs", "UploadDocs#csv", "file", "UploadDocs.UploadDocs#csv.file")]
    [DataBinding("UploadLibraries", "UploadLibraries#csv", "library", "UploadLibraries.UploadLibraries#csv.library")]
    [DataBinding("UploadLibraries", "UploadLibraries#csv", "listid", "UploadLibraries.UploadLibraries#csv.listid")]
    [DataBinding("UploadLibraries", "UploadLibraries#csv", "site", "UploadLibraries.UploadLibraries#csv.site")]
    public class UploadRandomDocument : WebTest
    {

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

        public override IEnumerator<WebTestRequest> GetRequestEnumerator()
        {
            this.UserName = this.Context["Users.Users#csv.username"].ToString();
            this.Password = this.Context["Users.Users#csv.password"].ToString();

            // 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);
            }

            string fileLocation = Guid.NewGuid().ToString() + ".docx";
            System.IO.File.Copy(this.Context["UploadDocs.UploadDocs#csv.file"].ToString(), fileLocation);

            WebTestRequest request1 = new WebTestRequest((this.Context["ConfigXml.Config.UrlRoot"].ToString()
                            + (this.Context["UploadLibraries.UploadLibraries#csv.site"].ToString())
                            + (this.Context["UploadLibraries.UploadLibraries#csv.library"].ToString() + "/Forms/AllItems.aspx")));
            request1.QueryStringParameters.Add("List", this.Context["UploadLibraries.UploadLibraries#csv.listid"].ToString(), false, false);
            ExtractHiddenFields extractionRule1 = new ExtractHiddenFields();
            extractionRule1.ContextParameterName = "";
            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((this.Context["ConfigXml.Config.UrlRoot"].ToString()
                            + (this.Context["UploadLibraries.UploadLibraries#csv.site"].ToString() + "_layouts/Upload.aspx")));
            request2.QueryStringParameters.Add("List", this.Context["UploadLibraries.UploadLibraries#csv.listid"].ToString(), false, false);
            request2.QueryStringParameters.Add("RootFolder", "", false, false);
            request2.QueryStringParameters.Add("IsDlg", "1", false, false);
            ExtractHiddenFields extractionRule2 = new ExtractHiddenFields();
            extractionRule2.Required = true;
            extractionRule2.HtmlDecode = true;
            extractionRule2.ContextParameterName = "2";
            request2.ExtractValues += new EventHandler<ExtractionEventArgs>(extractionRule2.Extract);
            // CJ: added ThinkTime
            request2.ThinkTime = 15;
            yield return request2;
            request2 = null;

            WebTestRequest request3 = new WebTestRequest((this.Context["ConfigXml.Config.UrlRoot"].ToString()
                             + (this.Context["UploadLibraries.UploadLibraries#csv.site"].ToString() + "_layouts/UploadEx.aspx")));
            request3.Method = "POST";
            request3.QueryStringParameters.Add("List", this.Context["UploadLibraries.UploadLibraries#csv.listid"].ToString(), false, false);
            request3.QueryStringParameters.Add("RootFolder", "", false, false);
            request3.QueryStringParameters.Add("IsDlg", "1", false, false);
            FormPostHttpBody request3Body = new FormPostHttpBody();
            request3Body.FormPostParameters.Add("MSOWebPartPage_PostbackSource", this.Context["$HIDDEN2.MSOWebPartPage_PostbackSource"].ToString());
            request3Body.FormPostParameters.Add("MSOTlPn_SelectedWpId", this.Context["$HIDDEN2.MSOTlPn_SelectedWpId"].ToString());
            request3Body.FormPostParameters.Add("MSOTlPn_View", this.Context["$HIDDEN2.MSOTlPn_View"].ToString());
            request3Body.FormPostParameters.Add("MSOTlPn_ShowSettings", this.Context["$HIDDEN2.MSOTlPn_ShowSettings"].ToString());
            request3Body.FormPostParameters.Add("MSOGallery_SelectedLibrary", this.Context["$HIDDEN2.MSOGallery_SelectedLibrary"].ToString());
            request3Body.FormPostParameters.Add("MSOGallery_FilterString", this.Context["$HIDDEN2.MSOGallery_FilterString"].ToString());
            request3Body.FormPostParameters.Add("MSOTlPn_Button", this.Context["$HIDDEN2.MSOTlPn_Button"].ToString());
            request3Body.FormPostParameters.Add("__EVENTTARGET", "ctl00$PlaceHolderMain$ctl03$RptControls$btnOK");
            request3Body.FormPostParameters.Add("__EVENTARGUMENT", this.Context["$HIDDEN2.__EVENTARGUMENT"].ToString());
            request3Body.FormPostParameters.Add("MSOSPWebPartManager_DisplayModeName", this.Context["$HIDDEN2.MSOSPWebPartManager_DisplayModeName"].ToString());
            request3Body.FormPostParameters.Add("MSOSPWebPartManager_ExitingDesignMode", this.Context["$HIDDEN2.MSOSPWebPartManager_ExitingDesignMode"].ToString());
            request3Body.FormPostParameters.Add("MSOWebPartPage_Shared", this.Context["$HIDDEN2.MSOWebPartPage_Shared"].ToString());
            request3Body.FormPostParameters.Add("MSOLayout_LayoutChanges", this.Context["$HIDDEN2.MSOLayout_LayoutChanges"].ToString());
            request3Body.FormPostParameters.Add("MSOLayout_InDesignMode", this.Context["$HIDDEN2.MSOLayout_InDesignMode"].ToString());
            request3Body.FormPostParameters.Add("MSOSPWebPartManager_OldDisplayModeName", this.Context["$HIDDEN2.MSOSPWebPartManager_OldDisplayModeName"].ToString());
            request3Body.FormPostParameters.Add("MSOSPWebPartManager_StartWebPartEditingName", this.Context["$HIDDEN2.MSOSPWebPartManager_StartWebPartEditingName"].ToString());
            request3Body.FormPostParameters.Add("MSOSPWebPartManager_EndWebPartEditing", this.Context["$HIDDEN2.MSOSPWebPartManager_EndWebPartEditing"].ToString());
            request3Body.FormPostParameters.Add("_maintainWorkspaceScrollPosition", this.Context["$HIDDEN2._maintainWorkspaceScrollPosition"].ToString());
            request3Body.FormPostParameters.Add("__REQUESTDIGEST", this.Context["$HIDDEN2.__REQUESTDIGEST"].ToString());
            request3Body.FormPostParameters.Add("__VIEWSTATE", this.Context["$HIDDEN2.__VIEWSTATE"].ToString());
            request3Body.FormPostParameters.Add("__SCROLLPOSITIONX", this.Context["$HIDDEN2.__SCROLLPOSITIONX"].ToString());
            request3Body.FormPostParameters.Add("__SCROLLPOSITIONY", this.Context["$HIDDEN2.__SCROLLPOSITIONY"].ToString());
            request3Body.FormPostParameters.Add("__EVENTVALIDATION", this.Context["$HIDDEN2.__EVENTVALIDATION"].ToString());
            request3Body.FormPostParameters.Add("ctl00$PlaceHolderSearchArea$ctl01$ctl00", this.Context["$HIDDEN2.ctl00$PlaceHolderSearchArea$ctl01$ctl00"].ToString());
            request3Body.FormPostParameters.Add("ctl00$PlaceHolderSearchArea$ctl01$ctl01", this.Context["$HIDDEN2.ctl00$PlaceHolderSearchArea$ctl01$ctl01"].ToString());
            request3Body.FormPostParameters.Add("InputKeywords", "Search this site...");
            request3Body.FormPostParameters.Add("ctl00$PlaceHolderSearchArea$ctl01$ctl05", this.Context["$HIDDEN2.ctl00$PlaceHolderSearchArea$ctl01$ctl05"].ToString());
            request3Body.FormPostParameters.Add("destination", this.Context["$HIDDEN2.destination"].ToString());
            request3Body.FormPostParameters.Add(new FileUploadParameter("ctl00$PlaceHolderMain$UploadDocumentSection$ctl03$InputFile", fileLocation, "application/x-zip-compressed", true));
            request3Body.FormPostParameters.Add("ctl00$PlaceHolderMain$UploadDocumentSection$ctl03$OverwriteSingle", "on");
            request3Body.FormPostParameters.Add("__spText1", "");
            request3Body.FormPostParameters.Add("__spText2", "");
            request3.Body = request3Body;
            yield return request3;
            request3 = null;

            WebTestRequest request4 = new WebTestRequest((this.Context["ConfigXml.Config.UrlRoot"].ToString()
                            + (this.Context["UploadLibraries.UploadLibraries#csv.site"].ToString() + "_layouts/blank.htm")));
            yield return request4;
            request4 = null;

            WebTestRequest request5 = new WebTestRequest((this.Context["ConfigXml.Config.UrlRoot"].ToString()
                            + (this.Context["UploadLibraries.UploadLibraries#csv.site"].ToString())
                            + (this.Context["UploadLibraries.UploadLibraries#csv.library"].ToString() + "/Forms/AllItems.aspx")));
            request5.Method = "POST";
            FormPostHttpBody request5Body = new FormPostHttpBody();
            request5Body.FormPostParameters.Add("MSOWebPartPage_PostbackSource", this.Context["$HIDDEN1.MSOWebPartPage_PostbackSource"].ToString());
            request5Body.FormPostParameters.Add("MSOTlPn_SelectedWpId", this.Context["$HIDDEN1.MSOTlPn_SelectedWpId"].ToString());
            request5Body.FormPostParameters.Add("MSOTlPn_View", this.Context["$HIDDEN1.MSOTlPn_View"].ToString());
            request5Body.FormPostParameters.Add("MSOTlPn_ShowSettings", this.Context["$HIDDEN1.MSOTlPn_ShowSettings"].ToString());
            request5Body.FormPostParameters.Add("MSOGallery_SelectedLibrary", this.Context["$HIDDEN1.MSOGallery_SelectedLibrary"].ToString());
            request5Body.FormPostParameters.Add("MSOGallery_FilterString", this.Context["$HIDDEN1.MSOGallery_FilterString"].ToString());
            request5Body.FormPostParameters.Add("MSOTlPn_Button", this.Context["$HIDDEN1.MSOTlPn_Button"].ToString());
            request5Body.FormPostParameters.Add("__EVENTTARGET", this.Context["$HIDDEN1.__EVENTTARGET"].ToString());
            request5Body.FormPostParameters.Add("__EVENTARGUMENT", this.Context["$HIDDEN1.__EVENTARGUMENT"].ToString());
            request5Body.FormPostParameters.Add("__REQUESTDIGEST", this.Context["$HIDDEN1.__REQUESTDIGEST"].ToString());
            request5Body.FormPostParameters.Add("MSOSPWebPartManager_DisplayModeName", this.Context["$HIDDEN1.MSOSPWebPartManager_DisplayModeName"].ToString());
            request5Body.FormPostParameters.Add("MSOSPWebPartManager_ExitingDesignMode", this.Context["$HIDDEN1.MSOSPWebPartManager_ExitingDesignMode"].ToString());
            request5Body.FormPostParameters.Add("MSOWebPartPage_Shared", this.Context["$HIDDEN1.MSOWebPartPage_Shared"].ToString());
            request5Body.FormPostParameters.Add("MSOLayout_LayoutChanges", this.Context["$HIDDEN1.MSOLayout_LayoutChanges"].ToString());
            request5Body.FormPostParameters.Add("MSOLayout_InDesignMode", this.Context["$HIDDEN1.MSOLayout_InDesignMode"].ToString());
            request5Body.FormPostParameters.Add("_wpSelected", this.Context["$HIDDEN1._wpSelected"].ToString());
            request5Body.FormPostParameters.Add("_wzSelected", this.Context["$HIDDEN1._wzSelected"].ToString());
            request5Body.FormPostParameters.Add("MSOSPWebPartManager_OldDisplayModeName", this.Context["$HIDDEN1.MSOSPWebPartManager_OldDisplayModeName"].ToString());
            request5Body.FormPostParameters.Add("MSOSPWebPartManager_StartWebPartEditingName", this.Context["$HIDDEN1.MSOSPWebPartManager_StartWebPartEditingName"].ToString());
            request5Body.FormPostParameters.Add("MSOSPWebPartManager_EndWebPartEditing", this.Context["$HIDDEN1.MSOSPWebPartManager_EndWebPartEditing"].ToString());
            request5Body.FormPostParameters.Add("_maintainWorkspaceScrollPosition", this.Context["$HIDDEN1._maintainWorkspaceScrollPosition"].ToString());
            request5Body.FormPostParameters.Add("__VIEWSTATE", this.Context["$HIDDEN1.__VIEWSTATE"].ToString());
            request5Body.FormPostParameters.Add("__SCROLLPOSITIONX", this.Context["$HIDDEN1.__SCROLLPOSITIONX"].ToString());
            request5Body.FormPostParameters.Add("__SCROLLPOSITIONY", this.Context["$HIDDEN1.__SCROLLPOSITIONY"].ToString());
            request5Body.FormPostParameters.Add("__EVENTVALIDATION", this.Context["$HIDDEN1.__EVENTVALIDATION"].ToString());
            request5Body.FormPostParameters.Add("ctl00$ctl29", this.Context["$HIDDEN1.ctl00$ctl29"].ToString());
            request5Body.FormPostParameters.Add("ctl00$PlaceHolderSearchArea$ctl01$ctl00", this.Context["$HIDDEN1.ctl00$PlaceHolderSearchArea$ctl01$ctl00"].ToString());
            request5Body.FormPostParameters.Add("ctl00$PlaceHolderSearchArea$ctl01$ctl01", this.Context["$HIDDEN1.ctl00$PlaceHolderSearchArea$ctl01$ctl01"].ToString());
            request5Body.FormPostParameters.Add("InputKeywords", "Search this site...");
            request5Body.FormPostParameters.Add("ctl00$PlaceHolderSearchArea$ctl01$ctl05", this.Context["$HIDDEN1.ctl00$PlaceHolderSearchArea$ctl01$ctl05"].ToString());
            request5Body.FormPostParameters.Add("__spText1", "");
            request5Body.FormPostParameters.Add("__spText2", "");
            request5Body.FormPostParameters.Add("_wpcmWpid", this.Context["$HIDDEN1._wpcmWpid"].ToString());
            request5Body.FormPostParameters.Add("wpcmVal", this.Context["$HIDDEN1.wpcmVal"].ToString());
            request5.Body = request5Body;
            yield return request5;
            request5 = null;
        }
    }
}