UITest how to switch ContentPage?

Hi,

I'm trying to write more UITests for our application but I'm wondering how I can navigate or start a different ContenPage to test?
The flow of the app doesn't allow to navigate to another ContentPage with the normal UI, because it needs a valid Login and a login is only valid for one single login. After that a different login has to be used.

So how can I test a different ContentPage than the start page?

Best regards

Best Answers

Answers

  • Glenn.WilsonGlenn.Wilson USXamarin Team Xamurai

    @DirkDenzer I'm not sure I fully understand your workflow but I think backdoors may be what you need to login multiple times or to navigate to different pages within one login if the app does not normally allow that.

    Backdoors.

  • DirkDenzerDirkDenzer USMember ✭✭

    Yes I also thought Backdoors would be helpful but it seems it's only working with Android and iOS?
    But I'm having a Forms project.

    I thought I could call the method that checks the Login validation and pass some valid mock data to it but can't find anything how to do that for methods declared in a Forms project. How can I invoke Forms methods?

    Sincerely

  • Glenn.WilsonGlenn.Wilson USXamarin Team Xamurai

    @DirkDenzer The UITest Invoke method is executed at the native iOS or Android level so you can use invoke to call native methods.

    But Backdoors can be called in Forms projects. You can, for example, add backdoor methods to the AppDelegate.cs (iOS) and MainActivity.cs (Android) in your Forms projects.

  • DirkDenzerDirkDenzer USMember ✭✭

    Sure. Ok, maybe it was a bit unclear, if I say Forms Project I mean the platform independent part of the solution.
    So in my ContentPage that is working on both Systems, Android and iOS, I have a method handleResponse(Response response object) that handles the response of the request to the server.
    Now if I want a backdoor for that method how can I achieve that?

    The method is declared in the ContentPage not in the MainActivity or AppDelegate.

    Best regards

  • vizalvizal USMember
    edited December 2016

    Hi @DirkDenzer Can you please share how to achieve this if you have got the solution.

    Best Regards

  • DirkDenzerDirkDenzer USMember ✭✭

    Hi @vizal

    as said I ended up implementing a fake server which always returns ok to my app. That solution was needed in my case because the backend only accepted a login once. And after that it was invalid.
    So I wrote a really small Java backend which just returns an ok response to my app no matter what and then I changed the configuration for my UITests so it targets the fake backend instead of the real one.

    If you are interested in Backdoors, what Glenn suggested, you have to place a function in AppDelegate and MainActivity like this:
    AppDelegate
    [Export ("simpleTest")] public void simpleTest () { }
    MainActivity
    [Java.Interop.Export("simpleTest")] public void simpleTest() { }

    and then in your UITest, you can call like
    if (platform == Platform.iOS) app.Invoke ("simpleTest:"); else app.Invoke ("simpleTest");

    I hope it helps.

    Greetings

Sign In or Register to comment.