locked
UITestControl should not be shared across TestMethods. RRS feed

  • Question

  • I have a very small and basic app.

    Running two methods on the same Application Window.  Both method access a TreeViewButton that opens up a window.  There will be about 15 methods in the future accessing this same control.

    Each methods basically click on the TreeViewButton to open the window, carry out a few tasks on that window and then close/cancel the Window. 

    I'm getting the error below on the TreeViewButton.

    The Coded UI Test is running in Single Thread Apartment (STA) mode of COM.  In this mode, all the playback calls should happen from the TestMethod thread only and UITestControl should not be shared across TestMethods.

    Anyone knows how can I use a UITestControl that will be shared across many methods?  I have used an ordered list to execute sequentially, but it doesn't help.  I have placed Playback.Cleanup() after every  Test method and that doesn't help either.

    I believe that apart from the message, what's happening is that I have placed UI calls on another class and the code is trying to access the UI outside of the main thread which is where my test cases are.  I have resolved this type of problem in the past with a UI dispatcher, however, I don't know if that can fly in Coded UI Test.  The solution could be to move all UI calls to the main thread by declaring the external class a partial of the main thread class.  In any case will like to hear from someone who has resolved this problem on their end.


    NR






    Monday, March 20, 2017 2:32 AM

Answers

  • This problem went away after I took the method that clicks the button that opens the window out of the second class and put it back in the Main Thread class.  This is weird because I'm using other controls from the second class and they are working fine.  Just one single control was causing all the problem.  I have no idea as to what I was doing wrong.


    NR

    • Marked as answer by Highlander4 Thursday, March 23, 2017 1:22 AM
    Thursday, March 23, 2017 1:22 AM

All replies

  • Hi friend,

    You could try to add:

    Playback.Initialize();

    at first line of each TestMethod.

    Please let me know if it works.

    Best regards,

    Fletch


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, March 21, 2017 8:41 AM
  • This problem went away after I took the method that clicks the button that opens the window out of the second class and put it back in the Main Thread class.  This is weird because I'm using other controls from the second class and they are working fine.  Just one single control was causing all the problem.  I have no idea as to what I was doing wrong.


    NR

    • Marked as answer by Highlander4 Thursday, March 23, 2017 1:22 AM
    Thursday, March 23, 2017 1:22 AM