Hi guys, I am writing here the commands to use when you run cucumber on Automation. It is very usefully 🙂
Launching and Customizing launch
Calabash has two ways of launching apps: SimLauncher and Apple’s instruments tool. Each has its own advantages and problems (see below).
For iOS7+ only the instruments launch method is supported. If instruments is not used to automatically launch the app touch events wont work.
Since version 0.9.154, Calabash is using instruments and UIAutomation to launch apps by default. The primary reason for this is two-fold: (a) in iOS7, Apple removed access to APIs previously used to synthesize touch events and we needed a different approach, (b) there are things possible with UIA that are not possible from “inside the app”, i.e., in the Calabash server (like accepting the Access to current location dialog or sending the app to the background).
The launch method can be controlled using environment variables. With Calabash 0.9.157+, the use of environment variables was greatly simplified. If you’re updating from a previous version, it is recommended to try removing all the environment variables, and then adding only the ones you’re sure you need.
- DEVICE_TARGET controls which device to launch on. When set Calabash uses instruments to launch. The default is ‘simulator’ (see also Testing on Physical iDevices). You can also set
DEVICE_TARGET=device
or DEVICE_TARGET=UDID_OF_CONNECTED_DEVICE
to pick a specific connected device, or DEVICE_TARGET=simulator to force use of instruments and simulator. (You can see the UDID of your device in the Devices tab in Xcode’s Organizer window).
- SDK_VERSION is only used when running on the simulator. It controls which iOS version of the simulator is launched. Note, SDK_VERSION forces the launch method to be SimLauncher (not instruments). The reason for this is that the instruments tool does not support launching a simulator that is not the latest version.
- DEVICE=ipad if you want to ensure we launch the iPad simulator. Defaults to ‘iphone’.
- OS is deprecated and now automatically detected (it was previously used to decide which “recordings” to use for playback).
- NO_LAUNCH is not supported when running with instruments. It tells Calabash to not automatically launch the app (it is mostly used when you want to start the app yourself – should rarely be used).
- NO_STOP means don’t stop the app after the test completes. (It is mostly used to leave the app open in case of a test failure and should be used for debugging purposes only).
- RESET_BETWEEN_SCENARIOS (example: RESET_BETWEEN_SCENARIOS=1) – Reset iOS Simulator between each scenario.
EG.
$ SDK_VERSION=6.1 DEVICE=ipad cucumber
Explore interactively!
To start-up a console, you can run the command: calabash-ios console
and then start a simulator withstart_test_server_in_background
for iOS7 to get touch events to work.
Try starting your app using the -cal scheme from Xcode and then run calabash-ios console
. This will give you a Calabash console (it is just a Ruby irb with calabash loaded).
From this console you can explore your application interactively.
You can query, touch, scroll, etc from the irb session. This information below also serves as an introduction for the APIs that are available in other place.
Query
If your app have two buttons. Try this from the console:
irb > query("button")
You should see something like this:
=> [{"class"=>"UIRoundedRectButton", frame"=>
{"y"=>287, "width"=>72, "x"=>100,
"height"=>37}, "UIType"=>"UIControl",
"description"=>"<UIRoundedRectButton: 0x7d463d0;
frame = (100 287; 72 37); opaque = NO; autoresize = RM+BM;
layer = <CALayer: 0x7d46ae0>>"},
{"class"=>"UIRoundedRectButton", "frame"=>
{"y"=>215, "width"=>73, "x"=>109,
"height"=>37}, "UIType"=>"UIControl",
"description"=>"<UIRoundedRectButton: 0x7d3a760;
frame = (109 215; 73 37); opaque = NO; autoresize = RM+BM;
layer = <CALayer: 0x7d3a8a0>>"}]
This is actually an array with two objects that are descriptions of the two buttons. For example, the class of the first button is “UIRoundedRectButton”. We can dive into this information using Ruby programming:
irb > result = query("button") ... irb > btn1 =
result[0] ... irb > class1 = btn1["class"] =>
"UIRoundedRectButton"
The query
function takes a string query as an argument. The query argument is similar to a css selector, for example we can do:
irb > query("button index:0 label") =>
[{"class"=>"UIButtonLabel", "frame"=>{"y"=>9,
"width"=>38, "x"=>17, "height"=>19}, "UIType"=>"UIView",
"description"=>"<UIButtonLabel: 0x7d41120; frame =
(17 9; 38 19); text = 'other'; clipsToBounds = YES; opaque
= NO; userInteractionEnabled = NO; layer = <CALayer:
0x7d40510>>"}]
This means “find the first button, and then inside of that find all labels”.
Query may also take parameters that are mapped to Objective-C selectors on the found object.
irb > query("button index:0 label", :text) =>
["other"]
Query is very powerful, but the full syntax and power of query is beyond the scope of the Getting started guide on GitHub.
Touch
Anything that can be found using query can also be touched. Try this while you watch the iOS Simulator:
irb > touch("button index:0")
Notice that the button is touched (turns blue), although this button doesn’t do anything.
You can also touch the tab bars:
irb > touch("tabBarButton index:1")
The filter: index:1
means that it is the second tab-bar button that should be touched.
Setting accessibility
Identifiers and accessibility
Labels
In general UI views are found using accessibility ids or labels. Go to the “First” tab in simulator, and then in your console session try this:
# query for the switch on the "First" tab irb >
query("view marked:'switch'") [ [0] { "class" =>
"UISwitch", "frame" => { "y" => 148, "width" =>
79, "x" => 106, "height" => 27 }, "UIType" =>
"UIControl", "description" => "<UISwitch: 0x7d3ffb0;
frame = (106 148; 79 27); <snip> >>" } ]
You can set the accessibility attributes of UIView from the Interface Builder or programmatically.
In some cases the UIKit framework will set the accessibilityLabel for you if you don’t explicitly set the value.
For example, UITabBarButton will have an accessibility label that is the same as title of the tab bar button.
irb > query("tabBarButton marked:'Second'") [ [0] {
"class" => "UITabBarButton", "id" => nil, "rect"
=> { "center_x" => 120, "y" => 520, "width" =>
76, "x" => 82, "center_y" => 544, "height" => 48
}, "frame" => { "y" => 1, "width" => 76, "x" =>
82, "height" => 48 }, "label" => "Second",
"description" => "<UITabBarButton: 0x857e010; frame =
(82 1; 76 48); <snip> >" } ]
Whenever possible, you should use the accessibilityIdentifier of UIView and reserve the accessibilityLabel for providing localized Accessibility traits.
- (void) viewDidLoad { [super viewDidLoad]; UISwitch
*switch = self.wantsCoffeeSwitch; # ex. queries # query
"view marked:'wants coffee'" # query "switch
{accessibilityIdentifier LIKE 'wants coffee'}" # query
"switch marked:'wants coffee'"
switch.accessibilityIdentifier = @"wants coffee"; #
accessibilityLabels should be localized and follow the
conventions # described by Apple's Accessibility
documentation if (switch.isOn == YES) {
switch.accessibilityLabel = NSLocalizedString(@"Wants
coffee"); } else { switch.accessibilityLabel =
NSLocalizedString(@"Does not want coffee"); } }
Thank you guys ! If you have any question, just write below. Bye !!
Fonts: https://github.com/calabash/calabash-ios/wiki/01-Getting-started-guide
Like this:
Like Loading...