Module: BrowserShooter::Commander

Defined in:
lib/browser_shooter/commander.rb

Class Method Summary collapse

Class Method Details

.execute(command_executor, command) ⇒ Object



73
74
75
76
77
78
79
80
81
82
# File 'lib/browser_shooter/commander.rb', line 73

def self.execute( command_executor, command )
  BrowserShooter::Logger.log "command: #{command}"
  command_name = command.split( /[\s\(]/ )[0].strip

  if( command_executor.respond_to?( command_name.to_sym ) )
    eval "command_executor.#{command}"
  else
    eval "command_executor.driver.#{command}"
  end
end

.script(commands, driver, browser, output_path) ⇒ Object

Executes a test script with all its commands.

Returns: the test result in this format:

{
  :time => (the actual time),
  :success => (true|false),
  :command => (the actual command),
  :message => (the command message or error message),
}


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/browser_shooter/commander.rb', line 12

def self.script( commands, driver, browser, output_path )
  command_executor =
    BrowserShooter::Commands::Base.new(
      driver,
      browser,
      output_path
    )

  test_result =
    commands.map do |command|
      command_result =
        BrowserShooter::Commander.wrapper_execute(
          command_executor,
          command.strip
        )

      BrowserShooter::Logger.command_result( command_result )

      command_result
    end

  BrowserShooter::Logger.test_result( test_result )

  test_result
end

.wrapper_execute(command_executor, command) ⇒ Object



38
39
40
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
# File 'lib/browser_shooter/commander.rb', line 38

def self.wrapper_execute( command_executor, command )
  result = {
    :time     => Time.now.to_i,
    :command  => command
  }

  begin
    message =
      BrowserShooter::Commander.execute(
        command_executor,
        command
      )


    result.merge!(
      :success => true,
      :message => message
    )

  rescue Exception => e
    BrowserShooter::Logger.log "ERROR: #{e.message}"

    # puts "XXX: Exception"
    # puts e.backtrace.join( "\n" )

    result.merge!(
      :success  => false,
      :message  => e.message
    )

  end

  return result
end