Skip to content

Instantly share code, notes, and snippets.

@Snarp
Last active September 8, 2021 18:15
Show Gist options
  • Save Snarp/67f3c8f846f0f4c1cd4641937040595e to your computer and use it in GitHub Desktop.
Save Snarp/67f3c8f846f0f4c1cd4641937040595e to your computer and use it in GitHub Desktop.
Initializes an instance of Watir::Browser using a specified Firefox profile.
require 'watir'
require 'webdrivers/geckodriver'
# Source:
# <https://github.com/SeleniumHQ/selenium/issues/7796#issuecomment-555833317>
# Find your Firefox profile's directory by opening 'about:support' in the
# browser and scrolling down to the 'Profile Directory' field.
#
# Alternately, to create a new profile, go to 'about:profiles' and click
# "Create a new profile". When it is created, copy the "Root Directory" path.
@firefox_profile_dir = 'PROFILE PATH GOES HERE'
def init_browser
profile = @firefox_profile_dir
service = Selenium::WebDriver::Service.firefox(args: {marionette_port: 2828})
options = Selenium::WebDriver::Firefox::Options.new(args: ["-profile", profile])
driver = Selenium::WebDriver.for(:firefox, service: service, options: options)
@browser = Watir::Browser.new(driver)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment