Skip to content

Commit

Permalink
[rb] allow users to direct driver process output (#11964)
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner authored Apr 28, 2023
1 parent 1947771 commit da2e767
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
12 changes: 10 additions & 2 deletions rb/lib/selenium/webdriver/common/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def driver_path=(path)
end
end

attr_accessor :host, :executable_path, :port, :args
attr_accessor :host, :executable_path, :port, :log, :args
alias extra_args args

#
Expand All @@ -66,13 +66,21 @@ def driver_path=(path)
# @api private
#

def initialize(path: nil, port: nil, args: nil)
def initialize(path: nil, port: nil, log: nil, args: nil)
port ||= self.class::DEFAULT_PORT
args ||= []

@executable_path = path
@host = Platform.localhost
@port = Integer(port)
@log = case log
when :stdout
$stdout
when :stderr
$stderr
else
log
end

@args = args.is_a?(Hash) ? extract_service_args(args) : args

Expand Down
4 changes: 3 additions & 1 deletion rb/lib/selenium/webdriver/common/service_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def initialize(config)
@host = Platform.localhost
@port = config.port
@extra_args = config.args
@io = config.log
@shutdown_supported = config.shutdown_supported

raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
Expand Down Expand Up @@ -79,7 +80,8 @@ def uri
def build_process(*command)
WebDriver.logger.debug("Executing Process #{command}")
@process = ChildProcess.build(*command)
@process.io = WebDriver.logger.io if WebDriver.logger.debug?
@process.io = @io
@process.io ||= WebDriver.logger.io if WebDriver.logger.debug?

@process
end
Expand Down
12 changes: 12 additions & 0 deletions rb/spec/unit/selenium/webdriver/chrome/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,18 @@ module Chrome
expect(service.extra_args).to be_empty
end

it 'uses sets log path to stdout' do
service = described_class.chrome(log: :stdout)

expect(service.log).to eq $stdout
end

it 'uses sets log path to stderr' do
service = described_class.chrome(log: :stderr)

expect(service.log).to eq $stderr
end

it 'uses provided args' do
allow(Platform).to receive(:find_binary).and_return(service_path)

Expand Down

0 comments on commit da2e767

Please sign in to comment.