Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions rb/lib/selenium/webdriver/phantomjs/bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,26 @@ module PhantomJS
# @api private
class Bridge < Remote::Bridge

def initialize(opts = {})
http_client = opts.delete(:http_client)
def initialize(options = {})
remote_options = {}

if opts.has_key?(:url)
url = opts.delete(:url)
remote_options[:desired_capabilities] = Remote::Capabilities.phantomjs
remote_options[:http_client] = options.delete(:http_client) if options.has_key? :http_client

if options.has_key?(:url)
remote_options[:url] = options.delete(:url)
else
@service = Service.default_service
service_options = {}
service_options[:debugger] = options.delete(:debugger) if options.has_key? :debugger
service_options[:debugger_port] = options.delete(:debugger_port) if options.has_key? :debugger_port

@service = Service.default_service service_options
@service.start

url = @service.uri
remote_options[:url] = @service.uri
end

caps = Remote::Capabilities.phantomjs

remote_opts = {
:url => url,
:desired_capabilities => caps
}

remote_opts.merge!(:http_client => http_client) if http_client

super(remote_opts)
super remote_options
end

def browser
Expand Down
38 changes: 27 additions & 11 deletions rb/lib/selenium/webdriver/phantomjs/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,50 @@ module PhantomJS

class Service
START_TIMEOUT = 20
STOP_TIMEOUT = 5
DEFAULT_PORT = 8910
MISSING_TEXT = "Unable to find phantomjs executable."
STOP_TIMEOUT = 5
DEFAULT_PORT = 8910
MISSING_TEXT = "Unable to find phantomjs executable."

attr_reader :uri

def self.executable_path
@executable_path ||= (
@executable_path ||= begin
path = PhantomJS.path
path or raise Error::WebDriverError, MISSING_TEXT
Platform.assert_executable path

path
)
end
end

def self.default_service
new executable_path, PortProber.above(DEFAULT_PORT)
def self.default_service options={}
new executable_path, options
end

def initialize(executable_path, port)
@uri = URI.parse "http://#{Platform.localhost}:#{port}"
def initialize(executable_path, options)
@port = options[:port]
@port ||= PortProber.above(DEFAULT_PORT)

@debugger = options[:debugger]

@debugger_port = options[:debugger_port]
@debugger_port ||= PortProber.above(port + 1) if debugger

@uri = URI.parse "http://#{Platform.localhost}:#{port}"

server_command = [executable_path, "--webdriver=#{port}"]
server_command << "--remote-debugger-port=#{debugger_port}" if debugger

@process = ChildProcess.build(*server_command)
@socket_poller = SocketPoller.new Platform.localhost, port, START_TIMEOUT

@process.io.inherit! if $DEBUG == true
@process.io.inherit! if $DEBUG
end

attr_reader :debugger, :debugger_port, :port

def debugger_uri
URI("http://#{Platform.localhost}:#{debugger_port}")
end

def start
Expand Down Expand Up @@ -67,4 +83,4 @@ def stop

end # PhantomJS
end # WebDriver
end # Service
end # Service