Class: AutoPilot::SeleniumRunner
- Inherits:
-
Object
- Object
- AutoPilot::SeleniumRunner
- Defined in:
- lib/auto_pilot/selenium_runner.rb
Overview
Controller for AutoPilot.
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
-
#clean ⇒ Object
writeonly
Sets the attribute clean.
-
#dir ⇒ Object
Returns the value of attribute dir.
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#port ⇒ Object
Returns the value of attribute port.
-
#suites ⇒ Object
Returns the value of attribute suites.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
Instance Method Summary collapse
- #check_location ⇒ Object
- #clean? ⇒ Boolean
-
#initialize(browser_name) ⇒ SeleniumRunner
constructor
A new instance of SeleniumRunner.
- #run ⇒ Object
Constructor Details
#initialize(browser_name) ⇒ SeleniumRunner
Returns a new instance of SeleniumRunner.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/auto_pilot/selenium_runner.rb', line 43 def initialize(browser_name) @port = DEFAULT_PORT @timeout = DEFAULT_TIMEOUT @interval = DEFAULT_INTERVAL @suites = [] @clean = false @browser_name = browser_name @dir = DEFAULT_RESULTS_DIR if block_given? yield self end end |
Instance Attribute Details
#browser ⇒ Object
Returns the value of attribute browser.
40 41 42 |
# File 'lib/auto_pilot/selenium_runner.rb', line 40 def browser @browser end |
#clean=(value) ⇒ Object (writeonly)
Sets the attribute clean
41 42 43 |
# File 'lib/auto_pilot/selenium_runner.rb', line 41 def clean=(value) @clean = value end |
#dir ⇒ Object
Returns the value of attribute dir.
40 41 42 |
# File 'lib/auto_pilot/selenium_runner.rb', line 40 def dir @dir end |
#interval ⇒ Object
Returns the value of attribute interval.
40 41 42 |
# File 'lib/auto_pilot/selenium_runner.rb', line 40 def interval @interval end |
#port ⇒ Object
Returns the value of attribute port.
40 41 42 |
# File 'lib/auto_pilot/selenium_runner.rb', line 40 def port @port end |
#suites ⇒ Object
Returns the value of attribute suites.
40 41 42 |
# File 'lib/auto_pilot/selenium_runner.rb', line 40 def suites @suites end |
#timeout ⇒ Object
Returns the value of attribute timeout.
40 41 42 |
# File 'lib/auto_pilot/selenium_runner.rb', line 40 def timeout @timeout end |
Instance Method Details
#check_location ⇒ Object
56 57 58 59 |
# File 'lib/auto_pilot/selenium_runner.rb', line 56 def check_location #puts Dir.pwd[-7..-1] #abort("Please run this script from the \'webtest\' directory!") if(Dir.pwd[-7..-1] != "webtest") end |
#clean? ⇒ Boolean
61 62 63 |
# File 'lib/auto_pilot/selenium_runner.rb', line 61 def clean? @clean end |
#run ⇒ Object
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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/auto_pilot/selenium_runner.rb', line 65 def run server = nil FileUtils.rm_r(dir) if self.clean? && File.exist?(dir) PassFailFile.clean(dir) # Thread that runs the http server server_thread = Thread.new do server = HTTPServer.new(:Port => @port) server.mount("/postResults", SeleniumTestResultsServlet, @dir) trap("INT"){ server.shutdown } server.start end # Thread that runs the test processor @suites.each do |suite| #make sure the server is running begin puts suite res = Net::HTTP.get_response(URI.parse(suite)) next unless res.code == '200' rescue Errno::ECONNREFUSED => error puts error next end processor_thread = Thread.new do ResultsState.waiting = true poller = ResultsStatePoller.new poller.timeout = @timeout poller.interval = @interval start_time = Time.now trap("INT"){ poller.stop; break } poller.start end # Open the file in the browser. # Mac OS browser = Browser.new(@browser_name, suite, @port) puts "starting browser ", browser.name browser.start # Join the thread, then quit the browser processor_thread.join # Quit the browser puts "quitting browser #{@browser_name}" browser.stop end server.shutdown server_thread.join end |