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
- 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."
Instance Attribute Summary collapse
- #uri ⇒ Object readonly private
Class Method Summary collapse
- .default_service(port = nil) ⇒ Object private
- .executable_path ⇒ Object private
Instance Method Summary collapse
- #create_process(args) ⇒ Object private
-
#initialize(executable_path, port) ⇒ Service
constructor
private
A new instance of Service.
- #start(args = []) ⇒ Object private
- #stop ⇒ 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.
50 51 52 53 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 50 def initialize(executable_path, port) @uri = URI.parse "http://#{Platform.localhost}:#{port}" @executable = executable_path end |
Instance Attribute Details
#uri ⇒ Object (readonly)
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.
34 35 36 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 34 def uri @uri 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.
46 47 48 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 46 def self.default_service(port = nil) new executable_path, port || PortProber.above(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.
36 37 38 39 40 41 42 43 44 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 36 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
#create_process(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.
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 92 def create_process(args) server_command = [@executable, "--webdriver=#{@uri.port}", *args] process = ChildProcess.build(*server_command.compact) if $DEBUG == true process.io.inherit! elsif Platform.jruby? # apparently we need to read the output for phantomjs to work on jruby process.io.stdout = process.io.stderr = File.new(Platform.null_device, 'w') end process 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 68 69 70 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 55 def start(args = []) if @process && @process.alive? raise "already started: #{@uri.inspect} #{@executable.inspect}" end @process = create_process(args) @process.start socket_poller = SocketPoller.new Platform.localhost, @uri.port, START_TIMEOUT unless socket_poller.connected? raise Error::WebDriverError, "unable to connect to phantomjs @ #{@uri} after #{START_TIMEOUT} seconds" end Platform.exit_hook { stop } # make sure we don't leave the server running 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.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/selenium/webdriver/phantomjs/service.rb', line 72 def stop return if @process.nil? || @process.exited? Net::HTTP.start(uri.host, uri.port) do |http| http.open_timeout = STOP_TIMEOUT / 2 http.read_timeout = STOP_TIMEOUT / 2 http.get("/shutdown") end @process.poll_for_exit STOP_TIMEOUT rescue ChildProcess::TimeoutError # ok, force quit @process.stop STOP_TIMEOUT if Platform.jruby? && !$DEBUG @process.io.close rescue nil end end |