Skip to content

Commit

Permalink
[rb] setting log path in Chromium needs to pass an argument instead o…
Browse files Browse the repository at this point in the history
…f piping process

Performance Logging can not be used without enabling logging with --log-path
  • Loading branch information
titusfortner committed Sep 17, 2023
1 parent 84457df commit f116bac
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 6 deletions.
7 changes: 7 additions & 0 deletions rb/lib/selenium/webdriver/chrome/service.rb
Expand Up @@ -24,6 +24,13 @@ class Service < WebDriver::Service
DEFAULT_PORT = 9515
EXECUTABLE = 'chromedriver'
SHUTDOWN_SUPPORTED = true

def log
return @log unless @log.is_a? String

@args += ['--log-path', @log]
@log = nil
end
end # Service
end # Chrome
end # WebDriver
Expand Down
2 changes: 1 addition & 1 deletion rb/lib/selenium/webdriver/common/service_manager.rb
Expand Up @@ -40,8 +40,8 @@ def initialize(config)
@executable_path = config.executable_path
@host = Platform.localhost
@port = config.port
@extra_args = config.args
@io = config.log
@extra_args = config.args
@shutdown_supported = config.shutdown_supported

raise Error::WebDriverError, "invalid port: #{@port}" if @port < 1
Expand Down
7 changes: 7 additions & 0 deletions rb/lib/selenium/webdriver/edge/service.rb
Expand Up @@ -24,6 +24,13 @@ class Service < WebDriver::Service
DEFAULT_PORT = 9515
EXECUTABLE = 'msedgedriver'
SHUTDOWN_SUPPORTED = true

def log
return @log unless @log.is_a? String

@args += ['--log-path', @log]
@log = nil
end
end # Service
end # Edge
end # WebDriver
Expand Down
17 changes: 12 additions & 5 deletions rb/spec/unit/selenium/webdriver/chrome/service_spec.rb
Expand Up @@ -33,7 +33,7 @@ module Chrome
after { described_class.driver_path = nil }

it 'uses nil path and default port' do
service = described_class.chrome
service = described_class.new

expect(service.port).to eq Service::DEFAULT_PORT
expect(service.host).to eq Platform.localhost
Expand All @@ -44,7 +44,7 @@ module Chrome
path = 'foo'
port = 5678

service = described_class.chrome(path: path, port: port)
service = described_class.new(path: path, port: port)

expect(service.executable_path).to eq path
expect(service.port).to eq port
Expand All @@ -58,19 +58,26 @@ module Chrome
end

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

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

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

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

it 'setting log output as a file converts to argument' do
service = described_class.new(log: '/path/to/log.txt')

expect(service.log).to be_nil
expect(service.args).to eq ['--log-path', '/path/to/log.txt']
end

it 'uses provided args' do
service = described_class.chrome(args: ['--foo', '--bar'])
service = described_class.new(args: ['--foo', '--bar'])

expect(service.extra_args).to eq ['--foo', '--bar']
end
Expand Down
26 changes: 26 additions & 0 deletions rb/spec/unit/selenium/webdriver/edge/service_spec.rb
Expand Up @@ -56,6 +56,25 @@ module Edge
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 'setting log output as a file converts to argument' do
service = described_class.chrome(log: '/path/to/log.txt')

expect(service.log).to be_nil
expect(service.args).to eq ['--log-path', '/path/to/log.txt']
end

it 'uses provided args' do
service = described_class.new(args: ['--foo', '--bar'])

Expand Down Expand Up @@ -106,6 +125,13 @@ module Edge
driver.new(service: service)
expect(described_class).not_to have_received(:new)
end

it 'setting log output as a file converts to argument' do
service = described_class.chrome(log: '/path/to/log.txt')

expect(service.log).to be_nil
expect(service.args).to eq ['--log-path', '/path/to/log.txt']
end
end
end
end # Edge
Expand Down
18 changes: 18 additions & 0 deletions rb/spec/unit/selenium/webdriver/firefox/service_spec.rb
Expand Up @@ -54,6 +54,24 @@ module Firefox
expect(service.extra_args).to be_empty
end

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

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

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

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

it 'sets log path as file location' do
service = described_class.new(log: '/path/to/log.txt')

expect(service.log).to eq '/path/to/log.txt'
end

it 'uses provided args' do
service = described_class.new(args: ['--foo', '--bar'])

Expand Down
18 changes: 18 additions & 0 deletions rb/spec/unit/selenium/webdriver/ie/service_spec.rb
Expand Up @@ -55,6 +55,24 @@ module IE
expect(service.extra_args).to be_empty
end

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

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

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

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

it 'sets log path as file location' do
service = described_class.new(log: '/path/to/log.txt')

expect(service.log).to eq '/path/to/log.txt'
end

it 'uses provided args' do
service = described_class.new(args: ['--foo', '--bar'])

Expand Down

0 comments on commit f116bac

Please sign in to comment.