locked
coded ui testing - hidden control error RRS feed

  • Question

  • Hi,

    I was hoping for some help. When I run my test methods one at a time it run successfully with no errors. But when I run them sequentially one after the other my second test method gives me "Cannot perform 'Click' on the hidden control." error. I was hoping to get some guidance on how to fix this issue. It has stumped me for the past few hours.

    [DataSource("System.Data.Odbc", "Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};dbq=|DataDirectory|\\Data\\Entities.xls;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5;readonly=true", "Sheet1$", DataAccessMethod.Sequential), TestMethod]
            public void AddAttributesSingleLine()
            {
                // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
                // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
                OpenBrowser();
                this.UIMap.GoToEntity();
                String entity = TestContext.DataRow["Entity"].ToString();
                String attributeType = TestContext.DataRow["AttributeType"].ToString();
                if (entity.Equals("Person") && attributeType.Equals("SingleLine"))
                {
                    this.UIMap.GoToPersonEntity();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttribute();
                }
                else if (entity.Equals("Transaction") && attributeType.Equals("SingleLine"))
                {
                    this.UIMap.GoToTransactionEntity();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttribute();
                }
                else if (entity.Equals("Account") && attributeType.Equals("SingleLine"))
                {
                    this.UIMap.GoToAccountEntity();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttribute();
                }
                else if (entity.Equals("Tmp") && attributeType.Equals("SingleLine"))
                {
                    this.UIMap.GoToTmpEntity();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddSingleLineEditorTextAttribute();
                }
            }
    
            [DataSource("System.Data.Odbc", "Dsn=Excel Files;Driver={Microsoft Excel Driver (*.xls)};dbq=|DataDirectory|\\Data\\Entities.xls;defaultdir=.;driverid=790;maxbuffersize=2048;pagetimeout=5;readonly=true", "Sheet1$", DataAccessMethod.Sequential), TestMethod]
            public void AddAttributesEmail()
            {
                // To generate code for this test, select "Generate Code for Coded UI Test" from the shortcut menu and select one of the menu items.
                // For more information on generated code, see http://go.microsoft.com/fwlink/?LinkId=179463
    
                OpenBrowser();
                this.UIMap.GoToEntity();
                String entity = TestContext.DataRow["Entity"].ToString();
                String attributeType = TestContext.DataRow["AttributeType"].ToString();
                if (entity.Equals("Person") && attributeType.Equals("Email"))
                {
                    this.UIMap.GoToPersonEntity();
                    this.UIMap.AddEmailAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddEmailAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddEmailAttribute();
                }
                else if (entity.Equals("Transaction") && attributeType.Equals("Email"))
                {
                    this.UIMap.GoToTransactionEntity();
                    this.UIMap.AddEmailAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddEmailAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddEmailAttribute();
                }
                else if (entity.Equals("Account") && attributeType.Equals("Email"))
                {
                    this.UIMap.GoToAccountEntity();
                    this.UIMap.AddEmailAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddEmailAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddEmailAttribute();
                }
                else if (entity.Equals("Tmp") && attributeType.Equals("Email"))
                {
                    this.UIMap.GoToTmpEntity();
                    this.UIMap.AddEmailAttributeParams.UILabelEditText = TestContext.DataRow["Label"].ToString();
                    this.UIMap.AddEmailAttributeParams.UIIDEditText = TestContext.DataRow["Id"].ToString();
                    this.UIMap.AddEmailAttribute();
                }
            }



    Wednesday, March 6, 2013 8:20 PM

Answers

  • Hello Mirooshidan,

    If you mean that each test can run successfully when you run one of both test methods alone, and the second test method will fail when you run them sequentially. I would like to know if you have performed actions on the same HyperLink control in AddAttributeSingleLine method and it can work well in AddAttributeSingleLine method. Meanwhile I suggest that you try to clear browser cache using BrowserWindow.ClearCache() in AddAttributesEmail method to check the result.

    “When i try to highlight the button nothing gets highlighted,”

    Now I doubt that if your control still can be found. I suggest that you can run AddAttributesEmail method alone without AddAttributeSingleLine method in a new test project and add more search properties for this control and check it again. If the target control still can’t be highlighted when you use DrawHightlight() for this control, I doubt that there are hidden controls in your UI.

    Please use the FindMatchingControls().Count to verify whether there are some same controls in your app. And then do not set any relative coordinates, just Mouse.Click(button) and check it.

    For the hidden control, the BoundingRectangle.Width/Height value is -1.

    You could get some useful information from the following code.

    BrowserWindow ie = new BrowserWindow();

    ie.SearchProperties.Add("ClassName", "IEFrame");

    HtmlHyperlink link = new HtmlHyperlink(ie);

    link.SearchProperties.Add("InnerText", "InnerText content");

    UITestControlCollection uic = link.FindMatchingControls();

    foreach (UITestControl ui in uic)

    {

    if (ui.BoundingRectangle.Width > 0)

    {

    Mouse.Click(ui);

    break;

    }

    }

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Amanda Zhu Monday, March 18, 2013 12:38 AM
    Wednesday, March 13, 2013 1:52 AM

All replies

  • Hello Mirooshidan,

    Thank you for your post.

    Not very sure about your real app, maybe you could try to check it with the following steps.

    1. Use the Playback.PlaybackSettings.WaitForReadyTimeout = 60000
    2. Use the FindMatchingControls() to verify if more than one control matches
    3. If you use the DrawHighlight() on the control, do you see any bounding rectangle being drawn on the UI?
    4. Try to click the control with Mouse.Click(new Point(myUiControl.BoundingRectactangle.X + myUiControl.BoundingRectangle.Width, myUiControl.BoundingRectangle.Y + myUiControl.BoundingRectangle.Height/2)) to check if it can help.
    5. Similar thread: http://social.msdn.microsoft.com/Forums/en-US/vsautotest/thread/ec76299f-e8bb-4a09-a33d-f2f5fa6e4168

    If your app is a web application, you can try to refresh the web browser before the second method to check the result.

    If still no help, please provide us detailed error messages so that we can further look at this issue.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 7, 2013 8:23 AM
  • Hi Amanda,

    Thanks for your reply. I tried to refresh the page but it doesn't work. I also tried the tmieout and it still gives me the same error When i try to highlight the button nothing gets highlighted, but i see the button properly. This is happening in JQuery btw if it makes a difference. This is the output from the stack i get from the error:

    Test Name:	AddAttributesEmail
    Test FullName:	CodedUITestProject2.CodedUITest1.AddAttributesEmail
    Test Source:	c:\Users\Miro\Documents\Visual Studio 2012\Projects\CodedUITestProject2\CodedUITestProject2\CodedUITest1.cs : line 192
    Test Outcome:	Failed
    Test Duration:	0:00:59.6260859
    
    Result1 Name:	AddAttributesEmail
    Result1 Outcome:	Failed
    Result1 Duration:	0:00:29.8393625
    Result1 Message:
    Result1 StackTrace:
    
    Result2 Name:	AddAttributesEmail (Data Row 4)
    Result2 Outcome:	Failed
    Result2 Duration:	0:00:23.1509545
    Result2 Message:	
    Test method CodedUITestProject2.CodedUITest1.AddAttributesEmail threw exception: 
    Microsoft.VisualStudio.TestTools.UITest.Extension.FailedToPerformActionOnHiddenControlException: Cannot perform 'Click' on the hidden control. Additional Details: 
    TechnologyName:  'Web'
    ControlType:  'Hyperlink'
    TagName:  'A'
    Id:  ''
    Name:  ''
    Target:  ''
    InnerText:  'E-Mail Address'
     ---> System.Runtime.InteropServices.COMException: Exception from HRESULT: 0xF004F002
    Result2 StackTrace:	
    at Microsoft.VisualStudio.TestTools.UITest.Playback.Engine.IScreenElement.MouseButtonClick(Int32 x, Int32 y, Int32 nButton, Int32 fEnsureVisible, String bstrKeyModifiers)
       at Microsoft.VisualStudio.TestTools.UITest.Playback.ScreenElement.MouseButtonClick(Int32 x, Int32 y, MouseButtons button, ModifierKeys modifierKeys, Int32 ensureVisible)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Click(MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinates)
     --- End of inner exception stack trace ---
        at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowComException(COMException innerException, IPlaybackContext context)
       at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(SystemException exception, IPlaybackContext context)
       at Microsoft.VisualStudio.TestTools.UITesting.Playback.MapAndThrowException(SystemException exception, String actionName, UITestControl uiControl, Point point)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestControl.Click(MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinates)
       at Microsoft.VisualStudio.TestTools.UITesting.UITestActionExecutorCore.Click(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
       at Microsoft.VisualStudio.TestTools.UITesting.Mouse.ClickImplementation(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
       at Microsoft.VisualStudio.TestTools.UITesting.Mouse.<>c__DisplayClass6.<Click>b__5()
       at Microsoft.VisualStudio.TestTools.UITesting.CodedUITestMethodInvoker.InvokeMethod[T](Func`1 function, UITestControl control, Boolean firePlaybackErrorEvent, Boolean logAsAction)
       at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, MouseButtons button, ModifierKeys modifierKeys, Point relativeCoordinate)
       at Microsoft.VisualStudio.TestTools.UITesting.Mouse.Click(UITestControl control, Point relativeCoordinate)
       at CodedUITestProject2.UIMap.AddEmailAttribute() in c:\Users\Miro\Documents\Visual Studio 2012\Projects\CodedUITestProject2\CodedUITestProject2\UIMap.Designer.cs:line 869
       at CodedUITestProject2.CodedUITest1.AddAttributesEmail() in c:\Users\Miro\Documents\Visual Studio 2012\Projects\CodedUITestProject2\CodedUITestProject2\CodedUITest1.cs:line 219
    
    

    Thanks for your reply again :D

    Thursday, March 7, 2013 7:01 PM
  • Hello,

    “When i try to highlight the button nothing gets highlighted, but i see the button properly.”

    It seems that the button control is not found. Based on the error messages, I suggest that you can add greater properties to searchproperties such as Id and Name so that the target control can be found well. If the control can be found, then you can try to use Mouse.Click(new Point(myUiControl.BoundingRectactangle.X + myUiControl.BoundingRectangle.Width, myUiControl.BoundingRectangle.Y + myUiControl.BoundingRectangle.Height/2)) to click it.

    If still no help, I suggest that you can try to run AddAttributesEmail method after AddAttributesSingleLine method to check if you still get the same issue.

    If you have other environments, you can try this scenario on another machine e to check the result. Maybe the issue is related to your test environment.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, March 8, 2013 1:59 AM
  • Hi Amanda,

    I tried to run email after single line but I still get the same issue. I also tried in a different test environment but still have no luck.

    Any more ideas?

    Thanks for your help once again

    Tuesday, March 12, 2013 3:24 PM
  • Hello Mirooshidan,

    If you mean that each test can run successfully when you run one of both test methods alone, and the second test method will fail when you run them sequentially. I would like to know if you have performed actions on the same HyperLink control in AddAttributeSingleLine method and it can work well in AddAttributeSingleLine method. Meanwhile I suggest that you try to clear browser cache using BrowserWindow.ClearCache() in AddAttributesEmail method to check the result.

    “When i try to highlight the button nothing gets highlighted,”

    Now I doubt that if your control still can be found. I suggest that you can run AddAttributesEmail method alone without AddAttributeSingleLine method in a new test project and add more search properties for this control and check it again. If the target control still can’t be highlighted when you use DrawHightlight() for this control, I doubt that there are hidden controls in your UI.

    Please use the FindMatchingControls().Count to verify whether there are some same controls in your app. And then do not set any relative coordinates, just Mouse.Click(button) and check it.

    For the hidden control, the BoundingRectangle.Width/Height value is -1.

    You could get some useful information from the following code.

    BrowserWindow ie = new BrowserWindow();

    ie.SearchProperties.Add("ClassName", "IEFrame");

    HtmlHyperlink link = new HtmlHyperlink(ie);

    link.SearchProperties.Add("InnerText", "InnerText content");

    UITestControlCollection uic = link.FindMatchingControls();

    foreach (UITestControl ui in uic)

    {

    if (ui.BoundingRectangle.Width > 0)

    {

    Mouse.Click(ui);

    break;

    }

    }

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Amanda Zhu Monday, March 18, 2013 12:38 AM
    Wednesday, March 13, 2013 1:52 AM
  • Hello,

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please feel free to reopen it or submit a new question.

    Thanks for your understanding.

    Best regards,


    Amanda Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, March 18, 2013 12:38 AM