Skip to content

Tips and Tricks

Joshua Moody edited this page Jun 17, 2015 · 1 revision

This page contains different tips and info that may be relevant to building better tests with Calabash iOS.

Resetting app data between scenarios

Often you'd want to reset app data between scenarios. This is a new feature from version 0.9.48. To be backwards compatible, however, it is not enabled by default, and is opt in. To enable use environment variable RESET_BETWEEN_SCENARIOS=1

 $ RESET_BETWEEN_SCENARIOS=1 OS=ios5 cucumber

Send screenshots to a specific directory

If you want to send your screenshots to a specific directory, use SCREENSHOT_PATH

$ SCREENSHOT_PATH=./screenshots/ cucumber

Specify a custom .irbrc

By default the calabash-ios console command will read the .irbrc in the current directory. To override this behavior use the CALABASH_IRBRC variable.

$ CALABASH_IRBRC=~/.irbrc calabash-ios console

Handling quotes

The query language that Calabash uses single quotes ' to delimit strings. This has an unfortunate interaction with the Ruby API.

What this means is that strings that contain single quotes must be escaped in a special way. With Calabash-iOS 0.9.53 this is partially remedied.

  1. A new function escape_quotes is introduced in operations.rb. To use, call escape_quotes on a string containing quotes like "Karl's". This gives a new string that you can pass to query and the other operations.

  2. The previous difference between touch and query in handling of quotes should disappear.

Example:

irb(main):001:0> txt = "karl's"
=> "karl's"

irb(main):002:0> txt = escape_quotes("karl's")
=> "karl\\'s"

irb(main):003:0> query("view marked:'#{txt}'")
=> ["<UIRoundedRectButton: 0x7e95840; frame = (100 287; 72 37); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x7e95700>>"]

irb(main):004:0> touch("view marked:'#{txt}'")
=> ["<UIRoundedRectButton: 0x7e95840; frame = (100 287; 72 37); opaque = NO; autoresize = RM+BM; layer <CALayer: 0x7e95700>>"]
Clone this wiki locally