Module: Frank::Cucumber::FrankHelper
- Defined in:
- lib/frank-cucumber/frank_helper.rb
Instance Method Summary collapse
- #app_exec(method_name, *method_args) ⇒ Object
- #check_element_does_not_exist(query) ⇒ Object
- #check_element_exists(query) ⇒ Object
- #check_view_with_mark_exists(expected_mark) ⇒ Object
- #element_exists(query) ⇒ Object
-
#element_is_not_hidden(query) ⇒ Object
a better name would be element_exists_and_is_not_hidden.
- #frank_url_for(verb) ⇒ Object
- #frankly_current_orientation ⇒ Object
- #frankly_dump ⇒ Object
- #frankly_is_accessibility_enabled ⇒ Object
- #frankly_map(query, method_name, *method_args) ⇒ Object
- #frankly_oriented_landscape? ⇒ Boolean
- #frankly_oriented_portrait? ⇒ Boolean
- #frankly_ping ⇒ Object
- #get_to_uispec_server(verb) ⇒ Object
- #make_http_request(url, req) ⇒ Object
-
#post_to_uispec_server(verb, command_hash) ⇒ Object
taken from Ian Dee’s Encumber.
- #press_home_on_simulator ⇒ Object
- #quit_simulator ⇒ Object
- #rotate_simulator_left ⇒ Object
- #rotate_simulator_right ⇒ Object
- #shake_simulator ⇒ Object
- #simulate_hardware_keyboard ⇒ Object
- #simulate_memory_warning ⇒ Object
-
#simulator_hardware_menu_press(menu_label) ⇒ Object
Note this needs to have “Enable access for assistive devices” chcked in the Universal Access system preferences.
- #start_recording ⇒ Object
- #stop_recording ⇒ Object
- #toggle_call_status_bar ⇒ Object
- #touch(uiquery) ⇒ Object
- #view_with_mark_exists(expected_mark) ⇒ Object
- #wait_for_frank_to_come_up ⇒ Object
Instance Method Details
#app_exec(method_name, *method_args) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/frank-cucumber/frank_helper.rb', line 45 def app_exec(method_name, *method_args) operation_map = { :method_name => method_name, :arguments => method_args } before = Time.now res = post_to_uispec_server( 'app_exec', :operation => operation_map ) logger.debug( "MAP applying #{method_name} with args:( #{method_args.inspect} ) to 'Application Delegate' took #{Time.now - before} seconds" ) res = JSON.parse( res ) if res['outcome'] != 'SUCCESS' raise "app_exec #{method_name} failed because: #{res['reason']}\n#{res['details']}" end res['results'] end |
#check_element_does_not_exist(query) ⇒ Object
25 26 27 28 |
# File 'lib/frank-cucumber/frank_helper.rb', line 25 def check_element_does_not_exist( query ) #puts "checking #{query} does not exist..." element_exists( query ).should be_false end |
#check_element_exists(query) ⇒ Object
20 21 22 23 |
# File 'lib/frank-cucumber/frank_helper.rb', line 20 def check_element_exists( query ) #puts "checking #{query} exists..." element_exists( query ).should be_true end |
#check_view_with_mark_exists(expected_mark) ⇒ Object
34 35 36 |
# File 'lib/frank-cucumber/frank_helper.rb', line 34 def check_view_with_mark_exists(expected_mark) check_element_exists( "view marked:'#{expected_mark}'" ) end |
#element_exists(query) ⇒ Object
14 15 16 17 18 |
# File 'lib/frank-cucumber/frank_helper.rb', line 14 def element_exists( query ) matches = frankly_map( query, 'accessibilityLabel' ) # TODO: raise warning if matches.count > 1 !matches.empty? end |
#element_is_not_hidden(query) ⇒ Object
a better name would be element_exists_and_is_not_hidden
39 40 41 42 43 |
# File 'lib/frank-cucumber/frank_helper.rb', line 39 def element_is_not_hidden(query) matches = frankly_map( query, 'isHidden' ) matches.delete(true) !matches.empty? end |
#frank_url_for(verb) ⇒ Object
153 154 155 156 157 |
# File 'lib/frank-cucumber/frank_helper.rb', line 153 def frank_url_for( verb ) url = URI.parse "http://localhost:37265/" url.path = '/'+verb url end |
#frankly_current_orientation ⇒ Object
91 92 93 94 |
# File 'lib/frank-cucumber/frank_helper.rb', line 91 def frankly_current_orientation res = get_to_uispec_server( 'orientation' ) JSON.parse( res )['orientation'] end |
#frankly_dump ⇒ Object
78 79 80 81 |
# File 'lib/frank-cucumber/frank_helper.rb', line 78 def frankly_dump res = get_to_uispec_server( 'dump' ) puts JSON.pretty_generate(JSON.parse(res)) rescue puts res #dumping a super-deep DOM causes errors end |
#frankly_is_accessibility_enabled ⇒ Object
97 98 99 100 |
# File 'lib/frank-cucumber/frank_helper.rb', line 97 def frankly_is_accessibility_enabled res = get_to_uispec_server( 'accessibility_check' ) JSON.parse( res )['accessibility_enabled'] == 'true' end |
#frankly_map(query, method_name, *method_args) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/frank-cucumber/frank_helper.rb', line 64 def frankly_map( query, method_name, *method_args ) operation_map = { :method_name => method_name, :arguments => method_args } res = post_to_uispec_server( 'map', :query => query, :operation => operation_map ) res = JSON.parse( res ) if res['outcome'] != 'SUCCESS' raise "frankly_map #{query} #{method_name} failed because: #{res['reason']}\n#{res['details']}" end res['results'] end |
#frankly_oriented_landscape? ⇒ Boolean
87 88 89 |
# File 'lib/frank-cucumber/frank_helper.rb', line 87 def frankly_oriented_landscape? 'landscape' == frankly_current_orientation end |
#frankly_oriented_portrait? ⇒ Boolean
83 84 85 |
# File 'lib/frank-cucumber/frank_helper.rb', line 83 def frankly_oriented_portrait? 'portrait' == frankly_current_orientation end |
#frankly_ping ⇒ Object
129 130 131 132 133 134 135 136 |
# File 'lib/frank-cucumber/frank_helper.rb', line 129 def frankly_ping get_to_uispec_server('') return true rescue Errno::ECONNREFUSED return false rescue EOFError return false end |
#get_to_uispec_server(verb) ⇒ Object
147 148 149 150 151 |
# File 'lib/frank-cucumber/frank_helper.rb', line 147 def get_to_uispec_server( verb ) url = frank_url_for( verb ) req = Net::HTTP::Get.new url.path make_http_request( url, req ) end |
#make_http_request(url, req) ⇒ Object
159 160 161 162 163 164 165 166 167 |
# File 'lib/frank-cucumber/frank_helper.rb', line 159 def make_http_request( url, req ) http = Net::HTTP.new(url.host, url.port) res = http.start do |sess| sess.request req end res.body end |
#post_to_uispec_server(verb, command_hash) ⇒ Object
taken from Ian Dee’s Encumber
139 140 141 142 143 144 145 |
# File 'lib/frank-cucumber/frank_helper.rb', line 139 def post_to_uispec_server( verb, command_hash ) url = frank_url_for( verb ) req = Net::HTTP::Post.new url.path req.body = command_hash.to_json make_http_request( url, req ) end |
#press_home_on_simulator ⇒ Object
205 206 207 |
# File 'lib/frank-cucumber/frank_helper.rb', line 205 def press_home_on_simulator "Home" end |
#quit_simulator ⇒ Object
188 189 190 191 192 |
# File 'lib/frank-cucumber/frank_helper.rb', line 188 def quit_simulator %x{osascript<<APPLESCRIPT- application "iPhone Simulator" quit APPLESCRIPT} end |
#rotate_simulator_left ⇒ Object
209 210 211 |
# File 'lib/frank-cucumber/frank_helper.rb', line 209 def rotate_simulator_left "Rotate Left" end |
#rotate_simulator_right ⇒ Object
213 214 215 |
# File 'lib/frank-cucumber/frank_helper.rb', line 213 def rotate_simulator_right "Rotate Right" end |
#shake_simulator ⇒ Object
217 218 219 |
# File 'lib/frank-cucumber/frank_helper.rb', line 217 def shake_simulator "Shake Gesture" end |
#simulate_hardware_keyboard ⇒ Object
229 230 231 |
# File 'lib/frank-cucumber/frank_helper.rb', line 229 def simulate_hardware_keyboard "Simulate Hardware Keyboard" end |
#simulate_memory_warning ⇒ Object
221 222 223 |
# File 'lib/frank-cucumber/frank_helper.rb', line 221 def simulate_memory_warning "Simulate Memory Warning" end |
#simulator_hardware_menu_press(menu_label) ⇒ Object
Note this needs to have “Enable access for assistive devices” chcked in the Universal Access system preferences
196 197 198 199 200 201 202 203 |
# File 'lib/frank-cucumber/frank_helper.rb', line 196 def ( ) %x{osascript<<APPLESCRIPT activate application "iPhone Simulator" tell application "System Events" click menu item "#{menu_label}" of menu "Hardware" of menu bar of process "iPhone Simulator" end tell APPLESCRIPT} end |
#start_recording ⇒ Object
169 170 171 172 173 174 175 176 177 |
# File 'lib/frank-cucumber/frank_helper.rb', line 169 def start_recording %x{osascript<<APPLESCRIPT tell application "QuickTime Player" set sr to new screen recording tell sr to start end tell APPLESCRIPT} end |
#stop_recording ⇒ Object
179 180 181 182 183 184 185 186 |
# File 'lib/frank-cucumber/frank_helper.rb', line 179 def stop_recording %x{osascript<<APPLESCRIPT tell application "QuickTime Player" set sr to (document 1) tell sr to stop end tell APPLESCRIPT} end |
#toggle_call_status_bar ⇒ Object
225 226 227 |
# File 'lib/frank-cucumber/frank_helper.rb', line 225 def "Toggle In-Call Status Bar" end |
#touch(uiquery) ⇒ Object
8 9 10 11 12 |
# File 'lib/frank-cucumber/frank_helper.rb', line 8 def touch( uiquery ) views_touched = frankly_map( uiquery, 'touch' ) raise "could not find anything matching [#{uiquery}] to touch" if views_touched.empty? #TODO raise warning if views_touched.count > 1 end |
#view_with_mark_exists(expected_mark) ⇒ Object
30 31 32 |
# File 'lib/frank-cucumber/frank_helper.rb', line 30 def view_with_mark_exists(expected_mark) element_exists( "view marked:'#{expected_mark}'" ) end |
#wait_for_frank_to_come_up ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/frank-cucumber/frank_helper.rb', line 102 def wait_for_frank_to_come_up num_consec_successes = 0 num_consec_failures = 0 Timeout.timeout(20) do while num_consec_successes <= 6 if frankly_ping num_consec_failures = 0 num_consec_successes += 1 print (num_consec_successes == 1 ) ? "\n" : "\r" print "FRANK!".slice(0,num_consec_successes) else num_consec_successes = 0 num_consec_failures += 1 print (num_consec_failures == 1 ) ? "\n" : "\r" print "PING FAILED" + "!"*num_consec_failures end STDOUT.flush sleep 0.2 end puts '' end unless frankly_is_accessibility_enabled raise "ACCESSIBILITY DOES NOT APPEAR TO BE ENABLED ON YOUR SIMULATOR. Hit the home button, go to settings, select Accessibility, and turn the inspector on." end end |