wpfautomated-testscoded-ui-testsmtm

Why isn't the Mouse.DoubleClick functioning properly when the Coded UI test is executed via MTM?


What I'm trying to is to double click on a row in a WPF datagrid. To achieve this I'm using the following code:

WpfTable invoiceList = new WpfTable(base.MainWindow);
invoiceList.SearchProperties.Add(WpfTable.PropertyNames.AutomationId, "datagridID");
invoiceList.WaitForControlReady(15000);

Mouse.DoubleClick(invoiceList.GetRow(0));

When I run this on my machine the test passes but when I run the same test via MTM I get the following error:

Test method org.Application.Automation.TestCases.CommentsTests.VerifyExistingCommentsTest threw exception: Microsoft.VisualStudio.TestTools.UITest.Extension.PlaybackFailureException: Cannot perform 'DoubleClick' on the control. Additional Details: TechnologyName: 'UIA' ControlType: 'Row' FrameworkId: 'WPF' ---> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.

Could someone point in the right direction as to how I could fix this?


Solution

  • In case anyone else is facing this issue, I changed my code to the following to get it to work.

    WpfControl row = invoiceList.GetRow(0);
    row.WaitForControlReady();
    
    Mouse.DoubleClick(new System.Drawing.Point(row.BoundingRectangle.X + row.BoundingRectangle.Width, row.BoundingRectangle.Y + row.BoundingRectangle.Height/2));
    

    So instead of double clicking on the WpfRow object, I used the Mouse.DoubleClick(new System.Drawing.Point()) option and passed center point (i.e System.Drawing.Point) as the parameter. As to why the previous approach didn't work, I'm afraid I cannot explain.