Class: AutoPilot::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/auto_pilot/CLI.rb

Overview

The CLI class encapsulates the behavior of autopilot when it is invoked as a command-line utility. This allows other programs to embed AP and preserve it’s command-line semantics.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CLI

Returns a new instance of CLI.



31
32
33
34
35
36
37
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/auto_pilot/CLI.rb', line 31

def initialize(args = ARGV)
  @args = args
  @options = { :suites => [] }

  OptionParser.new do |opts|
    opts.banner = "Usage: #{$0} [options] [args]"

    opts.separator ""
    opts.separator "AutoPilot Options -----------------------"
    opts.separator ""

    opts.on("-s", "--suite SUITE",
      "A test suite to execute. Multiple suites may",
      "be specified, and are loaded in the given order."
    ) { |value| @options[:suites] << value }

    opts.on("-t", "--timeout [TIMEOUT]",
      "The timeout value in seconds to run a suite before giving up",
      "and moving on to the next suite."
    ) { |value| @options[:timeout] = value.to_i }

    opts.on("-i", "--interval [INTERVAL]",
      "The polling interval value in seconds to poll the server posted for results."
    ) { |value| @options[:interval] = value.to_i }

    opts.on("-c", "--clean [CLEAN]",
      "Flag to clean previous results. "
    ) { |value| @options[:clean] = true }

    opts.on("-b", "--browser [BROWSER]",
      "Browser to use: FIREFOX (or FF, default), IE, SAFARI."
    ) do |value| 
      case value
      when "FIREFOX", "FF"
        @options[:browser] = FIREFOX
      when "IE"
        @options[:browser] = IE
      when "SAFARI"
        @options[:browser] = SAFARI  
      else
        abort "Incorrect browser name: #{value}."
      end
    end

    opts.on("-d", "--dir [DIR]",
      "Directory to store the results. Defaults to ./tmp."
    ) { |value| @options[:dir] = value }

    opts.on("-p", "--port [PORT]",
      "Port on which to run the servlet server."
    ) { |value| @options[:port] = value }
    
    if args.empty?
      puts opts
      exit
    else
      opts.parse!(args)
    end
  end #OptionParser.new
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



29
30
31
# File 'lib/auto_pilot/CLI.rb', line 29

def args
  @args
end

#optionsObject (readonly)

Returns the value of attribute options.



29
30
31
# File 'lib/auto_pilot/CLI.rb', line 29

def options
  @options
end

Class Method Details

.execute!Object

Invoke autopilot using the ARGV array as the option parameters. This is what the command-line autopilot (aup) utility does.



11
12
13
# File 'lib/auto_pilot/CLI.rb', line 11

def self.execute!
  new.execute!
end

Instance Method Details

#execute!Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/auto_pilot/CLI.rb', line 15

def execute!
  runner = AutoPilot::SeleniumRunner.new(AutoPilot::FIREFOX)
  runner.timeout = options[:timeout] if options[:timeout]
  runner.interval = options[:interval] if options[:interval]
  runner.port = options[:port] if options[:port]
  runner.dir = options[:dir] if options[:dir]
  runner.clean = true if options[:clean]
  
  for suite in options[:suites]
    runner.suites << suite
  end
  runner.run
end