Class: Selenium::WebDriver::PhantomJS::Service Private
- Inherits:
-
Object
- Object
- Selenium::WebDriver::PhantomJS::Service
- Defined in:
- lib/selenium/webdriver/phantomjs/service.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Constant Summary collapse
- START_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
20
- SOCKET_LOCK_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
45
- STOP_TIMEOUT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
5
- DEFAULT_PORT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
8910
- MISSING_TEXT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"Unable to find phantomjs executable."
Class Method Summary collapse
- .default_service(port = nil) ⇒ Object private
- .executable_path ⇒ Object private
Instance Method Summary collapse
- #find_free_port ⇒ Object private
-
#initialize(executable_path, port) ⇒ Service
constructor
private
A new instance of Service.
- #start(args = []) ⇒ Object private
- #stop ⇒ Object private
- #uri ⇒ Object private
Constructor Details
#initialize(executable_path, port) ⇒ Service
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Service.
49 50 51 52 53 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 49 def initialize(executable_path, port) @host = Platform.localhost @executable = executable_path @port = Integer(port) end |
Class Method Details
.default_service(port = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
45 46 47 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 45 def self.default_service(port = nil) new executable_path, DEFAULT_PORT end |
.executable_path ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
35 36 37 38 39 40 41 42 43 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 35 def self.executable_path @executable_path ||= ( path = PhantomJS.path path or raise Error::WebDriverError, MISSING_TEXT Platform.assert_executable path path ) end |
Instance Method Details
#find_free_port ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
85 86 87 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 85 def find_free_port @port = PortProber.above @port end |
#start(args = []) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 55 def start(args = []) if @process && @process.alive? raise "already started: #{uri.inspect} #{@executable.inspect}" end Platform.exit_hook { stop } # make sure we don't leave the server running socket_lock.locked do find_free_port start_process(args) connect_until_stable end end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 69 def stop return if @process.nil? || @process.exited? Net::HTTP.start(@host, @port) do |http| http.open_timeout = STOP_TIMEOUT / 2 http.read_timeout = STOP_TIMEOUT / 2 http.get("/shutdown") end ensure stop_process if Platform.jruby? && !$DEBUG @process.io.close rescue nil end end |
#uri ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 89 def uri URI.parse "http://#{@host}:#{@port}" end |