2

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.

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
s73v3r
  • 1,751
  • 2
  • 22
  • 48
  • Could you paste some of the page model here, especially the part about how you set the @screen value. – Lasse Oct 07 '14 at 05:02

1 Answers1

2

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.

Carl Manaster
  • 39,912
  • 17
  • 102
  • 155
  • Before this post, I had never heard of the transition method before. I did a quick Google search, and the only thing I've found on it was the source listing. Nothing in any of their docs. Are there many more methods like this, that I should be aware of? – s73v3r Oct 07 '14 at 18:45
  • Since I answered this question, we've changed the way we use screens/pages. We have some steps that is used from multiple places so we can't assume that @screen is always the right screen at the start of a step. We therefore at the start of the step assign a local variable with the newly instantiated screen object. – Morten Bjerg Gregersen Sep 07 '16 at 06:41