Last modified: 2014-10-19 17:43:55 UTC
Created attachment 14861 [details] 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