0

I am using Microsoft.visualStudio.TestTools.UITesting for UI automation and found that sometimes for a particular buttons , button click takes more than expected time like 3 minutes or so. My code is as follows :

WebPage.Button_WithId_Click("OK");

definition of 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);
    }
}

There is no loading mask issue the control i.e button is available on the dialog box but takes approx 3 min to get clicked. what can be the resolution.

daniele3004
  • 13,072
  • 12
  • 67
  • 75
priya
  • 852
  • 18
  • 39
  • There are many reasons for this but the most common is that the maps generated by codedui, are dependent on a strict hierarchy. The root level node starts the journey. From there, codedui traverses the nodes based on the next one it has to find. It will actually wait for the node to appear if it's not there! Until of course, a timeout happens and the search fails completely. To fix this you have to become more familiar with what and how it's attempting to find things. The best solution is to refactor the paths from the recording. Too much to train in this note. – JWP Dec 01 '14 at 09:17
  • Check this answer: http://stackoverflow.com/questions/20367855/coded-ui-test-is-slow-waiting-for-ui-thread/20371320#20371320 – AdrianHHH Dec 01 '14 at 09:33

0 Answers0