0

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

4

2 回答 2

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;
}
于 2013-09-26T10:09:14.240 回答
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

于 2013-09-25T17:02:26.890 回答