I'm looking to assert that I am on a particular screen during my tests, and if I'm not, then I should fail. What is the recommended way of doing this? For example, if I have a test like this:
Given that I am on the Login screen
When I press "Sign Up"
Then I should be on the Sign up screen
I've written Page Object Models for both screens involved, and they each have a trait method defined.
I've looked, and there is the TaskyPro sample (https://github.com/xamarin/mobile-samples/tree/master/TaskyPro-Calabash/features/step_definitions), which defines an "assert_screen" method. I've tried putting it into my project, but it doesn't work, as @screen is always nil. I don't have Xamarin, so I can't build their project and test it out.
You need to assign @screen
first.
If your screen objects inherent from Calabash::IBase
(iOS) or Calabash::ABase
(Android), you could use the built in await
method. You just have to set a trait
or title
for the screen.
A good example is the "Calabash Cross Platform Example": https://github.com/calabash/x-platform-example In there you can see examples of how to assign screen/page objects, how to make screen/page objects and how to check if a screen is visible.
We use screen objects all over our tests, and they help a lot when you need to use the same tests on multiple platforms.
I would recommend that you also use the transition
method on the screen/page objects to navigate between screens.