Forum Xamarin Test Cloud (Read Only)

How to enter a backspace into an Entry field?

The Application Under Test uses behaviours to implement validation on Entry fields, performing the validation each time a character is typed. That includes when the user backspaces.

When using UITest, I started with ClearText to get to a known starting point on each Entry, then used EnterText to populate the Entry. However, there are times when I want to test what happens if the user backspaces until the Entry is empty. Unfortunately, ClearText doesn't seem to trigger the validation behaviour, so I seem to need to enter a string using EnterText and then backspace it out in order to trigger the validation when the Entry is empty. I tried "1\b", but this results in an error of "failed to locate key '\b'".

Can anybody tell me how to "populate" an Entry with an empty string, using UITest in such a way that a validation behaviour is fired in the AUT?

Many thanks,

John H.

Answers

  • JohnHardmanJohnHardman GBUniversity mod

    Many thanks to Rob Gibbens for this. The answer on iOS is as follows:

                    var uia = "uia.keyboard().elements().firstWithName('Delete').tap()";
                    ((iOSApp)TestSettings.App).InvokeUia(uia);
    

    Still investigating for the equivalent on Android.

  • i_NateCooki_NateCook USMember ✭✭

    It looks like InvokeUia no longer works:

    >>> app.InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Exception: System.Exception: InvokeUia is not supported when using DeviceAgent
    at Xamarin.UITest.iOS.iOSGestures.InvokeUia (System.String script) [0x0000b] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.iOS.iOSApp+<InvokeUia>c__AnonStorey27.<>m__0 () [0x00000] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1[TResult] func, System.Object[] args, System.String memberName) [0x00010] in <e747267e258a4a668973c7ca7e9014a8>:0
    Exception: Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()"
    
  • i_NateCooki_NateCook USMember ✭✭

    It looks like this no longer works for iOS

    >>> app.InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Exception: System.Exception: InvokeUia is not supported when using DeviceAgent
    at Xamarin.UITest.iOS.iOSGestures.InvokeUia (System.String script) [0x0000b] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.iOS.iOSApp+<InvokeUia>c__AnonStorey27.<>m__0 () [0x00000] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1[TResult] func, System.Object[] args, System.String memberName) [0x00010] in <e747267e258a4a668973c7ca7e9014a8>:0
    Exception: Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()"
    

    This does though:

    const char backspaceChar = '\u0008';
    app.EnterText(backspaceChar.ToString());
    
  • i_NateCooki_NateCook USMember ✭✭

    It looks like InvokeUia no longer works:

    >>> app.InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Exception: System.Exception: InvokeUia is not supported when using DeviceAgent
    at Xamarin.UITest.iOS.iOSGestures.InvokeUia (System.String script) [0x0000b] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.iOS.iOSApp+<InvokeUia>c__AnonStorey27.<>m__0 () [0x00000] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1[TResult] func, System.Object[] args, System.String memberName) [0x00010] in <e747267e258a4a668973c7ca7e9014a8>:0
    Exception: Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()"
    
  • i_NateCooki_NateCook USMember ✭✭

    It looks like this no longer works for iOS

    >>> app.InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()")
    Exception: System.Exception: InvokeUia is not supported when using DeviceAgent
    at Xamarin.UITest.iOS.iOSGestures.InvokeUia (System.String script) [0x0000b] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.iOS.iOSApp+<InvokeUia>c__AnonStorey27.<>m__0 () [0x00000] in <e747267e258a4a668973c7ca7e9014a8>:0
    at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1[TResult] func, System.Object[] args, System.String memberName) [0x00010] in <e747267e258a4a668973c7ca7e9014a8>:0
    Exception: Error while performing InvokeUia("uia.keyboard().elements().firstWithName('Delete').tap()"
    

    This does though:

    const char backspaceChar = '\u0008';
    app.EnterText(backspaceChar.ToString());
    
  • ros_vizros_viz Member ✭✭

    to delete all input in an input field?? in ios???

Sign In or Register to comment.