Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] allow users to direct driver process output #11964

Merged
merged 1 commit into from
Apr 28, 2023
Merged
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
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