visual-studioload-testingweb-testingwebtest

How to upload a file with unique name in Visual Studio Webtest


Using Visual Studio 2015 I've recorded a web test which includes uploading a file to the website. This site doesn't allow to upload files with the same name. In webtest scenario I have a File Upload Parameter with the property Generate Unique Name set to True:

enter image description here

But every time I try to run this webtest it will fail when trying to upload a file, because file with given name already exists.

In my project folder I checked TestResults folder, which copies the file I need to upload with the same name it was recorded, rather then giving it a unique name.

I've seen some suggestion about this problem and tried to check Enable deployment option in my .testsettings file among with adding the exact path to this file in the Files to deploy section under this check. But still it doesn't solve the problem.

UPD. Debug of a single webtest run.

Request: enter image description here Response:

Headers:

HTTP/1.1 500 Internal Server Error
X-AspNetMvc-Version : 5.2
Persistent-Auth : true
Content-Length : 312
Cache-Control : private, s-maxage=0
Content-Type : application/json; charset=utf-8
Date : Tue, 06 Mar 2018 14:42:48 GMT
Server : Microsoft-IIS/8.5
X-AspNet-Version : 4.0.30319
X-Powered-By : ASP.NET

Body:

0x00000000  7B  22  63  6F  6E  66  69  72  6D  61  74  69  6F  6E  22  3A    {"confirmation":
0x00000010  7B  22  6D  65  73  73  61  67  65  22  3A  22  D0  94  D0  BE    {"message":"....
0x00000020  D0  BA  D1  83  D0  BC  D0  B5  D0  BD  D1  82  20  D1  81  20    ............ .. 
0x00000030  D0  B8  D0  BC  D0  B5  D0  BD  D0  B5  D0  BC  20  5C  75  30    ............ \u0
0x00000040  30  32  37  32  6D  62  2E  70  64  66  5C  75  30  30  32  37    0272mb.pdf\u0027
0x00000050  20  D1  83  D0  B6  D0  B5  20  D1  81  D1  83  D1  89  D0  B5     ...... ........
0x00000060  D1  81  D1  82  D0  B2  D1  83  D0  B5  D1  82  2E  20  D0  A1    ............. ..
0x00000070  D0  BE  D0  B7  D0  B4  D0  B0  D1  82  D1  8C  20  D0  BD  D0    ............ ...
0x00000080  BE  D0  B2  D1  83  D1  8E  20  D0  B2  D0  B5  D1  80  D1  81    ....... ........
0x00000090  D0  B8  D1  8E  20  D0  B4  D0  BE  D0  BA  D1  83  D0  BC  D0    .... ...........
0x000000A0  B5  D0  BD  D1  82  D0  B0  3F  22  2C  22  73  68  6F  72  74    .......?","short
0x000000B0  4D  65  73  73  61  67  65  22  3A  22  D0  92  D0  B5  D1  80    Message":"......
0x000000C0  D1  81  D0  B8  D1  8F  20  D0  B4  D0  BE  D0  BA  D1  83  D0    ...... .........
0x000000D0  BC  D0  B5  D0  BD  D1  82  D0  B0  20  D0  BD  D0  B5  20  D0    ......... .... .
0x000000E0  BE  D0  B1  D0  BD  D0  BE  D0  B2  D0  BB  D0  B5  D0  BD  D0    ................
0x000000F0  B0  22  7D  2C  22  6D  65  73  73  61  67  65  22  3A  22  D0    ."},"message":".
0x00000100  92  D0  B5  D1  80  D1  81  D0  B8  D1  8F  20  D0  B4  D0  BE    ........... ....
0x00000110  D0  BA  D1  83  D0  BC  D0  B5  D0  BD  D1  82  D0  B0  20  D0    .............. .
0x00000120  BD  D0  B5  20  D0  BE  D0  B1  D0  BD  D0  BE  D0  B2  D0  BB    ... ............
0x00000130  D0  B5  D0  BD  D0  B0  22  7D                                    ......"}   

Details: enter image description here


Solution

  • Came up with some workaround. I generated code out of my .webtest and added Guid.NewGuid() to the value of fileName parameter. So the piece of code which generates Form Post Parameters looks like this:

    FormPostHttpBody request2Body = new FormPostHttpBody();
    request2Body.FormPostParameters.Add(new FileUploadParameter("null", "2mb.pdf", "application/pdf", true));
    request2Body.FormPostParameters.Add("fileName", Guid.NewGuid() + "2mb.pdf");
    request2.Body = request2Body;
    

    Made a .loadtest based on this coded .webtest and it finally started adding Guids to the name of the files which are being uploaded during loadtest. Perhaps it's not the best solution, but attempts to delete fileName parameter, change the Name parameter value from null to something else, etc. didn't help.