Module: Frank::Cucumber::Launcher

Includes:
FrankHelper
Included in:
Frank::CLI, Frank::Console
Defined in:
lib/frank-cucumber/launcher.rb

Constant Summary

Constants included from WaitHelper

WaitHelper::POLL_SLEEP, WaitHelper::TIMEOUT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from FrankHelper

#accessibility_frame, #app_exec, #base_server_url, #check_element_does_not_exist, #check_element_does_not_exist_or_is_not_visible, #check_element_exists, #check_element_exists_and_is_visible, #check_navigation_title_with_text_exists, #check_view_with_mark_does_not_exist, #check_view_with_mark_exists, #drag_with_initial_delay, #element_exists, #element_is_not_hidden, #fill_in, #frank_server, #frankly_current_orientation, #frankly_device_name, #frankly_dump, #frankly_is_accessibility_enabled, #frankly_map, #frankly_oriented_landscape?, #frankly_oriented_portrait?, #frankly_os_version, #frankly_ping, #frankly_screenshot, #frankly_set_orientation, #get_selector_quote, #is_ipad, #is_iphone, #is_mac, #navigation_title_with_text_exists, #selector_engine, test_on_physical_device_via_bonjour, #test_on_physical_device_with_ip, #touch, use_shelley_from_now_on, #view_with_mark_exists, #wait_for_element_to_exist, #wait_for_element_to_exist_and_then_touch_it, #wait_for_element_to_not_exist, #wait_for_frank_to_come_up, #wait_for_nothing_to_be_animating

Methods included from LocationHelper

#set_location

Methods included from HostScripting

#press_home_on_simulator, #quit_double_simulator, #quit_simulator, #rotate_simulator_left, #rotate_simulator_right, #shake_simulator, #simulate_hardware_keyboard, #simulate_memory_warning, #simulator_hardware_menu_press, #simulator_reset_data, #start_recording, #stop_recording, #toggle_call_status_bar

Methods included from GestureHelper

#double_tap, #double_tap_point, #drag_thumb_in_slider, #drag_thumb_in_slider_with_default_duration, #tap_and_hold, #tap_and_hold_point

Methods included from ScrollHelper

#scroll_table_view, #scroll_view_to_bottom, #scroll_view_to_position, #scroll_view_to_top

Methods included from KeyboardHelper

#type_into_keyboard, #type_shortcut

Methods included from WaitHelper

wait_until

Instance Attribute Details

#application_pathObject

Returns the value of attribute application_path.



10
11
12
# File 'lib/frank-cucumber/launcher.rb', line 10

def application_path
  @application_path
end

#sdkObject

Returns the value of attribute sdk.



10
11
12
# File 'lib/frank-cucumber/launcher.rb', line 10

def sdk
  @sdk
end

#versionObject

Returns the value of attribute version.



10
11
12
# File 'lib/frank-cucumber/launcher.rb', line 10

def version
  @version
end

Instance Method Details

#enforce(app_path, locator = Frank::Cucumber::AppBundleLocator.new) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/frank-cucumber/launcher.rb', line 20

def enforce(app_path, locator = Frank::Cucumber::AppBundleLocator.new)
  if app_path.nil?
    message = "APP_BUNDLE_PATH is not set. \n\nPlease set APP_BUNDLE_PATH (either an environment variable, or the ruby constant in support/env.rb) to the path of your Frankified target's iOS app bundle."
    possible_app_bundles = locator.guess_possible_app_bundles_for_dir( Dir.pwd )
    if possible_app_bundles && !possible_app_bundles.empty?
      message << "\n\nBased on your current directory, you probably want to use one of the following paths for your APP_BUNDLE_PATH:\n"
      message << possible_app_bundles.join("\n")
    end
    raise "\n\n"+("="*80)+"\n"+message+"\n"+("="*80)+"\n\n"
  end

  if app_path_problem = SimLauncher.check_app_path(app_path)
    raise "\n\n"+("="*80)+"\n"+app_path_problem+"\n"+("="*80)+"\n\n"
  end
end

#launch_app(app_path, sdk = nil, version = 'iphone', wait_for_launch = true) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/frank-cucumber/launcher.rb', line 36

def launch_app(app_path, sdk = nil, version = 'iphone', wait_for_launch = true)
  @application_path = app_path
  @sdk = sdk
  @version = version

  if path_is_mac_app(@application_path)
    launch_mac_app(wait_for_launch)
  else
    enforce(app_path)
    launch_ios_app(wait_for_launch)
  end
end

#launch_ios_app(wait_for_launch = true) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/frank-cucumber/launcher.rb', line 49

def launch_ios_app(wait_for_launch = true)
  # kill the app if it's already running, just in case this helps
  # reduce simulator flakiness when relaunching the app. Use a timeout of 5 seconds to
  # prevent us hanging around for ages waiting for the ping to fail if the app isn't running
  begin
    Timeout::timeout(5) { press_home_on_simulator if frankly_ping }
  rescue Timeout::Error
  end

  if( ENV['USE_SIM_LAUNCHER_SERVER'] )
    simulator = simulator_client
  else
    simulator = simulator_direct_client
  end

  num_timeouts = 0
  begin
    simulator.relaunch

    if wait_for_launch
      wait_for_frank_to_come_up
    end
  rescue Timeout::Error
    num_timeouts += 1
    puts "Encountered #{num_timeouts} timeouts while launching the app."
    if num_timeouts > 3
      raise "Encountered #{num_timeouts} timeouts in a row while trying to launch the app."
    end
    quit_double_simulator
    retry
  end

end

#launch_mac_app(wait_for_launch = true) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/frank-cucumber/launcher.rb', line 88

def launch_mac_app(wait_for_launch = true)
  `open "#{@application_path}"`

  if wait_for_launch
    wait_for_frank_to_come_up
  end
end

#path_is_mac_app(app_dir) ⇒ Object



83
84
85
# File 'lib/frank-cucumber/launcher.rb', line 83

def path_is_mac_app (app_dir)
  return File.exists? File.join( app_dir, "Contents", "MacOS" )
end

#quit_mac_app_if_runningObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/frank-cucumber/launcher.rb', line 96

def quit_mac_app_if_running
  pid = `ps -ax | grep "#{@app_path}" | grep -v grep`

  if pid != ""
    pid = pid.strip.split[0]
    `kill #{pid}`
  end

  Timeout::timeout(60) {
    while pid != ""
      pid = `ps -ax | grep "#{@app_path}" | grep -v grep`
    end
  }

end

#relaunch_mac_appObject



112
113
114
115
# File 'lib/frank-cucumber/launcher.rb', line 112

def relaunch_mac_app
  self.quit_if_running
  self.launch
end

#simulator_clientObject



12
13
14
# File 'lib/frank-cucumber/launcher.rb', line 12

def simulator_client
  @simulator_client ||= SimLauncher::Client.new(@application_path, @sdk, @version)
end

#simulator_direct_clientObject



16
17
18
# File 'lib/frank-cucumber/launcher.rb', line 16

def simulator_direct_client
  @simulator_direct_client ||= SimLauncher::DirectClient.new(@application_path, @sdk, @version)
end