Freigeben über


File Upload In A Web Test: The Case Of Submitting A Form With JavaScript

 Alik Levin    This post documents steps we have taken to simulate file upload with Web Test when the form is submitted via JavaScript [vs. simple postback]. Credits go directly to Shai Raiten, MVP, brilliant young man, and the mind behind the workaround.

Quick Resource Box

The technique described in the post exploits fantastic Custom Extraction Rule extensibility options in Visual Studio 2008. It also proves once more endless usefulness of Fiddler.

The Challenge – Web Test Does Not Record File Upload

Our main scenario required to upload files to the web server. Quick search on the web revealed Ed Glas’ post How to upload a file in a Web test. The future looked great. When we followed the steps outlined in the post our Web Test kept failing in recording the file to be uploaded preventing the automation of the load test.

After quick research we identified the difference in our situation – the form was submitted by JavaScript’s Form.Submit(). That is why Visual Studio wasn’t able to record it. We used Fiddler – it captured everything just fine. Next was to save Fiddler’s capture as Visual Studio Web Test:

image 

and then add the Web Test to the solution in Visual Studio (right click on the Project in Solution Explorer-> Add-> Existing Item…).

Creating Custom Extract Rule

When we inspected the capture in Visual Studio we observed the following String Body header that actually was the uploaded file’s contents:

clip_image001

We decided to create custom Extraction Rule that would first extract the user name – the name of the files included user name – and based on it look up related file, then read its contents into context parameter. Later on we used the context parameter to dynamically add the file contents to the request:

clip_image001[5]

The rule itself looked similar to this:

 

                                                                                                                                                                                                                                    

 

 

Related Books