testautoi 0.9.127

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/.gitignore +4 -0
  2. data/CHANGES.txt +1 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +8 -0
  5. data/Rakefile +2 -0
  6. data/bin/CalabashSetup +0 -0
  7. data/bin/cal.xcconfig +3 -0
  8. data/bin/calabash-ios +79 -0
  9. data/bin/calabash-ios-build.rb +110 -0
  10. data/bin/calabash-ios-generate.rb +26 -0
  11. data/bin/calabash-ios-helpers.rb +130 -0
  12. data/bin/calabash-ios-setup.rb +334 -0
  13. data/bin/calabash-ios-sim.rb +149 -0
  14. data/calabash-cucumber.gemspec +29 -0
  15. data/doc/calabash-ios-help.txt +73 -0
  16. data/epl-v10.html +261 -0
  17. data/features-skeleton/.irbrc +23 -0
  18. data/features-skeleton/irb_ios4.sh +2 -0
  19. data/features-skeleton/irb_ios5.sh +2 -0
  20. data/features-skeleton/my_first.feature +12 -0
  21. data/features-skeleton/step_definitions/calabash_steps.rb +1 -0
  22. data/features-skeleton/step_definitions/my_first_steps.rb +4 -0
  23. data/features-skeleton/support/env.rb +1 -0
  24. data/features-skeleton/support/hooks.rb +0 -0
  25. data/features-skeleton/support/launch.rb +77 -0
  26. data/features/step_definitions/calabash_steps.rb +439 -0
  27. data/lib/calabash-cucumber.rb +7 -0
  28. data/lib/calabash-cucumber/calabash_steps.rb +1 -0
  29. data/lib/calabash-cucumber/core.rb +553 -0
  30. data/lib/calabash-cucumber/cucumber.rb +8 -0
  31. data/lib/calabash-cucumber/ibase.rb +45 -0
  32. data/lib/calabash-cucumber/keyboard_helpers.rb +124 -0
  33. data/lib/calabash-cucumber/launch/simulator_helper.rb +297 -0
  34. data/lib/calabash-cucumber/location.rb +26 -0
  35. data/lib/calabash-cucumber/operations.rb +162 -0
  36. data/lib/calabash-cucumber/resources/cell_swipe_ios4_ipad.base64 +51 -0
  37. data/lib/calabash-cucumber/resources/cell_swipe_ios4_iphone.base64 +51 -0
  38. data/lib/calabash-cucumber/resources/cell_swipe_ios5_ipad.base64 +74 -0
  39. data/lib/calabash-cucumber/resources/cell_swipe_ios5_iphone.base64 +74 -0
  40. data/lib/calabash-cucumber/resources/pinch_in_ios4_ipad.base64 +104 -0
  41. data/lib/calabash-cucumber/resources/pinch_in_ios4_iphone.base64 +104 -0
  42. data/lib/calabash-cucumber/resources/pinch_in_ios5_ipad.base64 +144 -0
  43. data/lib/calabash-cucumber/resources/pinch_in_ios5_iphone.base64 +144 -0
  44. data/lib/calabash-cucumber/resources/pinch_in_ios6_ipad.base64 +70 -0
  45. data/lib/calabash-cucumber/resources/pinch_in_ios6_iphone.base64 +70 -0
  46. data/lib/calabash-cucumber/resources/pinch_out_ios5_ipad.base64 +207 -0
  47. data/lib/calabash-cucumber/resources/pinch_out_ios5_iphone.base64 +207 -0
  48. data/lib/calabash-cucumber/resources/pinch_out_ios6_ipad.base64 +96 -0
  49. data/lib/calabash-cucumber/resources/pinch_out_ios6_iphone.base64 +96 -0
  50. data/lib/calabash-cucumber/resources/rotate_left_home_down_ios4_ipad.base64 +2 -0
  51. data/lib/calabash-cucumber/resources/rotate_left_home_down_ios4_iphone.base64 +2 -0
  52. data/lib/calabash-cucumber/resources/rotate_left_home_down_ios5_ipad.base64 +2 -0
  53. data/lib/calabash-cucumber/resources/rotate_left_home_down_ios5_iphone.base64 +2 -0
  54. data/lib/calabash-cucumber/resources/rotate_left_home_left_ios4_ipad.base64 +2 -0
  55. data/lib/calabash-cucumber/resources/rotate_left_home_left_ios4_iphone.base64 +2 -0
  56. data/lib/calabash-cucumber/resources/rotate_left_home_left_ios5_ipad.base64 +2 -0
  57. data/lib/calabash-cucumber/resources/rotate_left_home_left_ios5_iphone.base64 +2 -0
  58. data/lib/calabash-cucumber/resources/rotate_left_home_right_ios4_ipad.base64 +2 -0
  59. data/lib/calabash-cucumber/resources/rotate_left_home_right_ios4_iphone.base64 +2 -0
  60. data/lib/calabash-cucumber/resources/rotate_left_home_right_ios5_ipad.base64 +2 -0
  61. data/lib/calabash-cucumber/resources/rotate_left_home_right_ios5_iphone.base64 +2 -0
  62. data/lib/calabash-cucumber/resources/rotate_left_home_up_ios4_ipad.base64 +2 -0
  63. data/lib/calabash-cucumber/resources/rotate_left_home_up_ios4_iphone.base64 +2 -0
  64. data/lib/calabash-cucumber/resources/rotate_left_home_up_ios5_ipad.base64 +2 -0
  65. data/lib/calabash-cucumber/resources/rotate_left_home_up_ios5_iphone.base64 +2 -0
  66. data/lib/calabash-cucumber/resources/rotate_right_home_down_ios4_ipad.base64 +2 -0
  67. data/lib/calabash-cucumber/resources/rotate_right_home_down_ios4_iphone.base64 +2 -0
  68. data/lib/calabash-cucumber/resources/rotate_right_home_down_ios5_ipad.base64 +2 -0
  69. data/lib/calabash-cucumber/resources/rotate_right_home_down_ios5_iphone.base64 +2 -0
  70. data/lib/calabash-cucumber/resources/rotate_right_home_left_ios4_ipad.base64 +2 -0
  71. data/lib/calabash-cucumber/resources/rotate_right_home_left_ios4_iphone.base64 +2 -0
  72. data/lib/calabash-cucumber/resources/rotate_right_home_left_ios5_ipad.base64 +2 -0
  73. data/lib/calabash-cucumber/resources/rotate_right_home_left_ios5_iphone.base64 +2 -0
  74. data/lib/calabash-cucumber/resources/rotate_right_home_right_ios4_ipad.base64 +2 -0
  75. data/lib/calabash-cucumber/resources/rotate_right_home_right_ios4_iphone.base64 +2 -0
  76. data/lib/calabash-cucumber/resources/rotate_right_home_right_ios5_ipad.base64 +2 -0
  77. data/lib/calabash-cucumber/resources/rotate_right_home_right_ios5_iphone.base64 +2 -0
  78. data/lib/calabash-cucumber/resources/rotate_right_home_up_ios4_ipad.base64 +2 -0
  79. data/lib/calabash-cucumber/resources/rotate_right_home_up_ios4_iphone.base64 +2 -0
  80. data/lib/calabash-cucumber/resources/rotate_right_home_up_ios5_ipad.base64 +2 -0
  81. data/lib/calabash-cucumber/resources/rotate_right_home_up_ios5_iphone.base64 +2 -0
  82. data/lib/calabash-cucumber/resources/swipe_down_ios5_ipad.base64 +18 -0
  83. data/lib/calabash-cucumber/resources/swipe_down_ios5_iphone.base64 +18 -0
  84. data/lib/calabash-cucumber/resources/swipe_left_hard_ios4_ipad.base64 +15 -0
  85. data/lib/calabash-cucumber/resources/swipe_left_hard_ios4_iphone.base64 +15 -0
  86. data/lib/calabash-cucumber/resources/swipe_left_ios4_ipad.base64 +18 -0
  87. data/lib/calabash-cucumber/resources/swipe_left_ios4_iphone.base64 +18 -0
  88. data/lib/calabash-cucumber/resources/swipe_left_ios5_ipad.base64 +17 -0
  89. data/lib/calabash-cucumber/resources/swipe_left_ios5_iphone.base64 +17 -0
  90. data/lib/calabash-cucumber/resources/swipe_right_hard_ios4_ipad.base64 +17 -0
  91. data/lib/calabash-cucumber/resources/swipe_right_hard_ios4_iphone.base64 +17 -0
  92. data/lib/calabash-cucumber/resources/swipe_right_ios4_ipad.base64 +13 -0
  93. data/lib/calabash-cucumber/resources/swipe_right_ios4_iphone.base64 +13 -0
  94. data/lib/calabash-cucumber/resources/swipe_right_ios5_ipad.base64 +17 -0
  95. data/lib/calabash-cucumber/resources/swipe_right_ios5_iphone.base64 +17 -0
  96. data/lib/calabash-cucumber/resources/swipe_up_ios5_ipad.base64 +34 -0
  97. data/lib/calabash-cucumber/resources/swipe_up_ios5_iphone.base64 +34 -0
  98. data/lib/calabash-cucumber/resources/touch_done_ios4_ipad.base64 +7 -0
  99. data/lib/calabash-cucumber/resources/touch_done_ios4_iphone.base64 +9 -0
  100. data/lib/calabash-cucumber/resources/touch_done_ios5_ipad.base64 +7 -0
  101. data/lib/calabash-cucumber/resources/touch_done_ios5_iphone.base64 +9 -0
  102. data/lib/calabash-cucumber/resources/touch_ios4_ipad.base64 +9 -0
  103. data/lib/calabash-cucumber/resources/touch_ios4_iphone.base64 +9 -0
  104. data/lib/calabash-cucumber/resources/touch_ios5_ipad.base64 +9 -0
  105. data/lib/calabash-cucumber/resources/touch_ios5_iphone.base64 +9 -0
  106. data/lib/calabash-cucumber/resources/wheel_down_ios4_ipad.base64 +159 -0
  107. data/lib/calabash-cucumber/resources/wheel_down_ios4_iphone.base64 +159 -0
  108. data/lib/calabash-cucumber/resources/wheel_down_ios5_ipad.base64 +156 -0
  109. data/lib/calabash-cucumber/resources/wheel_down_ios5_iphone.base64 +156 -0
  110. data/lib/calabash-cucumber/resources/wheel_up_ios4_ipad.base64 +166 -0
  111. data/lib/calabash-cucumber/resources/wheel_up_ios4_iphone.base64 +166 -0
  112. data/lib/calabash-cucumber/resources/wheel_up_ios5_ipad.base64 +156 -0
  113. data/lib/calabash-cucumber/resources/wheel_up_ios5_iphone.base64 +156 -0
  114. data/lib/calabash-cucumber/tests_helpers.rb +136 -0
  115. data/lib/calabash-cucumber/version.rb +6 -0
  116. data/lib/calabash-cucumber/wait_helpers.rb +149 -0
  117. data/scripts/data/.GlobalPreferences.plist +0 -0
  118. data/scripts/data/clients.plist +0 -0
  119. data/scripts/data/com.apple.Accessibility.plist +0 -0
  120. data/scripts/reset_simulator.scpt +0 -0
  121. metadata +319 -0
@@ -0,0 +1,23 @@
1
+ require 'rubygems'
2
+ require 'irb/completion'
3
+ require 'irb/ext/save-history'
4
+
5
+ ARGV.concat [ "--readline",
6
+ "--prompt-mode",
7
+ "simple" ]
8
+
9
+ # 25 entries in the list
10
+ IRB.conf[:SAVE_HISTORY] = 50
11
+
12
+ # Store results in home directory with specified file name
13
+ IRB.conf[:HISTORY_FILE] = ".irb-history"
14
+
15
+ require 'calabash-cucumber/operations'
16
+ require 'calabash-cucumber/launch/simulator_helper'
17
+ SIM=Calabash::Cucumber::SimulatorHelper
18
+
19
+ include Calabash::Cucumber::Operations
20
+
21
+ def embed(x,y=nil,z=nil)
22
+ puts "Screenshot at #{x}"
23
+ end
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ IRBRC=.irbrc OS=ios4 irb
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ IRBRC=.irbrc irb
@@ -0,0 +1,12 @@
1
+ Feature: Running a test
2
+ As an iOS developer
3
+ I want to have a sample feature file
4
+ So I can begin testing quickly
5
+
6
+ Scenario: Example steps
7
+ Given I am on the Welcome Screen
8
+ Then I swipe left
9
+ And I wait until I don't see "Please swipe left"
10
+ And take picture
11
+
12
+
@@ -0,0 +1 @@
1
+ require 'calabash-cucumber/calabash_steps'
@@ -0,0 +1,4 @@
1
+ Given /^I am on the Welcome Screen$/ do
2
+ element_exists("view")
3
+ sleep(STEP_PAUSE)
4
+ end
@@ -0,0 +1 @@
1
+ require 'calabash-cucumber/cucumber'
File without changes
@@ -0,0 +1,77 @@
1
+ ########################################
2
+ # #
3
+ # Important Note #
4
+ # #
5
+ # When running calabash-ios tests at #
6
+ # www.lesspainful.com #
7
+ # this file will be overwritten by #
8
+ # a file which automates #
9
+ # app launch on devices. #
10
+ # #
11
+ # Don't rely on this file being #
12
+ # present when running at #
13
+ # www.lesspainful.com. #
14
+ # #
15
+ # Only put stuff here to automate #
16
+ # iOS Simulator. #
17
+ # #
18
+ # You can put your app bundle path #
19
+ # for automating simulator app start: #
20
+ # Uncomment APP_BUNDLE_PATH =.. #
21
+ # #
22
+ ########################################
23
+
24
+ require 'calabash-cucumber/launch/simulator_helper'
25
+ require 'sim_launcher'
26
+
27
+ # Uncomment and replace ?? appropriately
28
+ # This should point to your Simulator build
29
+ # which includes calabash framework
30
+ # this is usually the Calabash build configuration
31
+ # of your production target.
32
+ #APP_BUNDLE_PATH = "~/Library/Developer/Xcode/DerivedData/??/Build/Products/Calabash-iphonesimulator/??.app"
33
+ #
34
+
35
+ def reset_app_jail(sdk, app_path)
36
+ app = File.basename(app_path)
37
+ bundle = `find "#{ENV['HOME']}/Library/Application Support/iPhone Simulator/#{sdk}/Applications/" -type d -depth 2 -name "#{app}" | head -n 1`
38
+ return if bundle.empty? # Assuming we're already clean
39
+
40
+ sandbox = File.dirname(bundle)
41
+ ['Library', 'Documents', 'tmp'].each do |dir|
42
+ FileUtils.rm_rf(File.join(sandbox, dir))
43
+ end
44
+ end
45
+
46
+ def relaunch(args=nil)
47
+ if ENV['NO_LAUNCH']!="1"
48
+ sdk = ENV['SDK_VERSION'] || SimLauncher::SdkDetector.new().latest_sdk_version
49
+ path = Calabash::Cucumber::SimulatorHelper.app_bundle_or_raise(app_path)
50
+ if ENV['RESET_BETWEEN_SCENARIOS']=="1"
51
+ reset_app_jail(sdk, path)
52
+ end
53
+
54
+ Calabash::Cucumber::SimulatorHelper.relaunch(path,sdk,ENV['DEVICE'] || 'iphone', args)
55
+ end
56
+ end
57
+
58
+ def app_path
59
+ ENV['APP_BUNDLE_PATH'] || (defined?(APP_BUNDLE_PATH) && APP_BUNDLE_PATH)
60
+ end
61
+
62
+ def calabash_notify
63
+ if self.respond_to?(:on_launch)
64
+ self.on_launch
65
+ end
66
+ end
67
+
68
+ Before do |scenario|
69
+ relaunch
70
+ calabash_notify
71
+ end
72
+
73
+ at_exit do
74
+ if ENV['NO_LAUNCH']!="1" and ENV['NO_STOP']!="1"
75
+ Calabash::Cucumber::SimulatorHelper.stop
76
+ end
77
+ end
@@ -0,0 +1,439 @@
1
+ WAIT_TIMEOUT = (ENV['WAIT_TIMEOUT'] || 30).to_f
2
+ STEP_PAUSE = (ENV['STEP_PAUSE'] || 0.5).to_f
3
+
4
+ Given /^(my|the) app is running$/ do |_|
5
+ #no-op exists for backwards compatibility
6
+ end
7
+
8
+
9
+ # -- Touch --#
10
+ Then /^I (?:press|touch) on screen (\d+) from the left and (\d+) from the top$/ do |x, y|
11
+ touch(nil, {:offset => {:x => x.to_i, :y => y.to_i}})
12
+ sleep(STEP_PAUSE)
13
+ end
14
+
15
+ Then /^I (?:press|touch) "([^\"]*)"$/ do |name|
16
+ touch("view marked:'#{name}'")
17
+ sleep(STEP_PAUSE)
18
+ end
19
+
20
+ Then /^I (?:press|touch) "([^\"]*)" on number (\d+)$/ do |name, index|
21
+ index = index.to_i
22
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
23
+ cnt = 1
24
+ res = query("view marked:'#{name}'").empty?
25
+ while res do
26
+ swipe('up', {:query => "scrollView index:#{index-1}"})
27
+ res = query("view marked:'#{name}'").empty?
28
+ cnt = cnt + 1
29
+ if cnt >= 5 then
30
+ break
31
+ end
32
+ end
33
+ sleep(1.0)
34
+ touch("view marked:'#{name}'")
35
+ sleep(STEP_PAUSE)
36
+ end
37
+
38
+ Then /^I (?:press|touch) (\d+)% right and (\d+)% down from "([^\"]*)" $/ do |x,y,name|
39
+ raise "This step is not yet implemented on iOS"
40
+ end
41
+
42
+ Then /^I (?:press|touch) button number (\d+)$/ do |index|
43
+ index = index.to_i
44
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
45
+ touch("button index:#{index-1}")
46
+ sleep(STEP_PAUSE)
47
+ end
48
+
49
+ Then /^I (?:press|touch) the "([^\"]*)" button$/ do |name|
50
+ touch("button marked:'#{name}'")
51
+ sleep(STEP_PAUSE)
52
+ end
53
+
54
+ Then /^I (?:press|touch) the "([^\"]*)" (?:input|text) field$/ do |name|
55
+ touch("textField placeholder:'#{name}'")
56
+ sleep(STEP_PAUSE)
57
+ end
58
+
59
+ #Note in tables views: this means visible cell index!
60
+ Then /^I (?:press|touch) list item number (\d+)$/ do |index|
61
+ index = index.to_i
62
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
63
+ touch("tableViewCell index:#{index-1}")
64
+ sleep(STEP_PAUSE)
65
+ end
66
+
67
+ Then /^I (?:press|touch) list item "([^\"]*)"$/ do |cell_name|
68
+ touch("tableViewCell marked:'#{cell_name}'")
69
+ sleep(STEP_PAUSE)
70
+ end
71
+
72
+ Then /^I toggle the switch$/ do
73
+ touch("switch")
74
+ sleep(STEP_PAUSE)
75
+ end
76
+
77
+ Then /^I toggle the "([^\"]*)" switch$/ do |name|
78
+ touch("switch marked:'#{name}'")
79
+ sleep(STEP_PAUSE)
80
+ end
81
+
82
+ Then /^I touch (?:the)? user location$/ do
83
+ touch("view:'MKUserLocationView'")
84
+ sleep(STEP_PAUSE)
85
+ end
86
+
87
+ Then /^I (?:touch|press) (?:done|search)$/ do
88
+ done
89
+ sleep(STEP_PAUSE)
90
+ end
91
+
92
+
93
+ ## -- Entering text -- ##
94
+
95
+ Then /^I enter "([^\"]*)" into the "([^\"]*)" field$/ do |text_to_type, field_name|
96
+ set_text("textField marked:'#{field_name}'", text_to_type)
97
+ sleep(STEP_PAUSE)
98
+ end
99
+
100
+ Then /^I enter "([^\"]*)" into the "([^\"]*)" (?:text|input) field$/ do |text_to_type, field_name|
101
+ set_text("textField placeholder:'#{field_name}'", text_to_type)
102
+ sleep(STEP_PAUSE)
103
+ end
104
+
105
+ Then /^I type "([^\"]*)" into the "([^\"]*)" (?:text|input) field$/ do |text_to_type, field_name|
106
+ tap(field_name)
107
+ wait_for_elements_exist( ["keyboardAutomatic"] )
108
+ keyboard_enter_text(text_to_type)
109
+ sleep(STEP_PAUSE)
110
+ end
111
+
112
+ Then /^I type "([^\"]*)" into (?:input|text) field number (\d+)$/ do |text_to_type, index|
113
+ index = index.to_i
114
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
115
+ touch("textField index:#{index-1}")
116
+ wait_for_elements_exist( ["keyboardAutomatic"] )
117
+ keyboard_enter_text(text_to_type)
118
+ sleep(STEP_PAUSE)
119
+ end
120
+
121
+ # alias
122
+ Then /^I fill in "([^\"]*)" with "([^\"]*)"$/ do |text_field, text_to_type|
123
+ macro %Q|I enter "#{text_to_type}" into the "#{text_field}" text field|
124
+ end
125
+
126
+ Then /^I use the native keyboard to enter "([^\"]*)" into the "([^\"]*)" (?:text|input) field$/ do |text_to_type, field_name|
127
+ raise "Native keyboard entering is not yet implemented on iOS"
128
+ end
129
+
130
+ Then /^I fill in text fields as follows:$/ do |table|
131
+ table.hashes.each do |row|
132
+ macro %Q|I enter "#{row['text']}" into the "#{row['field']}" text field|
133
+ end
134
+ end
135
+
136
+ Then /^I enter "([^\"]*)" into (?:input|text) field number (\d+)$/ do |text, index|
137
+ index = index.to_i
138
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
139
+ set_text("textField index:#{index-1}",text)
140
+ end
141
+
142
+ Then /^I enter "([^\"]*)" into text view number (\d+)$/ do |text, index|
143
+ index = index.to_i
144
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
145
+ set_text("textView index:#{index-1}",text)
146
+ end
147
+
148
+ Then /^I use the native keyboard to enter "([^\"]*)" into (?:input|text) field number (\d+)$/ do |text, index|
149
+ raise "Native keyboard entering is not yet implemented on iOS"
150
+ end
151
+
152
+
153
+ When /^I clear "([^\"]*)"$/ do |name|
154
+ macro %Q|I enter "" into the "#{name}" text field|
155
+ end
156
+
157
+ Then /^I clear (?:input|text) field number (\d+)$/ do |index|
158
+ index = index.to_i
159
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
160
+ set_text("textField index:#{index-1}","")
161
+ end
162
+
163
+ # -- See -- #
164
+ Then /^I wait to see "([^\"]*)"$/ do |expected_mark|
165
+ wait_for(WAIT_TIMEOUT) { view_with_mark_exists( expected_mark ) }
166
+ end
167
+
168
+ Then /^I wait until I don't see "([^\"]*)"$/ do |expected_mark|
169
+ sleep 1## wait for previous screen to disappear
170
+ wait_for(WAIT_TIMEOUT) { not element_exists( "view marked:'#{expected_mark}'" )}
171
+ end
172
+
173
+ Then /^I wait to not see "([^\"]*)"$/ do |expected_mark|
174
+ macro %Q|I wait until I don't see "#{expected_mark}"|
175
+ end
176
+
177
+ Then /^I wait for "([^\"]*)" to appear$/ do |name|
178
+ macro %Q|I wait to see "#{name}"|
179
+ end
180
+
181
+ Then /^I wait for the "([^\"]*)" button to appear$/ do |name|
182
+ wait_for(WAIT_TIMEOUT) { element_exists( "button marked:'#{name}'" ) }
183
+ end
184
+
185
+
186
+ Then /^I wait to see a navigation bar titled "([^\"]*)"$/ do |expected_mark|
187
+ wait_for(WAIT_TIMEOUT) do
188
+ query('navigationItemView', :accessibilityLabel).include?(expected_mark)
189
+ end
190
+ end
191
+
192
+ Then /^I wait for the "([^\"]*)" (?:input|text) field$/ do |placeholder|
193
+ wait_for(WAIT_TIMEOUT) { element_exists( "textField placeholder:'#{placeholder}'") }
194
+ end
195
+
196
+ Then /^I wait for (\d+) (?:input|text) field(?:s)?$/ do |count|
197
+ count = count.to_i
198
+ wait_for(WAIT_TIMEOUT) { query(:textField).count >= count }
199
+ end
200
+
201
+
202
+ Then /^I wait$/ do
203
+ sleep 2
204
+ end
205
+
206
+ Then /^I wait and wait$/ do
207
+ sleep 4
208
+ end
209
+
210
+ Then /^I wait and wait and wait...$/ do
211
+ sleep 10
212
+ end
213
+
214
+ When /^I wait for ([\d\.]+) second(?:s)?$/ do |num_seconds|
215
+ num_seconds = num_seconds.to_f
216
+ sleep num_seconds
217
+ end
218
+
219
+
220
+ Then /^I go back$/ do
221
+ touch("navigationItemButtonView first")
222
+ sleep(STEP_PAUSE)
223
+ end
224
+
225
+ Then /^(?:I\s)?take (?:picture|screenshot)$/ do
226
+ sleep(STEP_PAUSE)
227
+ screenshot_embed
228
+ end
229
+
230
+ Then /^I swipe (left|right|up|down)$/ do |dir|
231
+ swipe(dir)
232
+ sleep(STEP_PAUSE)
233
+ end
234
+
235
+ Then /^I swipe (left|right|up|down) on number (\d+)$/ do |dir, index|
236
+ index = index.to_i
237
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
238
+ swipe(dir, {:query => "scrollView index:#{index-1}"})
239
+ sleep(STEP_PAUSE)
240
+ end
241
+
242
+ Then /^I swipe (left|right|up|down) on number (\d+) at x (\d+) and y (\d+)$/ do |dir, index, x, y|
243
+ index = index.to_i
244
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
245
+ swipe(dir, {:offset => {:x => x.to_i, :y => y.to_i}, :query => "scrollView index:#{index-1}"})
246
+ sleep(STEP_PAUSE)
247
+ end
248
+
249
+ Then /^I swipe (left|right|up|down) on "([^\"]*)"$/ do |dir, mark|
250
+ swipe(dir, {:query => "view marked:'#{mark}'"})
251
+ sleep(STEP_PAUSE)
252
+ end
253
+
254
+ Then /^I swipe on cell number (\d+)$/ do |index|
255
+ index = index.to_i
256
+ screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
257
+ cell_swipe({:query => "tableViewCell index:#{index-1}"})
258
+ sleep(STEP_PAUSE)
259
+ end
260
+
261
+
262
+ ##pinch##
263
+ Then /^I pinch to zoom (in|out)$/ do |in_out|
264
+ pinch(in_out)
265
+ sleep(STEP_PAUSE)
266
+ end
267
+
268
+ Then /^I pinch to zoom (in|out) on "([^\"]*)"$/ do |in_out, name|
269
+ pinch(in_out,{:query => "view marked:'#{name}'"})
270
+ sleep(STEP_PAUSE)
271
+ end
272
+
273
+ # Note "up/left/right" seems to be missing on the web base
274
+ Then /^I scroll (left|right|up|down)$/ do |dir|
275
+ scroll("scrollView index:0", dir)
276
+ sleep(STEP_PAUSE)
277
+ end
278
+
279
+ Then /^I scroll (left|right|up|down) on "([^\"]*)"$/ do |dir,name|
280
+ scroll("view marked:'#{name}'", dir)
281
+ sleep(STEP_PAUSE)
282
+ end
283
+
284
+
285
+
286
+ ### Playback ###
287
+ Then /^I playback recording "([^\"]*)"$/ do |filename|
288
+ playback(filename)
289
+ sleep(STEP_PAUSE)
290
+ end
291
+
292
+ Then /^I playback recording "([^\"]*)" on "([^\"]*)"$/ do |filename, name|
293
+ playback(filename, {:query => "view marked:'#{name}'"})
294
+ sleep(STEP_PAUSE)
295
+ end
296
+
297
+ Then /^I playback recording "([^\"]*)" on "([^\"]*)" with offset (\d+),(\d+)$/ do |filename, name, x, y|
298
+ x = x.to_i
299
+ y = y.to_i
300
+ playback(filename, {:query => "view marked:'#{name}'", :offset => {:x => x, :y => y}})
301
+ sleep(STEP_PAUSE)
302
+ end
303
+
304
+ Then /^I reverse playback recording "([^\"]*)"$/ do |filename|
305
+ playback(filename, {:reverse => true})
306
+ sleep(STEP_PAUSE)
307
+ end
308
+
309
+ Then /^I reverse playback recording "([^\"]*)" on "([^\"]*)"$/ do |filename, name|
310
+ playback(filename, {:query => "view marked:'#{name}'",:reverse => true})
311
+ sleep(STEP_PAUSE)
312
+ end
313
+
314
+ Then /^I reverse playback recording "([^\"]*)" on "([^\"]*)" with offset (\d+),(\d+)$/ do |filename, name, x, y|
315
+ x = x.to_i
316
+ y = y.to_i
317
+ playback(filename, {:query => "view marked:'#{name}'", :offset => {:x => x, :y => y},:reverse => true})
318
+ sleep(STEP_PAUSE)
319
+ end
320
+
321
+
322
+ ### Device orientation ###
323
+ Then /^I rotate device (left|right)$/ do |dir|
324
+ dir = dir.to_sym
325
+ rotate(dir)
326
+ sleep(5)#SERVO wait
327
+ end
328
+
329
+ Then /^I send app to background for (\d+) seconds$/ do |secs|
330
+ secs = secs.to_f
331
+ background(secs)
332
+ sleep(secs+10)
333
+ end
334
+
335
+ ### Assertions ###
336
+ Then /^I should see "([^\"]*)"$/ do |expected_mark|
337
+ res = (element_exists( "view marked:'#{expected_mark}'" ) or
338
+ element_exists( "view text:'#{expected_mark}'"))
339
+ if not res
340
+ screenshot_and_raise "No element found with mark or text: #{expected_mark}"
341
+ end
342
+ end
343
+
344
+ Then /^I should not see "([^\"]*)"$/ do |expected_mark|
345
+ res = query("view marked:'#{expected_mark}'")
346
+ res.concat query("view text:'#{expected_mark}'")
347
+ unless res.empty?
348
+ screenshot_and_raise "Expected no element with text nor accessibilityLabel: #{expected_mark}, found #{res.join(", ")}"
349
+ end
350
+ end
351
+
352
+ Then /^I should see a "([^\"]*)" button$/ do |expected_mark|
353
+ check_element_exists("button marked:'#{expected_mark}'")
354
+ end
355
+ Then /^I should not see a "([^\"]*)" button$/ do |expected_mark|
356
+ check_element_does_not_exist("button marked:'#{expected_mark}'")
357
+ end
358
+
359
+ Then /^I don't see the text "([^\"]*)"$/ do |text|
360
+ macro %Q|I should not see "#{text}"|
361
+ end
362
+ Then /^I don't see the "([^\"]*)"$/ do |text|
363
+ macro %Q|I should not see "#{text}"|
364
+ end
365
+
366
+ Then /^I see the text "([^\"]*)"$/ do |text|
367
+ macro %Q|I should see "#{text}"|
368
+ end
369
+ Then /^I see the "([^\"]*)"$/ do |text|
370
+ macro %Q|I should see "#{text}"|
371
+ end
372
+
373
+ Then /^I (?:should)? see text starting with "([^\"]*)"$/ do |text|
374
+ res = query("view {text BEGINSWITH '#{text}'}").empty?
375
+ if res
376
+ screenshot_and_raise "No text found starting with: #{text}"
377
+ end
378
+ end
379
+
380
+ Then /^I (?:should)? see text containing "([^\"]*)"$/ do |text|
381
+ res = query("view {text LIKE '*#{text}*'}").empty?
382
+ if res
383
+ screenshot_and_raise "No text found containing: #{text}"
384
+ end
385
+ end
386
+
387
+ Then /^I (?:should)? see text ending with "([^\"]*)"$/ do |text|
388
+ res = query("view {text ENDSWITH '#{text}'}").empty?
389
+ if res
390
+ screenshot_and_raise "No text found ending with: #{text}"
391
+ end
392
+ end
393
+
394
+ Then /^I see (\d+) (?:input|text) field(?:s)?$/ do |count|
395
+ count = count.to_i
396
+ cnt = query(:textField).count
397
+ if cnt < count
398
+ screenshot_and_raise "Expected at least #{count} text/input fields, found #{cnt}"
399
+ end
400
+ end
401
+
402
+ Then /^I should see a "([^\"]*)" (?:input|text) field$/ do |expected_mark|
403
+ res = element_exists("textField placeholder:'#{expected_mark}'") or
404
+ element_exists("textField marked:'#{expected_mark}'")
405
+ unless res
406
+ screenshot_and_raise "Expected textfield with placeholder or accessibilityLabel: #{txt}"
407
+ end
408
+ end
409
+
410
+ Then /^I should not see a "([^\"]*)" (?:input|text) field$/ do |expected_mark|
411
+ res = query("textField placeholder:'#{expected_mark}'")
412
+ res.concat query("textField marked:'#{expected_mark}'")
413
+ unless res.empty?
414
+ screenshot_and_raise "Expected no textfield with placeholder nor accessibilityLabel: #{txt}, found #{res}"
415
+ end
416
+ end
417
+
418
+
419
+ Then /^I should see a map$/ do
420
+ check_element_exists("view:'MKMapView'")
421
+ end
422
+
423
+ Then /^I should see (?:the)? user location$/ do
424
+ check_element_exists("view:'MKUserLocationView'")
425
+ end
426
+
427
+ ### Dismiss a dialog if it appears ###
428
+ Then /^I (?:press|touch) "([^\"]*)" on the "([^\"]*)" dialog if it appears$/ do |text, dialog|
429
+ text = escape_quotes(text)
430
+ dialog = escape_quotes(dialog)
431
+ res = (element_exists( "view marked:'#{dialog}'" ) or
432
+ element_exists( "view text:'#{dialog}'"))
433
+ if res
434
+ touch("view marked:'#{text}'")
435
+ end
436
+ sleep(STEP_PAUSE)
437
+ end
438
+
439
+