Class: AutoPilot::CLI
- Inherits:
-
Object
- Object
- AutoPilot::CLI
- 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
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.execute! ⇒ Object
Invoke autopilot using the ARGV array as the option parameters.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(args = ARGV) ⇒ CLI
constructor
A new instance of CLI.
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. = "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
#args ⇒ Object (readonly)
Returns the value of attribute args.
29 30 31 |
# File 'lib/auto_pilot/CLI.rb', line 29 def args @args end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
29 30 31 |
# File 'lib/auto_pilot/CLI.rb', line 29 def @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 = [:timeout] if [:timeout] runner.interval = [:interval] if [:interval] runner.port = [:port] if [:port] runner.dir = [:dir] if [:dir] runner.clean = true if [:clean] for suite in [:suites] runner.suites << suite end runner.run end |