Starting mozrunnerIf you wish to start the local firefox with the default mozrunner settings you can simply run. import mozrunner
moz = mozrunner.get_moz_from_settings()
moz.start()
moz.stop() If you'd like to run a different binary and/or default profile; import mozrunner
moz = mozrunner.get_moz('/path/to/binary', '/path/to/default/profile')
moz.start()
moz.stop()This is this simplest case where you simply want to start and stop a particular binary with the default mozrunner settings. Just using the get_moz method you can set a few other options. This is what the full default get_moz call looks like. moz = mozrunner.get_moz('/path/to/binary', '/path/to/default/profile', runner_class=mozrunner.runner.Firefox, cmd_args=[], prefs={},
enable_default_prefs=True, settings=None, create_new_profile=True,
plugins=None)For more advanced cases you'll want to start using a the settings system. SettingsLaunching Mozilla applications can be quite a task. There are a lot of different options to think about when starting any given Mozilla application and the mozrunner library supports these options through a wide variety of module settings. At the very least mozrunner needs to have the following settings; - The location of the Mozilla binary to launch
- The location of the Mozilla DEFAULT profile (a clean profile mozilla uses to create new profiles)
These settings are referred to as MOZILLA_BINARY and MOZILLA_DEFAULT_PROFILE. If you are launching Firefox from any number of default install locations mozrunner will find these for you and no configuration is necessary, but if not then you'll need to set these by hand. When using a local settings fileMany applications that use mozrunner allow you to set a local settings file. Here are some example options that can be set for adding additional preferences, extensions, and command line options. MOZILLA_PREFERENCES = {"a.preference.i.care.about":True}
MOZILLA_CMD_ARGS = ['-myflag']
MOZILLA_PLUGINS = ['/path/to/unzipped/extension', '/path/to/zipped/extension.xpi']MOZILLA_PREFERENCES translates the dictionary in to javascript calls to set those preferences. This setting sets these preferences in addition to some other default preferences that are set so you don't need to worry about overwriting any other tools preferences. MOZILLA_CMD_ARGS adds these arguments to the default set of arguments for launching the application with a particular profile. MOZILLA_PLUGINS is a list of extensions to install which can install unzipped extension directories or regular .xpi zipped extensions. This setting is used by a lot of other tools (jsbridge, mozmill) to get their extension installed when running from Python, if you're adding to it you may need to add their extensions by hand if you're overriding the setting. When embeddingMozrunner uses the simplesettings library, which mashes a local settings file over a large default settings module and returns a dictionary. The easiest way for you to override a bunch of settings is simply to overwrite them in mozrunner.global_settings and then run the get_moz_from_settings(). The following example changes the default prefs mozrunner adds to launch. import mozrunner
from mozrunner import global_settings
global_settings.MOZILLA_DEFAULT_PREFS = {'extensions.update.notifyUser' : False,
'browser.shell.checkDefaultBrowser' : False,
'browser.tabs.warnOnClose' : False,
'browser.warnOnQuit': False,
'browser.sessionstore.resume_from_crash': False,
}
moz = mozrunner.get_moz_from_settings()
|