Skip to content

Commit

Permalink
[rb] implement Firefox profile functionality for geckodriver
Browse files Browse the repository at this point in the history
Signed-off-by: Titus Fortner <titus.fortner@gmail.com>
  • Loading branch information
lmtierney authored and titusfortner committed Dec 21, 2016
1 parent e0a54f8 commit d4f142f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion rb/build.desc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ ruby_library(name = "firefox",
"lib/selenium/webdriver/firefox.rb"
],
resources = [
{ "//javascript/webdriver/atoms:getAttribute": "rb/lib/selenium/webdriver/atoms/getAttribute.js"}
{ "//javascript/webdriver/atoms:getAttribute": "rb/lib/selenium/webdriver/atoms/getAttribute.js"},
{ "//javascript/firefox-driver:webdriver_prefs" : "rb/lib/selenium/webdriver/firefox/extension/prefs.json" }
],
deps = [":common"]
)
Expand Down
4 changes: 0 additions & 4 deletions rb/lib/selenium/webdriver/firefox/launcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ def connect_until_stable
def fetch_profile
if @profile_name
@profile = Profile.from_name @profile_name

unless @profile
raise Error::WebDriverError, "unable to find profile named: #{@profile_name.inspect}"
end
else
@profile = Profile.new
end
Expand Down
9 changes: 8 additions & 1 deletion rb/lib/selenium/webdriver/firefox/profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ def ini
end

def from_name(name)
ini[name]
profile = ini[name]

raise Error::WebDriverError, "unable to find profile named: #{name.inspect}" unless profile
profile
end

def default_preferences
Expand Down Expand Up @@ -193,6 +196,10 @@ def proxy=(proxy)
proxy
end

def encoded
Zipper.zip(layout_on_disk)
end

private

def set_manual_proxy_preference(key, value)
Expand Down
5 changes: 2 additions & 3 deletions rb/lib/selenium/webdriver/firefox/profiles_ini.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ def parse
is_relative = Regexp.last_match(1).strip == '1'
when /^Path=(.+)$/
path = Regexp.last_match(1).strip
p = path_for(name, is_relative, path)
@profile_paths[name] = p if p
end
end

p = path_for(name, is_relative, path)
@profile_paths[name] = p if p
end

def path_for(name, is_relative, path)
Expand Down
7 changes: 7 additions & 0 deletions rb/lib/selenium/webdriver/firefox/w3c_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ def create_capabilities(opts)
caps = opts.delete(:desired_capabilities) || Remote::W3CCapabilities.firefox
firefox_options_caps = caps[:firefox_options] || {}
caps[:firefox_options] = firefox_options_caps.merge(opts[:firefox_options] || {})
if opts.key?(:profile)
profile = opts.delete(:profile)
unless profile.is_a?(Profile)
profile = Profile.from_name(profile)
end
caps[:firefox_options][:profile] = profile.encoded
end

Binary.path = caps[:firefox_options][:binary] if caps[:firefox_options].key?(:binary)
caps
Expand Down

0 comments on commit d4f142f

Please sign in to comment.