locked
How to press the up button on the navbar rather than the back button? RRS feed

  • Question

  • User89714 posted

    When running tests, I need to differentiate between the back button and the nav bar's up button (the left chevron or left arrow).

    How can I explicitly press the up button from a UITest? Is adding a backdoor in the app and invoking that the only way?

    Many thanks,

    John H.

    Saturday, August 8, 2015 5:22 PM

Answers

  • User142867 posted

    If i understand your question correctly you are trying to differentiate between the default Android 'physical' back button and an up 'software' button within an app. In order to select the up button you need only apply a unique ID to it and then use the standard .Tap() method:

    app.Tap(e => e.Id("upbutton"));

    You can select the physical back button by using the .Back() method:

    app.Back();

    From what i can see there is no need to use a backdoor in this use case.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 10, 2015 8:11 AM

All replies

  • User142867 posted

    If i understand your question correctly you are trying to differentiate between the default Android 'physical' back button and an up 'software' button within an app. In order to select the up button you need only apply a unique ID to it and then use the standard .Tap() method:

    app.Tap(e => e.Id("upbutton"));

    You can select the physical back button by using the .Back() method:

    app.Back();

    From what i can see there is no need to use a backdoor in this use case.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Monday, August 10, 2015 8:11 AM
  • User89714 posted

    @DavidLavender - Many thanks. Sorry, I should have spotted that - my brain was working on the assumption that as there was a Back() method, there might be an Up() method.

    I did have to make one slight tweak - in the Xamarin.Forms app that I am working on, the up button shows up as "up" rather than "upbutton" on Android.

    Monday, August 10, 2015 9:05 AM
  • User108112 posted

    From the 'Share with' overlay screen, I'm trying to press the back button i,e. app.Back() but it fails. Here's the screenshot http://prntscr.com/cjxc48 Any suggestions?

    Error while performing Back()
    Exception: System.Exception: PressKey for keycode:'KEYCODE_BACK' was unsucessful: java.lang.SecurityException: Injecting to another application requires INJECT_EVENTS permission
       at Xamarin.UITest.Android.AndroidGestures.PressKey(String keycode)
       at Xamarin.UITest.Utils.ErrorReporting.With(Action func, Object[] args, String memberName)
    
    Monday, September 19, 2016 6:42 PM
  • User245711 posted

    Having the same issue. Several tests open an external application, and I'm unable to get back to our application again. Is there any API available to go back to our own application ?

    Thursday, April 20, 2017 8:32 AM
  • User89714 posted

    @Bartdk- - To get back to your app from an external app, just use StartApp again. If your app isn't running it will be re-started, if it is running it will be brought to the foreground.

    Friday, April 21, 2017 12:22 AM
  • User245711 posted

    @JohnHardman : Thanks for the tip. It seems like the app will not be brought to the foreground, nor will it be re-started. During my test, the application did an entire re-install ? Is there any other call for StartApp that I'm missing ? (now calling : AppInitializer.StartApp(_platform))

    Would be very nice if we could trigger an App.Device.Back instead

    Friday, April 21, 2017 7:39 AM
  • User89714 posted

    @Bartdk- - I haven't looked at that bit of my code for a while, but when I was using Xamarin.UITest (I'm not any more, until it supports Windows platforms as well) I used StartApp to re-start the app or to re-foreground it. It definitely didn't do a re-install. All of my testing was done using physical devices though - I don't know if StartApp behaves differently in TestCloud.

    Friday, April 21, 2017 10:01 AM
  • User291964 posted

    On launch, app opens a browser. (a defect at the moment which will be addressed)

    When I do an app.back(), it doesnt seem to do anything. If I do StartApp(), it seems to relaunch the app - leading to the same outcome.

    Any thoughts?

    Friday, June 2, 2017 3:18 AM
  • User286351 posted

    app.Back() also doesn't work for me in test cloud. Any ideas?

    Wednesday, September 27, 2017 11:36 AM
  • User185434 posted

    Hi @AleksandrSmyk ,

    What is your Xamarin.UITest Version ? (https://www.nuget.org/packages/Xamarin.UITest/).

    app.Back() works only for Android.

    Anthony

    Wednesday, September 27, 2017 11:54 AM
  • User286351 posted

    @AnthonyMehallel I found a decision using tapCoordinates.

    Thursday, September 28, 2017 9:06 AM
  • User365517 posted

    I have a similar issue: I'm creating the test for my app. During the test a go to gallery and then go back to app, but app.Back() doesn't work. Help please!

    Friday, February 23, 2018 11:06 AM