Module: UIAutoMonkey::CommandHelper
- Included in:
- MonkeyRunner
- Defined in:
- lib/smart_monkey/command_helper.rb
Instance Method Summary collapse
- #instruments_deviceinfo(device) ⇒ Object
- #is_simulator ⇒ Object
- #kill_all(process_name, signal = nil) ⇒ Object
-
#relaunch_app(device, app) ⇒ Object
def run_process(cmds) puts “Run: #cmdscmds.inspect” Kernel.system(cmds, *cmds) end.
- #run_process(cmds) ⇒ Object
- #shell(cmds) ⇒ Object
- #xcode_path ⇒ Object
Instance Method Details
#instruments_deviceinfo(device) ⇒ Object
7 8 9 |
# File 'lib/smart_monkey/command_helper.rb', line 7 def instruments_deviceinfo(device) `"instruments" -s devices | grep "#{device}"`.strip end |
#is_simulator ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/smart_monkey/command_helper.rb', line 11 def is_simulator deviceinfo = instruments_deviceinfo(device) if deviceinfo.include? "-" true else false end end |
#kill_all(process_name, signal = nil) ⇒ Object
77 78 79 80 81 |
# File 'lib/smart_monkey/command_helper.rb', line 77 def kill_all(process_name, signal=nil) signal = signal ? "-#{signal}" : '' # puts "killall #{signal} #{process_name}" Kernel.system("killall #{signal} '#{process_name}' >/dev/null 2>&1") end |
#relaunch_app(device, app) ⇒ Object
def run_process(cmds)
puts "Run: #{cmds.inspect}"
Kernel.system(cmds[0], *cmds[1..-1])
end
33 34 35 36 37 38 39 |
# File 'lib/smart_monkey/command_helper.rb', line 33 def relaunch_app(device,app) if is_simulator `xcrun simctl launch #{device} #{app} >/dev/null 2>&1 &` else `idevicedebug -u #{device} run #{app} >/dev/null 2>&1 &` end end |
#run_process(cmds) ⇒ Object
41 42 43 44 45 46 47 48 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 |
# File 'lib/smart_monkey/command_helper.rb', line 41 def run_process(cmds) puts "Run: #{cmds.inspect}" device = cmds[2] app = cmds[-7] Open3.popen3(*cmds) do |stdin, stdout, stderr, thread| @tmpline = "" stdin.close app_hang_monitor_thread = Thread.start{ sleep 30 while true current_line = @tmpline sleep 30 after_sleep_line = @tmpline if current_line == after_sleep_line puts "WARN: no response in log, trigger re-launch action." relaunch_app(device, app) end end } instruments_stderr_thread = Thread.start{ stderr.each do |line| puts line end } stdout.each do |line| @tmpline = line.strip puts @tmpline if @tmpline =~ /MonkeyTest finish/ || @tmpline =~ /Script was stopped by the user/ app_hang_monitor_thread.kill end end app_hang_monitor_thread.kill instruments_stderr_thread.kill end end |
#shell(cmds) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/smart_monkey/command_helper.rb', line 20 def shell(cmds) puts "Shell: #{cmds.inspect}" Open3.popen3(*cmds) do |stdin, stdout, stderr| stdin.close return stdout.read end end |
#xcode_path ⇒ Object
83 84 85 |
# File 'lib/smart_monkey/command_helper.rb', line 83 def xcode_path @xcode_path ||= shell(%w(xcode-select -print-path)).strip end |