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

时间:2013-09-25 16:51:53

标签: c# visual-studio-2012 performance-testing coded-ui-tests

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

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

在对可能返回两个截然不同的页面之一的网页的编码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;
}