在 Web 性能测试中,我是否可以指定多个预期的响应页面



在处理编码的Web性能测试(在C#中)时,是否可以告诉Web测试需要多个有效的响应页面?我们在登录时有某些标准,并且根据某些标志,用户可能会被带到几个不同的页面,因此期望单个响应 URL 实际上是不可能的。

您不能简单地使用提取规则从可以重定向到的每个页面中提取某些内容吗?

在这里,您可以找到有关如何设置内容的一些指导:http://www.dotnetfunda.com/articles/show/901/web-performance-test-using-visual-studio-part-i

或者,如果这对您不起作用,您也可以对自定义验证规则进行编码:http://msdn.microsoft.com/en-us/library/ms182556.aspx

在可能返回两个完全不同的页面之一的网页的编码 UI 测试中,我编写了以下代码。它在该测试中工作正常,如果我再次需要类似的整理,我会调查几种可能的整理。因此,请考虑将此作为起点。

基本思想是查看检查当前网页以获取标识当前显示的预期页面的文本。如果找到,则处理该页面。如果未找到,请暂停一小段时间以允许加载页面,然后再次查看。在超时时添加,以防预期页面从未出现。

public void LookForResultPages()
{
    Int32 maxMilliSecondsToWait = 3 * 60 * 1000;
    bool processedPage = false;
    do
    {
        if ( CountProperties("InnerText", "Some text on most common page") > 0 )
        {
            ... process that page;
            processedPage = true;
        }
        else if ( CountProperties("InnerText", "Some text on another page") > 0 )
        {
            ... process that page;
            processedPage = true;
        }
        else
        {
            const Int32 pauseTime = 500;
            Playback.Wait(pauseTime); // In milliseconds
            maxMilliSecondsToWait -= pauseTime;
        }
    } while ( maxMilliSecondsToWait > 0 && !processedPage );
    if ( !processedPage )
    {
        ... handle timeout;
    }
}
public int CountProperties(string propertyName, string propertyValue)
{
    HtmlControl html = new HtmlControl(this.myBrowser);
    UITestControlCollection htmlcol = new UITestControlCollection();
    html.SearchProperties.Add(propertyName, propertyValue, PropertyExpressionOperator.Contains);
    htmlcol = html.FindMatchingControls();
    return htmlcol.Count;
}

最新更新