Page MenuHomePhabricator

make it possible to launch Firefox (and/or Chrome) with a custom profile
Closed, ResolvedPublic

Description

from https://git.wikimedia.org/tree/mediawiki%2Fextensions%2FMobileFrontend/1f24f2429471925fbb52324293acbd7599aa5ec2/tests%2Fbrowser%2Ffeatures%2Fsupport

From time to time it is useful to override default settings for Firefox in a browser test. The way to do this is to point Firefox at a custom Profile when the browser starts. This custom profile takes the form of a local SQLite file that Firefox will read upon starting.

In particular, it could be useful to allow access to the browser's geolocation information without having to manually answer the browser query.

Jeff Hall and I spiked this in early 2014 but never got it completely working. Our spike code was in the MobileFrontend env.rb file:

if user_agent =="default" && !ENV["NEARBY_FIREFOX"]
  browser = Watir::Browser.new browser_label
else
  if browser_label == :firefox && !ENV["NEARBY_FIREFOX"]
    profile = Selenium::WebDriver::Firefox::Profile.new
    profile["general.useragent.override"] = user_agent
    browser = Watir::Browser.new browser_label, :profile => profile
  else
    if ENV["NEARBY_FIREFOX"]
      permissions_file = "./features/support/permissions.sqlite"
      if RUBY_PLATFORM =~ /darwin/
        firefox_executable = "/Applications/Firefox.app/Contents/MacOS/firefox"
      elsif RUBY_PLATFORM =~ /linux/
        firefox_executable = '/usr/bin/firefox'
      else
        puts 'Cannot identify local OS, so cannot locate Firefox executable!'
      end
      profile_path = ("/tmp/NearbyProfile/")
      Dir.mkdir(profile_path) unless File.exists?(profile_path)
      system(firefox_executable + " -CreateProfile 'NearbyProfile " + profile_path + "'")
      system("cp " + permissions_file + " " + profile_path)
      browser = Watir::Browser.new :firefox, :profile => 'NearbyProfile'
    else
      raise "Changing user agent is currently supported only for Firefox!"
    end
  end
end

Version: unspecified
Severity: enhancement

Attached:

Details

Reference
bz62839

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 3:03 AM
bzimport set Reference to bz62839.
bzimport added a subscriber: Unknown Object (MLST).

As far as I remember, @dduvall said this is implemented in mediawiki_selenium 1.x. @dduvall, please reopen the task if I have misunderstood you.