Class: ParallelCalabash::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/parallel_calabash/runner.rb

Class Method Summary collapse

Class Method Details

.base_commandObject



4
5
6
# File 'lib/parallel_calabash/runner.rb', line 4

def base_command
  'calabash-android run'
end

.command_for_process(process_number, cmd) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/parallel_calabash/runner.rb', line 26

def command_for_process process_number, cmd
  env = {}
  device_for_current_process = ParallelCalabash::AdbHelper.device_for_process process_number
  env = env.merge({'AUTOTEST' => '1', 'ADB_DEVICE_ARG' => device_for_current_process, "TEST_PROCESS_NUMBER" => (process_number+1).to_s})
  separator = (WINDOWS ? ' & ' : ';')
  exports = env.map { |k, v| WINDOWS ? "(SET \"#{k}=#{v}\")" : "#{k}=#{v};export #{k}" }.join(separator)
  exports + separator + cmd
end

.execute_command_for_process(process_number, cmd, silence) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/parallel_calabash/runner.rb', line 13

def execute_command_for_process(process_number, cmd, silence)
  command_for_current_process = command_for_process(process_number, cmd)
  output = open("|#{command_for_current_process}", "r") { |output| show_output(output, silence) }
  exitstatus = $?.exitstatus

  if silence
    $stdout.print output
    $stdout.flush
  end
  puts "\n****** PROCESS #{process_number} COMPLETED ******\n\n"
  {:stdout => output, :exit_status => exitstatus}
end

.run_tests(test_files, process_number, options) ⇒ Object



8
9
10
11
# File 'lib/parallel_calabash/runner.rb', line 8

def run_tests(test_files, process_number, options)
  cmd = [base_command, options[:apk_path], options[:cucumber_options], *test_files].compact*' '
  execute_command_for_process(process_number, cmd, options[:mute_output])
end

.show_output(output, silence) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/parallel_calabash/runner.rb', line 35

def show_output(output, silence)
  result = ""
  loop do
    begin
      read = output.readpartial(1000000) # read whatever chunk we can get
      result << read
      unless silence
        $stdout.print read
        $stdout.flush
      end
    end
  end rescue EOFError
  result
end