繁体   English   中英

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

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

我在Visual Studio 2015中创建了一个Web性能和负载测试项目。我创建了负载测试,并在向导中为我提供了可用浏览器进行模拟的列表。 它列出的浏览器非常老旧(Chrome 2,Netscape)。

无论如何要更新列表?

在此处输入图片说明

浏览器列表取自Visual Studio目录中的文件。 对于2013版本,目录如下。 类似的命名目录用于其他Visual Studio版本。

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

实际的*.browser文件包含XML,并且可以使用记事本等进行编辑。如果您知道要模拟的浏览器的特征,则复制和修改现有文件应该很简单。

我还没有看到任何指定*.browser文件详细信息的网页。 其内容的一部分是“用户代理字符串”,并且网络搜索应该可以为许多新的浏览器轻松找到该字符串。

请注意,独立Web测试的运行方式与负载测试中的运行方式不同。 独立的Web测试就像默认浏览器一样运行。 尚未找到任何指定该浏览器的方法。 实际浏览器的许多特性可能无关紧要,但用户代理字符串可能很重要。 我在测试网站通过手机或平板电脑访问时的行为时编写了以下插件。

[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");
        }
    }
}

为其他设备设置用户代理字符串应该很容易。

暂无
暂无

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

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