简体   繁体   English

有什么方法可以在Visual Studio 2015的Web /负载测试项目中更新浏览器列表?

[英]Any way to update the browser list in a Web/Load Test Project in Visual Studio 2015?

I created a Web Performance and Load Test Project in Visual Studio 2015. I created a Load test and in the wizard it gives me a list of available browsers to simulate. 我在Visual Studio 2015中创建了一个Web性能和负载测试项目。我创建了负载测试,并在向导中为我提供了可用浏览器进行模拟的列表。 The browsers it lists are extremely old (Chrome 2, Netscape). 它列出的浏览器非常老旧(Chrome 2,Netscape)。

Anyway to update the list? 无论如何要更新列表?

在此处输入图片说明

The list of browsers is taken from the files in a Visual Studio directory. 浏览器列表取自Visual Studio目录中的文件。 For the 2013 version the directory is as follows. 对于2013版本,目录如下。 Similarly named directories are used for other Visual Studio versions. 类似的命名目录用于其他Visual Studio版本。

c:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\Templates\LoadTest\Browsers

The actual *.browser files contain XML and can be edited with Notepad etc. If you know the characteristics of the browser you want to simulate then it should be simple to copy and modify an existing file. 实际的*.browser文件包含XML,并且可以使用记事本等进行编辑。如果您知道要模拟的浏览器的特征,则复制和修改现有文件应该很简单。

I have not seen any web page that specifies the details of the *.browser files. 我还没有看到任何指定*.browser文件详细信息的网页。 Part of their content is the "user agent string" and web searching should readily find the string for many new browsers. 其内容的一部分是“用户代理字符串”,并且网络搜索应该可以为许多新的浏览器轻松找到该字符串。

Be aware that standalone web tests are run differently than those run within a load test. 请注意,独立Web测试的运行方式与负载测试中的运行方式不同。 Standalone web tests are run as if by a default browser. 独立的Web测试就像默认浏览器一样运行。 Have not found any way to specify that browser. 尚未找到任何指定该浏览器的方法。 Many characteristics of the real browser may be irrelevant but the user agent string may be important. 实际浏览器的许多特性可能无关紧要,但用户代理字符串可能很重要。 I wrote the following plugin when testing a web site for it behavior when accessed by a mobile phone or a tablet. 我在测试网站通过手机或平板电脑访问时的行为时编写了以下插件。

[System.ComponentModel.Description(
    "Set the user agent to a fixed value if called from a web test. For a load "
    + "test leave it alone so the value from the browser mix is used.")]
public class SetUserAgent : WebTestPlugin
{
    public override void PreRequest(object sender, PreRequestEventArgs e)
    {
        if (e.WebTest.Context.ContainsKey("$LoadTestUserContext"))
        {
            // Leave the user agent alone, it will be set by the load test's browser mix.
        }
        else
        {
            const string UserAgent = "User-Agent";

            if (e.Request.Headers.Contains(UserAgent))
            {
                e.Request.Headers.Remove(UserAgent);
            }

            // Samsung Galaxy Tab 3 7inch.
            // e.Request.Headers.Add(UserAgent, "Mozilla/5.0 (Linux; U; Android 4.2.2; en-gb; SM-T110 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Safari/534.30");

            // Sony Xeperia S, Ion.  360x640 pixels.
            e.Request.Headers.Add(UserAgent, "Mozilla/5.0 (Linux; U; Android 4.0; en-us; LT28at Build/6.1.C.1.111) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30");
        }
    }
}

It should be easy to set user agent strings for other devices. 为其他设备设置用户代理字符串应该很容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM