lib/xcmonkey/driver.rb in xcmonkey-1.0.0 vs lib/xcmonkey/driver.rb in xcmonkey-1.1.0
- old
+ new
@@ -11,10 +11,11 @@
@session = { params: params, actions: [] }
ensure_driver_installed
end
def monkey_test_precondition
+ puts
ensure_device_exists
ensure_app_installed
terminate_app
open_home_screen(with_tracker: true)
launch_app
@@ -72,10 +73,12 @@
swipe(
start_coordinates: { x: action['x'], y: action['y'] },
end_coordinates: { x: action['endX'], y: action['endY'] },
duration: action['duration']
)
+ else
+ next
end
Logger.error('App lost') if describe_ui.shuffle.include?(@home_tracker)
end
end
@@ -117,37 +120,35 @@
keyboard_status = enable_simulator_keyboard ? 0 : 1
`defaults write com.apple.iphonesimulator ConnectHardwareKeyboard #{keyboard_status}`
end
def list_targets
- @list_targets ||= `idb list-targets`.split("\n")
- @list_targets
+ @targets ||= `idb list-targets --json`.split("\n").map! { |target| JSON.parse(target) }
+ @targets
end
- def list_booted_simulators
- `idb list-targets`.split("\n").grep(/Booted/)
+ def list_apps
+ `idb list-apps --udid #{udid} --json`.split("\n").map! { |app| JSON.parse(app) }
end
def ensure_app_installed
- Logger.error("App #{bundle_id} is not installed on device #{udid}") unless list_apps.include?(bundle_id)
+ return if list_apps.any? { |app| app['bundle_id'] == bundle_id }
+
+ Logger.error("App #{bundle_id} is not installed on device #{udid}")
end
def ensure_device_exists
- device = list_targets.detect { |target| target.include?(udid) }
+ device = list_targets.detect { |target| target['udid'] == udid }
Logger.error("Can't find device #{udid}") if device.nil?
- Logger.info('Device info:', payload: device)
- if device.include?('simulator')
+ Logger.info('Device info:', payload: JSON.pretty_generate(device))
+ if device['type'] == 'simulator'
configure_simulator_keyboard
boot_simulator
end
end
- def list_apps
- `idb list-apps --udid #{udid}`
- end
-
def tap(coordinates:)
Logger.info('Tap:', payload: JSON.pretty_generate(coordinates))
@session[:actions] << { type: :tap, x: coordinates[:x], y: coordinates[:y] } unless session_actions
`idb ui tap --udid #{udid} #{coordinates[:x]} #{coordinates[:y]}`
end
@@ -232,16 +233,15 @@
end
@home_tracker
end
def wait_until_app_launched
- app_info = nil
+ app_is_running = false
current_time = Time.now
- while app_info.nil? && Time.now < current_time + 5
- app_info = list_apps.split("\n").detect do |app|
- app =~ /#{bundle_id}.*Running/
- end
+ while !app_is_running && Time.now < current_time + 5
+ app_info = list_apps.detect { |app| app['bundle_id'] == bundle_id }
+ app_is_running = app_info && app_info['process_state'] == 'Running'
end
- Logger.error("Can't run the app #{bundle_id}") if app_info.nil?
- Logger.info('App info:', payload: app_info)
+ Logger.error("Can't run the app #{bundle_id}") unless app_is_running
+ Logger.info('App info:', payload: JSON.pretty_generate(app_info))
end
end