locked
Example for UITestControl.WaitForControlCondition Method checking for WpfText.Text value RRS feed

  • Question

  • Hi

    I want to wait until the text value of a WpfText is a certain string. How would that be done using UITestControl.WaitForControlCondition Method when a predicate of the test function must be used and I need to reference the WpfText item I want to check text value of?

    Thanks

    RB_IA

    Monday, January 5, 2015 8:22 PM

Answers

  • Hi RB_IA,

    AdrianHHH’s idea for that code is right, he meant that he compiled the code but he did not execute it to verify whether the code can run fine. I think that code should run.

    For the code you pasted, yes, the UITestControl parameter is not sent to IsStatusDone method through  parameters within it directly, but the text is defined outside of IsStutusDone method and it is used in the IsStatusDone method.

    For your second doubt, Adrian used this API: WaitForControlCondition(Predicate<UITestControl>) which accepts a bool parameter as the specific condition instead of this API: WaitForCondition<T>(T, Predicate<T>).

    You can reference this code snippet which is used to wait till the status text of a control is “Succeeded” or “Failed”.in this blog:How To: Make playback wait for certain event?

    // Define the method to evaluate the condition

    private static bool IsStatusDoneOrError(UITestControl[] controls)

    {

        WinText statusText = controls[0] as WinText;

        WinWindow errorDialog = controls[1] as WinWindow;

        return statusText.DisplayText == "Succeeded" || errorDialog.Exists;

    }

    // In test method, wait till the method evaluates to true

    UITestControl.WaitForCondition<UITestControl[]>(new UITestControl[] { statusText, errorDialog }, IsStatusDoneOrError);

    I am not a developer, maybe you can try to write your code like below to compare the text value of the wpf control through WpfText.DisplayText property with the expected text value:

    class ParameterisedIsStatusDone

    {

        public ParameterisedIsStatusDone(string t)

        {

            expectedtext = t;

        }

        private string expectedtext;

        public bool IsStatusDone(UITestControl control)

        {

            WpfText ControlTextVale = control as WpfText;

            return ControlTextVale.DisplayText == expectedtext;

        }

    ParameterisedIsStatusDone pisd = new ParameterisedIsStatusDone("Succeeded");

    yourControl.WaitForControlCondition(pisd.IsStatusDone);

    You also can reference Victor Zn's solution in that thread.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 14, 2015 7:11 AM

All replies

  • Hi RB_IA,

    Adrian and Victor Zn provided some code examples about the usage of UITestControl.WaitForControlCondition meythod in this thread: https://social.msdn.microsoft.com/Forums/vstudio/en-US/d57c92ea-ffc4-4643-87c5-14cab6ae19de/waitforcontrolcondition-with-variable-conditions?forum=vstest

    You can reference them to write your own code logic.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Amanda Zhu Monday, January 12, 2015 2:37 AM
    Tuesday, January 6, 2015 8:29 AM
  • Hi Amanda

    Thanks for the reply but I neglected to mention if it was vb.net example that would be helpful.  I had seen the example you had pointed out before and working with it but seeing in in vb.net would get me from A to B faster.

    Actually the example shows converting a UiTestControl to WinControls.WinText and vb.net is not allowing a CType conversion.

     public bool IsStatusDone(UITestControl control)
       
    {
           
    WinText statusText = control as WinText;

    RB_IA


    • Edited by RB_IA Tuesday, January 6, 2015 5:12 PM
    Tuesday, January 6, 2015 4:42 PM
  • Hi RB_IA,

    I consulted Visual Basic experts about the conversion and got the following result

    C# code:
           
    WinText statusText = control as WinText;

    Converted to VB code:

    Dim statusText As WinText = TryCast(control, WinText)  

     You can try this tool: http://converter.telerik.com/ to convert the C# code to VB format.

    If there are any issues about the conversion, we recommend you open a new thread about the code conversion to Visual Basic forum: https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vbgeneral

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Proposed as answer by Amanda Zhu Monday, January 12, 2015 2:37 AM
    • Marked as answer by RB_IA Tuesday, January 13, 2015 4:24 PM
    • Unmarked as answer by RB_IA Tuesday, January 13, 2015 4:26 PM
    Wednesday, January 7, 2015 6:45 AM
  • Thanks for the reply Amanda but a couple of issues came up trying to use the example as starting point. One is the IsStatusDone function  needs a parameter of a UITestControl type and none is sent along in the example.  And the returned type is Boolean but the WaitForControl function needs (Predicate of)UITestControl. 

    I notice in the notes it indicates the code was complied but not actually ran

    If there are any suggestions or questions please let me know.

    Tuesday, January 13, 2015 5:11 PM
  • Hi RB_IA,

    AdrianHHH’s idea for that code is right, he meant that he compiled the code but he did not execute it to verify whether the code can run fine. I think that code should run.

    For the code you pasted, yes, the UITestControl parameter is not sent to IsStatusDone method through  parameters within it directly, but the text is defined outside of IsStutusDone method and it is used in the IsStatusDone method.

    For your second doubt, Adrian used this API: WaitForControlCondition(Predicate<UITestControl>) which accepts a bool parameter as the specific condition instead of this API: WaitForCondition<T>(T, Predicate<T>).

    You can reference this code snippet which is used to wait till the status text of a control is “Succeeded” or “Failed”.in this blog:How To: Make playback wait for certain event?

    // Define the method to evaluate the condition

    private static bool IsStatusDoneOrError(UITestControl[] controls)

    {

        WinText statusText = controls[0] as WinText;

        WinWindow errorDialog = controls[1] as WinWindow;

        return statusText.DisplayText == "Succeeded" || errorDialog.Exists;

    }

    // In test method, wait till the method evaluates to true

    UITestControl.WaitForCondition<UITestControl[]>(new UITestControl[] { statusText, errorDialog }, IsStatusDoneOrError);

    I am not a developer, maybe you can try to write your code like below to compare the text value of the wpf control through WpfText.DisplayText property with the expected text value:

    class ParameterisedIsStatusDone

    {

        public ParameterisedIsStatusDone(string t)

        {

            expectedtext = t;

        }

        private string expectedtext;

        public bool IsStatusDone(UITestControl control)

        {

            WpfText ControlTextVale = control as WpfText;

            return ControlTextVale.DisplayText == expectedtext;

        }

    ParameterisedIsStatusDone pisd = new ParameterisedIsStatusDone("Succeeded");

    yourControl.WaitForControlCondition(pisd.IsStatusDone);

    You also can reference Victor Zn's solution in that thread.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, January 14, 2015 7:11 AM
  • Hi RB_IA,

    If you have any concern, please feel free to come back.

    Thanks,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, January 19, 2015 8:32 AM