Skip to content

Commit

Permalink
Allow to pass profile name to Firefox::Options.new
Browse files Browse the repository at this point in the history
Closes #7119
  • Loading branch information
p0deje committed Apr 24, 2019
1 parent 4570582 commit 1268298
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
23 changes: 17 additions & 6 deletions rb/lib/selenium/webdriver/firefox/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Options
def initialize(**opts)
@args = Set.new(opts.delete(:args) || [])
@binary = opts.delete(:binary)
@profile = opts.delete(:profile)
@profile = process_profile(opts.delete(:profile))
@log_level = opts.delete(:log_level)
@prefs = opts.delete(:prefs) || {}
@options = opts.delete(:options) || {}
Expand Down Expand Up @@ -123,11 +123,7 @@ def headless!
#

def profile=(profile)
@profile = if profile.is_a?(Profile)
profile
else
Profile.from_name(profile)
end
@profile = process_profile(profile)
end

#
Expand All @@ -145,6 +141,21 @@ def as_json(*)

{KEY => opts}
end

private

def process_profile(profile)
return unless profile

case profile
when Profile
profile
when String
Profile.from_name(profile)
else
raise Error::WebDriverError, "don't know how to handle profile: #{profile.inspect}"
end
end
end # Options
end # Firefox
end # WebDriver
Expand Down
21 changes: 18 additions & 3 deletions rb/spec/unit/selenium/webdriver/firefox/options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,17 @@ module Firefox
expect(opt.binary).to eq('/foo/bar')
end

it 'sets passed profile' do
it 'sets passed new profile' do
profile = Profile.new
opt = Options.new(profile: profile)
expect(opt.profile).to eq(profile)
end

it 'sets passed existing profile' do
profile = Profile.new
expect(Profile).to receive(:from_name).with('foo').and_return(profile)
opt = Options.new(profile: 'foo')
expect(opt.profile).to eq('foo')
expect(opt.profile).to eq(profile)
end

it 'sets passed log level' do
Expand Down Expand Up @@ -72,11 +80,18 @@ module Firefox
end

describe '#profile=' do
it 'sets the profile' do
it 'sets a new profile' do
profile = Profile.new
options.profile = profile
expect(options.profile).to eq(profile)
end

it 'sets an existing profile' do
profile = Profile.new
expect(Profile).to receive(:from_name).with('foo').and_return(profile)
options.profile = 'foo'
expect(options.profile).to eq(profile)
end
end

describe '#headless!' do
Expand Down

0 comments on commit 1268298

Please sign in to comment.