From da2e767ebe307c5221ef3fb20b3dbc404fc19ff7 Mon Sep 17 00:00:00 2001 From: Titus Fortner Date: Fri, 28 Apr 2023 12:47:53 -0500 Subject: [PATCH] [rb] allow users to direct driver process output (#11964) --- rb/lib/selenium/webdriver/common/service.rb | 12 ++++++++++-- rb/lib/selenium/webdriver/common/service_manager.rb | 4 +++- .../unit/selenium/webdriver/chrome/service_spec.rb | 12 ++++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/service.rb b/rb/lib/selenium/webdriver/common/service.rb index 2623a9364559b..e4df4910bda91 100644 --- a/rb/lib/selenium/webdriver/common/service.rb +++ b/rb/lib/selenium/webdriver/common/service.rb @@ -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 # @@ -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 diff --git a/rb/lib/selenium/webdriver/common/service_manager.rb b/rb/lib/selenium/webdriver/common/service_manager.rb index 640b1ff010876..963cf6903a6c6 100644 --- a/rb/lib/selenium/webdriver/common/service_manager.rb +++ b/rb/lib/selenium/webdriver/common/service_manager.rb @@ -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 @@ -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 diff --git a/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb index 2f7f67a9f0e8d..c3cb3c0e5f0e9 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/service_spec.rb @@ -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)