Class: AutoPilot::SeleniumRunner

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

Overview

Controller for AutoPilot.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#browserObject

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

Parameters:

  • value

    the value to set the attribute clean to.



41
42
43
# File 'lib/auto_pilot/selenium_runner.rb', line 41

def clean=(value)
  @clean = value
end

#dirObject

Returns the value of attribute dir.



40
41
42
# File 'lib/auto_pilot/selenium_runner.rb', line 40

def dir
  @dir
end

#intervalObject

Returns the value of attribute interval.



40
41
42
# File 'lib/auto_pilot/selenium_runner.rb', line 40

def interval
  @interval
end

#portObject

Returns the value of attribute port.



40
41
42
# File 'lib/auto_pilot/selenium_runner.rb', line 40

def port
  @port
end

#suitesObject

Returns the value of attribute suites.



40
41
42
# File 'lib/auto_pilot/selenium_runner.rb', line 40

def suites
  @suites
end

#timeoutObject

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_locationObject



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

Returns:

  • (Boolean)


61
62
63
# File 'lib/auto_pilot/selenium_runner.rb', line 61

def clean?
  @clean
end

#runObject



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