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
@ DirkDenzer I'm not sure what is the best way but I would consider adding the backdoor methods to the AppDelegate.cs
(iOS) and MainActivity.cs
(Android) in your Forms projects.
And then, use some messaging system to forward the message to where it is needed in the app and call the method there.
See: Publish and Subscribe with MessagingCenter
Yes! I guess that would be a possible solution!
But I ended up implementing a mock server to run the tests again.
Thanks a lot I'm pretty sure that will help others and for other situations.
Best regards
Answers
@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.
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
@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) andMainActivity.cs
(Android) in your Forms projects.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
@ DirkDenzer I'm not sure what is the best way but I would consider adding the backdoor methods to the
AppDelegate.cs
(iOS) andMainActivity.cs
(Android) in your Forms projects.And then, use some messaging system to forward the message to where it is needed in the app and call the method there.
See: Publish and Subscribe with MessagingCenter
Yes! I guess that would be a possible solution!
But I ended up implementing a mock server to run the tests again.
Thanks a lot I'm pretty sure that will help others and for other situations.
Best regards
Hi @DirkDenzer Can you please share how to achieve this if you have got the solution.
Best Regards
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