为什么某些按钮点击在编码的Ui测试中花费的时间超过了预期的时间

时间:2014-12-01 07:29:30

标签: c# coded-ui-tests

我正在使用Microsoft.visualStudio.TestTools.UITesting进行UI自动化,并发现有时对于特定按钮,按钮点击需要超过预期时间,例如3分钟左右。我的代码如下:

WebPage.Button_WithId_Click(" OK&#34);

Button_WithId_Click的定义

public void Button_WithId_Click(string itemId)
{
    UiElement_ClickLocation(PrepareElementWithId(new HtmlButton(this.BrowserMainWindow.UiMobiControlDocument), itemId));
}
private HtmlControl PrepareElementWithId(HtmlControl uiElelement, string itemId)
{
    return PrepareElementWithPropertyName(uiElelement, HtmlControl.PropertyNames.Id, itemId);
}

private HtmlControl PrepareElementWithPropertyName(HtmlControl uiElelement, string propertyName, string itemValue)
{
    uiElelement.SearchProperties[propertyName] = itemValue;
    return PrepareElement(uiElelement);
}

private HtmlControl PrepareElement(HtmlControl uiElelement)
{
    HtmlControl controlToPrepare = uiElelement;
    try
    {
        uiElelement.WaitForControlExist();
        uiElelement.WaitForControlEnabled();
        uiElelement.WaitForControlReady();
        var matchingControl = uiElelement.FindMatchingControls();
        if (matchingControl.Count == 1)
        {
            matchingControl[0].EnsureClickable();
            return (HtmlControl)matchingControl[0];
        }
        return GetActiveControl(uiElelement);
    }
    catch (Exception)
    {
        //often element can not be clicked because it's obstructed by loading mask
        //TODO: promote to app.config
        const int webConsoleDefaultTimeout = 30000;

        uiElelement.WaitForControlExist();
        uiElelement.WaitForControlEnabled();
        uiElelement.WaitForControlReady();
        var matchingControl = uiElelement.FindMatchingControls();
        if (matchingControl.Count == 1)
        {
            matchingControl[0].EnsureClickable();
            return (HtmlControl)matchingControl[0];
        }
        return GetActiveControl(uiElelement);
    }
}

没有加载掩码问题,控件即按钮在对话框中可用,但需要大约3分钟才能点击。什么是决议。

0 个答案:

没有答案