How to upload a file in a Web test
From this post, I see many users are having trouble with file uploads.
Really this is not as easy as it should be.
To upload a file, first record the file upload. I have a simple site that I did that on to generate this web test.
The key parameter here is obviously the file upload parameter, which recorded the file as "MyImage.gif".
At runtime, the web test engine will look for a file with the name MyImage.gif in the test deployment directory.
If I just go ahead and run this the test fails with:
Request failed: Could not find file 'C:\Users\edglas.000\Documents\Visual Studio 2008\Projects\TestProject1\TestResults\edglas_EDGLAS-LT2 2008-08-05 08_57_58\Out\MyImage.gif'.
Of course the first thing you'll notice is the file path was not recorded in the web test. So how will this file be found? and why is it looking in that directory?
When you run tests in VS, the files required to run the tests are "deployed" to a directory for the test run (see my post on deployment), in this case it is edglas_EDGLAS-LT2 2008-08-05 08_57_58. You'll get a different directory every time you run your tests. Notice this directory is available in the web test context:
The best way to handle this in your test is to actually add the file to be uploaded to your test project, then add it as a deployment item on your test. That way it will be copied to the out directory prior to running the test, and will be available during execution. This also has the advantage that if you are working with others, the test will also run on their machine (hard-coded full paths in a test are bad, as these tests will fail on another person's machine if their drive isn't set up the same way).
Once you've added the file to your project, add it as a deployment item. There's two ways to do this, on the run config or on the test. Since this file is really associated with the test, I recommend putting it on the test. This is not discoverable at all. First, open test view (Test menu | Windows | Test View) and select the web test. Then set the Deployment Items property for the web test's test element.
Now add MyImage.gif as a deployment item by clicking ... next to the deployment items property. Since this is a property on the web test, the path is relative to the web test:
Now my test runs successfully:
Another approach is to create a folder in your project where you put all your file upload files.
Then specify the relative path in the deployment item properties (relative to the web test in the project). So if my file to upload is in the FileUpload folder
Now in deployment items specify the relative path, which again is relative to the web test. Note the path in the file upload web test parameter is not relative since it will be published "flat" with no subdirectories (no changes required):
Now the test runs successfully again.
Another option is to deploy the files or entire directory using the run config settings.
For the run config, go to the Deployment tab and use the Add Directory to add your folder with files to upload. Note that this path is solution relative, since the run config is in the solution directory. The <Solution Directory> macro is automatically inserted after you select the file or directory.
Now if I go to the deployment dir using Explorer (easiest way to find it is from the web test context parameter), I see that both of my images were deployed, and my test still runs successfully. Also any new files I want to upload I can just drop them in this folder in my solution and don't have to add it as a deployment item to my test. Note that all files are published "flat", which means you can't have two different deployment files in different folders with the same name.
Hope this helps,
Ed.
Comments
Anonymous
August 05, 2008
Thanks for going over this in detail Ed. it seemed like an issue that came up over and over on the forums.. I know I must have answered it a bunch of times when I was more active there. (and I expect you folks ended up pointing other people to my responses) it's great to have a step by step on this for process.Anonymous
August 05, 2008
The comment has been removedAnonymous
August 05, 2008
Thanks Chuck, good to hear from you again! Ed.Anonymous
August 05, 2008
Amitai, mstest will look in the current directory for the dll. Are you in the release folder when you run mstest? Ed.Anonymous
August 05, 2008
Ed, Thanks for the quick answer. Yes I am in the release folder when running mstest. Any idea how I can proceed investigating this problem?Anonymous
August 05, 2008
Hi Ed, I used the option using the run config. I am also performing load testing uploading large files. My asp page has the Telerik upload control. One problem I have is with a query string parameter the telerik control inserts into the url to uniquely identify the file being uploaded as the control is streaming the file to the server. VS did not recognise the query string as a dynamic parameter. I need to assign a guid to the query string parameter for each run of the test script. Your thoughts on how to do this would be appreciated. Cheers PeterAnonymous
August 06, 2008
Peter, do you know how the guid gets generated? If it really is a GUID you need, write a request plugin that generates a guid into a context param in the PreRequest call using Guid.NewGuid().ToString(), then attach the plugin to your request and bind the value of the context parameter to the query string parameter. Ed.Anonymous
August 06, 2008
The comment has been removedAnonymous
August 06, 2008
Ed, I have a solution with more than 20 test projects, I have defined a Solution Release folder and all the projects files are placed there by the build. When I open the "Visual Studio Command Prompt" and from there cd "MySolutionRelease" and then: MSTest.exe /testcontainer:"MyTests.orderedtest" /runconfig:"..MyConfig.testrunconfig" Both" MyTests.orderedtest" and "MyConfig.testrunconfig" are found but "MyFirstWebTest.webtest" is referencing a custom plugin defined in AutomaticTesting.Utils.dll and this .dll file is in "MySolutionRelease". The orderedtest and the dll are in the same directory and the webtest is in a sub directory of it. I am getting the same error if I try to run "MyFirstWebTest.webtest" directly. Cheers AmitaiAnonymous
August 07, 2008
Hi Ed, From investigations it appears that as the asp page is rendering, the Telerik upload control inserts a javascript function. Sys.Application.add_init(function() { $create(Telerik.Web.UI.RadProgressManager, {"ajaxCallUrl":"/SchoolsGold/Telerik.RadUploadProgressHandler.ashx","clientStateFieldID":"ctl00_DefaultContent_RadProgressManager1_ClientState","formId":"aspnetForm","pageGUID":"7a457cf2-2802-4352-947b-d04ee6238522","shouldRegisterForSubmit":false}, null, null, $get("ctl00_DefaultContent_RadProgressManager1")); The client side javascript of the telerik controls adds the PageGUID into the querystring. Would writing an extraction rule to and then use the context parameter to build the querystring be an good approach? Cheers PeterAnonymous
August 11, 2008
Peter, yes extracting the GUID from the ajax call response is the right way to go. I would have expected dynamic parameter detection to pick this up, but it missed it? Ed.Anonymous
August 11, 2008
Ed, unfortunately there was no dynamic parameter detected. PeterAnonymous
August 11, 2008
The comment has been removedAnonymous
February 19, 2009
Hi Ed We are using VSTS for Peformance Testing of Sharepoint application. In the file upload scenario, i have added the file upload parameter & also deployed the file as a deployment item. However the upload does not happen successfully. I have the below queries:
- Can u pls elaborate on the file upload parameter. How to identify to which request it should be added? what should be entered in the the "Name" field of the file upload parameter?
- If the file is available in the "out" folder of the results directory, can we assume that we have correctly added the file as a deployment item to the test?
Anonymous
February 13, 2010
Hello there I am trying to record a web test on a MOSS application, for uploading an image, when I run the script it fails and gives me the following error: Request failed: Context parameter '$HIDDEN1.MSOShowUnapproved_Xml' not found in test context Request failed: Context parameter '$HIDDEN2.MSOShowUnapproved_Xml' not found in test context Request failed: Context parameter '$HIDDEN3.MSOShowUnapproved_Xml' not found in test context Although I have added the image in the [Deployment Items] property for this webtest, from the class view. Can anyone please advise me what else to do to solve this?Anonymous
January 21, 2013
Any suggestion on how I can make this work in the VS 2012 edition?Anonymous
July 31, 2013
Hi I have uploaded an image but its actually taking some alphanumeric value instead of image file name which I had uploaded. Need your halp on this.Anonymous
October 24, 2013
I also had this error and I fixed as you say, but still error. I used Visual Studio 2013. How to fix?Anonymous
November 10, 2013
How big files could be uploaded using VSTS? Can we upload a 5 GB file if the network supports or there is any limitaions? Please let us know?Anonymous
January 15, 2014
Hi Ed...Thank You for the stepp by step description. It really helps a core manual tester like me. I am running a web test scenario where the file uploaded is uniqu each time its uploaded. Now if I add multiple files to the Deployment item relative to web test, how do i ensure that when I do the load test for this scenario, it picks up a different file each time?Anonymous
January 19, 2014
How to do file upload in 2012 version? I can't see option 1 and 2 doable in 2012. I can't see the test view section even though I followed the steps mentioned in customized your tool via tool->Customize->Add new tool bar etc...are there any setting I'm missing to do it? Looks like easy way 2008.. Awaiting the response...Anonymous
February 21, 2014
Tuve el mismo problema pero en Visual Studio 2013. Traté de seguir los pasos que se indican en ésta página pero al parecer en ésta versión las cosas han cambiado. Sea como fuere, lo resolví ejecutando una prueba de mi aplicación en el ambiente local (http://localhost/Proyecto/) y se copio el archivo de carga automáticamente al proyecto, cosa que no sucedió cuando ejecute la prueba sobre el proyecto publicado (www.pagina.com/Proyecto). Luego que terminó la prueba, modifiqué todos los enlaces reemplazando http://locahost por la URL de mi proyecto publicado.Anonymous
August 19, 2014
My HTML5 uploader uploads files with multiple chunk, if I add the file in deployment item then VSTS is not able to devide the file in multiple different chunk , it sends the duplicate chunk body so I get corrupted files. Can you please solve the problem.Anonymous
September 03, 2014
hi, I am working with VSTS 2012 to check in a file from my browser. I tried the options provided by Ed above but in my case they are not working. I am having 4 dynamic parameters in my query string such as Link ID, hwnd, DocID and DocName. I tried to add extraction rule but I am not finding these values anywhere in the previous request. I did not get any errors while running the test but file is not uploaded after the test run. Please suggest!!!!Anonymous
February 05, 2015
Hi Ed, Thanks for such great information. Out of two options you provided, I have choose the second option, by Test Setting --> Deployment --> add File. The reason I choose this is I am using Visual Studio 2013 ultimate where I couldn't see "Test View". But I see "File attachment failed" error. would you please help me why this happened and how to attach a file during webtest run. When I see the request content-Type : Multipart / form-data; boundary = --------------------------------7d42893280670 #ICOrigFileName 05022015040041786UpLoad_LoadTest.docx But orignal path is C:Usersmynamevisual studio 2013projectsfilesToUpload filename is : FileToUpload.docxAnonymous
December 27, 2015
Hardcoding is bad, but as a quick workaround it can be handly. Not able to get around the above steps on VS2015 This one works: Update the 'File Upload Parameter' of the WebTest highlighted in the article to hardcoded filepath. WebTest->Expand the URL->Form Post Param->File Upload Param FileName: Upload.txt Change it to Fullname C:UploadUpload.txt NOTE:- Set 'Generate Unique Name' to False, supports versioning or overritingAnonymous
January 07, 2016
Hi Satyajit321. Thanks for information. The method you said worked. -Viswa