Example 1: profile.set_preference('capability.policy.maonoscript.sites','
def _firefox_profile():
"""Configure the Firefox profile, respecting FIREFOX_PROFILE_PATH if set"""
profile_dir = os.environ.get(FIREFOX_PROFILE_ENV_VAR)
if profile_dir:
LOGGER.info("Using firefox profile: %s", profile_dir)
try:
firefox_profile = webdriver.FirefoxProfile(profile_dir)
except OSError as err:
if err.errno == errno.ENOENT:
raise BrowserConfigError(
"Firefox profile directory {env_var}={profile_dir} does not exist".format(
env_var=FIREFOX_PROFILE_ENV_VAR, profile_dir=profile_dir))
elif err.errno == errno.EACCES:
raise BrowserConfigError(
"Firefox profile directory {env_var}={profile_dir} has incorrect permissions. It must be \
readable and executable.".format(env_var=FIREFOX_PROFILE_ENV_VAR, profile_dir=profile_dir))
else:
raise BrowserConfigError(
"Problem with firefox profile directory {env_var}={profile_dir}: {msg}"
.format(env_var=FIREFOX_PROFILE_ENV_VAR, profile_dir=profile_dir, msg=str(err)))
else:
LOGGER.info("Using default firefox profile")
firefox_profile = webdriver.FirefoxProfile()
firefox_profile.set_preference('media.navigator.permission.disabled', True)
firefox_profile.set_preference('browser.startup.homepage', 'about:blank')
firefox_profile.set_preference('startup.homepage_welcome_url', 'about:blank')
firefox_profile.set_preference('startup.homepage_welcome_url.additional', 'about:blank')
for function in FIREFOX_PROFILE_CUSTOMIZERS:
function(firefox_profile)
return firefox_profile
Example 2: profile.set_preference('capability.policy.maonoscript.sites','
def fetch_adblockplus_list(output_directory, wait_time=20):
""" Saves an updated AdBlock Plus list to the specified directory.
<output_directory> - The directory to save lists to. Will be created if it
does not already exist.
"""
output_directory = os.path.expanduser(output_directory)
display = Display(visible=0)
display.start()
root_dir = os.path.dirname(__file__)
fb = FirefoxBinary(os.path.join(root_dir,'../firefox-bin/firefox'))
fp = webdriver.FirefoxProfile()
browser_path = fp.path + '/'
fp.add_extension(extension=os.path.join(root_dir,'DeployBrowsers/firefox_extensions/adblock_plus-2.7.xpi'))
fp.set_preference('extensions.adblockplus.subscriptions_exceptionsurl', '')
fp.set_preference('extensions.adblockplus.subscriptions_listurl', '')
fp.set_preference('extensions.adblockplus.subscriptions_fallbackurl', '')
fp.set_preference('extensions.adblockplus.subscriptions_antiadblockurl', '')
fp.set_preference('extensions.adblockplus.suppress_first_run_page', True)
fp.set_preference('extensions.adblockplus.notificationurl', '')
fp.set_preference('extensions.adblockplus.please_kill_startup_performance', True)
print "Starting webdriver with AdBlockPlus activated"
driver = webdriver.Firefox(firefox_profile = fp, firefox_binary = fb)
print "Sleeping %i seconds to give the list time to download" % wait_time
time.sleep(wait_time)
if not os.path.isdir(output_directory):
print "Output directory %s does not exist, creating." % output_directory
os.makedirs(output_directory)
print "Copying blocklists to %s" % output_directory
try:
shutil.copy(browser_path+'adblockplus/patterns.ini', output_directory)
shutil.copy(browser_path+'adblockplus/elemhide.css', output_directory)
finally:
driver.close()
display.stop()
Example 3: profile.set_preference('capability.policy.maonoscript.sites','
def init_browser(br_type, cmd_args=""):
if br_type is 'firefox':
fp = webdriver.FirefoxProfile()
return webdriver.Firefox(firefox_profile=fp)
else:
ch = webdriver.ChromeOptions()
ch.binary_location = CHROME_MOD_BINARY
for cmd_arg in cmd_args:
if cmd_arg:
ch.add_argument(cmd_arg)
return webdriver.Chrome(executable_path=CHROME_DRIVER_BINARY,
chrome_options=ch)
Example 4: profile.set_preference('capability.policy.maonoscript.sites','
@fc.timing
def setup_profile(self, firebug=True, netexport=True):
"""
Setup the profile for firefox
:param firebug: whether add firebug extension
:param netexport: whether add netexport extension
:return: a firefox profile object
"""
profile = webdriver.FirefoxProfile()
profile.set_preference("app.update.enabled", False)
if firebug:
profile.add_extension(os.path.join(self.cur_path, 'extensions/firebug-2.0.8.xpi'))
profile.set_preference("extensions.firebug.currentVersion", "2.0.8")
profile.set_preference("extensions.firebug.allPagesActivation", "on")
profile.set_preference("extensions.firebug.defaultPanelName", "net")
profile.set_preference("extensions.firebug.net.enableSites", True)
profile.set_preference("extensions.firebug.delayLoad", False)
profile.set_preference("extensions.firebug.onByDefault", True)
profile.set_preference("extensions.firebug.showFirstRunPage", False)
profile.set_preference("extensions.firebug.net.defaultPersist", True)
if netexport:
har_path = os.path.join(self.cur_path, "har")
if not os.path.exists(har_path):
os.mkdir(har_path)
profile.add_extension(os.path.join(self.cur_path, 'extensions/netExport-0.9b7.xpi'))
profile.set_preference("extensions.firebug.DBG_NETEXPORT", True)
profile.set_preference("extensions.firebug.netexport.alwaysEnableAutoExport", True)
profile.set_preference("extensions.firebug.netexport.defaultLogDir", har_path)
profile.set_preference("extensions.firebug.netexport.includeResponseBodies", True)
return profile