我有一个问题,希望有一个简单的解决方案,我忽略...这是我第一次使用Visual Studio性能测试工具的文件上传参数。当我第一次运行我的Web性能测试时,我的测试找到了该文件并按照我的预期上传了它。但是,当我现在重新运行测试时,我在"详细信息"中得到500内部服务器错误。结果部分,我注意到我的文件名包含了一个前缀为请求中正确名称的时间戳。由于我的文件名没有变化,这导致visual studio无法找到我的文档。
我为此测试生成了代码,因为我需要手动重置SSL设置。我的文档被移动到Test Results文件夹,因为我使用它作为DeploymentItem来装饰该方法。当我生成代码时,Visual Studio会自动执行此操作,这非常好但可能是问题...任何帮助都将非常感谢!这是我正在制作的POST请求:
WebTestRequest request11 = new WebTestRequest((this.Context["Environment"].ToString() + "/Submit/Upload"));
request11.Method = "POST";
request11.Headers.Add(new WebTestRequestHeader("Referer", (this.Context["Environment"].ToString() + "/Submit/Index/fakefolder456")));
FormPostHttpBody request11Body = new FormPostHttpBody();
request11Body.FormPostParameters.Add(new FileUploadParameter("files", "Test3.pptx", "application/vnd.openxmlformats-officedocument.presentationml.presentation", true));
request11Body.FormPostParameters.Add("folderId", "fakeId123");
request11Body.FormPostParameters.Add("fileNamePairs", "[{\"OriginalFileName\" : \"Test3.pptx\",\"NewFileName\" : \"Test3.pptx\"}]");
request11Body.FormPostParameters.Add("__RequestVerificationToken", this.Context["$HIDDEN1.__RequestVerificationToken"].ToString());
request11.Body = request11Body;
yield return request11;
request11 = null;
答案 0 :(得分:1)
Figured out the solution to my issue-- my File Upload Parameter had a setting "Generate Unique Name" set to "true". Visual Studio's method of making a filename unique is to take today's date and time and prepend it to your given filename. Also, you need to make sure the file you want to upload is getting transferred to your output folder. I did this by double clicking my testsettings file, checking the box "Enable deployment", then adding my file to the files to be deployed. I believe this will deploy the file for every single test though... it would be preferable to deploy the file for just my test. These links helped in my research: https://blogs.msdn.microsoft.com/edglas/2008/08/05/how-to-upload-a-file-in-a-web-test/,
For those of you who read AdrianHHH's excellent help in the comments, I learned how to write web test plugins using Ben Day's Pluralsight course "Load Testing With Visual Studio" https://app.pluralsight.com/library/courses/load-testing-visual-studio-2013/table-of-contents, and my plugin looks like this:
namespace WebTestPlugins
{
public class SsoAuth : WebTestPlugin
{
public override void PreWebTest(object sender, PreWebTestEventArgs e)
{
// Set the security protocol to TLS 1.2
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
}
}
}