Question

I think I'm a bit mixed up about the real purpose of Calabash.

I've found some demo script where I read:

Then I see "Sign In"
Then I wait to see if I am on a good screen
Then I enter "my_username" into text field number 1
Then I touch list item number 2

But how do I use operators? In my application, the user often lands on the login page, but can land on the home page if he's really logged. Or on the tutorial if he runs for the first time. On terms and conditions if he never confirmed new terms and condition, or on another screen if some actions are in cache. So it needs a ton of verification.

But all I found were scripts with then, then, that breaks if it doesn't find the specified item.

I'm trying to build a step that would do as follow:

If I am on terms and conditions, click Accept
If I am on login, click Sign In
If I am on tutorial, click Close

And there is no specific order. I found a lot of tutorials on the web, but there is nothing that applies to a normal navigation through an application that can have multiple scenarios. What I understand is that once a test doesn't pass, it stops. Often with a runtime error like "there is no button named -x- so I'll crash"

In a more general way, I want to do stuff like:

Ok, check where I am, and according to where I am in the app, reacts the good way.

Is there something (things) I don't understand about the goal of Calabash. And can I achieve this kind of test with Calabash?

How to cancel certain tests if they are not valid anymore because of the result of one test?

Was it helpful?

Solution

The solution is to develop steps that will perform some pre-condition job.

So your tests will look like:

Given I am on Sign In screen
Then ...

And Given I am on Sign In screen is something like

start_test_server_in_background
# additionally you may need some wait_for this line
touch 'accept_btn_locator' unless query('accept_btn_locator').empty?
touch 'sign_in_btn_locator' unless query('sign_in_btn_locator').empty?
touch 'close_btn_locator' unless query('close_btn_locator').empty?

It just for example. Usually an implementation is more complex.

OTHER TIPS

You can create your own steps to help with this, but Calabash does not have an "If I am on X page" function. The Ruby API has a ton of very helpful functions to allow you to create very effective tests. The documentation for the Ruby API is located here and I would highly recommend checking that out. If you want to be sure your tests are always running the same way, create a different 'Feature' for every main feature you want to test. When Calabash runs, it re-installs the apps before every Feature, so you can be sure that you won't still be logged in/on any page. You could start by writing a simple login/logout feature, then on your next feature, use the same steps to log in and then navigate to different features. To get really comfortable with Calabash, I recommend using the calabash console. That allows you to control the app via command line and is very helpful in learning how all of the different commands work. Hope this helps a little bit, feel free to tag me in a comment if you've got any questions, I use Calabash every day.

I would look at the calabash-x-platform example at https://github.com/calabash/x-platform-example. It goes through using a 'page-object' style framework for doing exactly what you're describing. It's made for using multiple frameworks but I don't see why you couldn't use it for a single one. I'd write more but it would just be copying what they have there.

Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top