def main(): """Command Line main function.""" parser = optparse.OptionParser() parser.add_option( "-s", "--settings", dest="settings", help="Settings file for mozrunner.", metavar="MOZRUNNER_SETTINGS_FILE" ) parser.add_option( "-n", "--new-profile", dest="new_profile", action="store_true", help="Create fresh profile.", metavar="MOZRUNNER_NEW_PROFILE", ) parser.add_option("-b", "--binary", dest="binary", help="Binary path.", metavar=None) parser.add_option("-d", "--default-profile", dest="default-profile", help="Default profile path.", metavar=None) parser.add_option("-p", "--profile", dest="profile", help="Profile path.", metavar=None) parser.add_option("-w", "--plugins", dest="plugins", help="Plugin paths to install.", metavar=None) (options, args) = parser.parse_args() settings_path = getattr(options, "settings", None) if settings_path is not None: settings_path = os.path.abspath(os.path.expanduser(settings_path)) os.environ[settings_env] = settings_path settings = simplesettings.initialize_settings( global_settings, sys.modules[__name__], local_env_variable=settings_env ) option_overrides = [ ("new_profile", "MOZILLA_CREATE_NEW_PROFILE"), ("binary", "MOZILLA_BINARY"), ("profile", "MOZILLA_PROFILE"), ("default-profile", "MOZILLA_DEFAULT_PROFILE"), ] for opt, override in option_overrides: if getattr(options, opt, None) is not None: settings[override] = getattr(options, opt) moz = get_moz_from_settings(settings) # if len(args) is not 0: # objdir = args.pop(0) # # moz.start() print "Started:", " ".join(moz.command) try: moz.wait() except KeyboardInterrupt: moz.stop() if settings["MOZILLA_CREATE_NEW_PROFILE"]: shutil.rmtree(settings["MOZILLA_PROFILE"]) else: install.clean_prefs_file(os.path.join(settings["MOZILLA_PROFILE"], "prefs.js"))
def get_moz(binary, profile, runner_class=runner.Firefox, cmd_args=[], prefs={}, enable_default_prefs=True, settings=None, create_new_profile=True, plugins=None): """Get the Mozilla object from options, settings dict overrides kwargs""" if settings is None: settings = simplesettings.initialize_settings( global_settings, sys.modules[__name__], local_env_variable=settings_env, ) sys.modules[__name__].settings = settings binary = os.path.abspath(binary) # Handle .app case if binary.endswith('.app'): apppath = binary binary = os.path.abspath( os.path.join(apppath, 'Contents', 'MacOS', 'firefox-bin')) profile = os.path.abspath( os.path.join(apppath, 'Contents', 'MacOS', 'defaults', 'profile')) if settings.get('MOZILLA_CREATE_NEW_PROFILE', create_new_profile): if not settings.has_key('MOZILLA_CREATE_NEW_PROFILE'): settings['MOZILLA_CREATE_NEW_PROFILE'] = create_new_profile settings['MOZILLA_DEFAULT_PROFILE'] = profile if settings['MOZILLA_CREATE_NEW_PROFILE']: if settings['MOZILLA_DEFAULT_PROFILE'] is None: raise Exception('No default or local profile has been set.') install.create_tmp_profile(settings) profile = settings['MOZILLA_PROFILE'] else: settings['MOZILLA_PROFILE'] = profile settings['MOZILLA_CREATE_NEW_PROFILE'] = create_new_profile if settings.get('MOZILLA_PLUGINS', plugins) is not None: if not settings.has_key('MOZILLA_PLUGINS'): settings['MOZILLA_PLUGINS'] = plugins if settings.has_key('MOZILLA_PLUGINS'): install.install_plugins(settings, runner_class) install.set_preferences(profile, prefs, enable_default_prefs) return runner_class(binary, profile, cmd_args=cmd_args, env=settings.get('MOZILLA_ENV', None))
def get_moz( binary, profile, runner_class=runner.Firefox, cmd_args=[], prefs={}, enable_default_prefs=True, settings=None, create_new_profile=True, plugins=None, ): """Get the Mozilla object from options, settings dict overrides kwargs""" if settings is None: settings = simplesettings.initialize_settings( global_settings, sys.modules[__name__], local_env_variable=settings_env ) sys.modules[__name__].settings = settings binary = os.path.abspath(binary) # Handle .app case if binary.endswith(".app"): apppath = binary binary = os.path.abspath(os.path.join(apppath, "Contents", "MacOS", "firefox-bin")) profile = os.path.abspath(os.path.join(apppath, "Contents", "MacOS", "defaults", "profile")) if settings.get("MOZILLA_CREATE_NEW_PROFILE", create_new_profile): if not settings.has_key("MOZILLA_CREATE_NEW_PROFILE"): settings["MOZILLA_CREATE_NEW_PROFILE"] = create_new_profile settings["MOZILLA_DEFAULT_PROFILE"] = profile if settings["MOZILLA_CREATE_NEW_PROFILE"]: if settings["MOZILLA_DEFAULT_PROFILE"] is None: raise Exception("No default or local profile has been set.") install.create_tmp_profile(settings) profile = settings["MOZILLA_PROFILE"] else: settings["MOZILLA_PROFILE"] = profile settings["MOZILLA_CREATE_NEW_PROFILE"] = create_new_profile if settings.get("MOZILLA_PLUGINS", plugins) is not None: if not settings.has_key("MOZILLA_PLUGINS"): settings["MOZILLA_PLUGINS"] = plugins if settings.has_key("MOZILLA_PLUGINS"): install.install_plugins(settings, runner_class) install.set_preferences(profile, prefs, enable_default_prefs) return runner_class(binary, profile, cmd_args=cmd_args, env=settings.get("MOZILLA_ENV", None))
def get_moz_from_settings(settings=None, runner_class=runner.Firefox): """Get Mozilla object from a settings dict. If one is not passed a default settings dict is created.""" if settings is None: settings = simplesettings.initialize_settings( global_settings, sys.modules[__name__], local_env_variable=settings_env ) sys.modules[__name__].settings = settings from windmill.dep import mozrunner mozrunner.settings = settings return get_moz( settings["MOZILLA_BINARY"], settings["MOZILLA_DEFAULT_PROFILE"], prefs=settings["MOZILLA_PREFERENCES"], runner_class=runner_class, settings=settings, enable_default_prefs=settings.get("MOZILLA_ENABLE_DEFAULT_PREFS", True), cmd_args=settings["MOZILLA_CMD_ARGS"], )
def get_moz_from_settings(settings=None, runner_class=runner.Firefox): """Get Mozilla object from a settings dict. If one is not passed a default settings dict is created.""" if settings is None: settings = simplesettings.initialize_settings( global_settings, sys.modules[__name__], local_env_variable=settings_env, ) sys.modules[__name__].settings = settings from windmill.dep import mozrunner mozrunner.settings = settings return get_moz(settings['MOZILLA_BINARY'], settings['MOZILLA_DEFAULT_PROFILE'], prefs=settings['MOZILLA_PREFERENCES'], runner_class=runner_class, settings=settings, enable_default_prefs=settings.get( 'MOZILLA_ENABLE_DEFAULT_PREFS', True), cmd_args=settings['MOZILLA_CMD_ARGS'])
def get_firefox_controller(): """Get the firefox browser object""" from windmill.dep import mozrunner global_settings = mozrunner.global_settings from windmill.dep import simplesettings mozrunner_settings = simplesettings.initialize_settings( global_settings, mozrunner, local_env_variable=mozrunner.settings_env ) for key, value in mozrunner.settings.items(): if not windmill.settings.has_key(key): windmill.settings[key] = value test_url = windmill.get_test_url(windmill.settings["TEST_URL"]) if windmill.settings["INSTALL_FIREBUG"]: windmill.settings["MOZILLA_PLUGINS"] = [ os.path.join(os.path.dirname(__file__), os.path.pardir, "xpi", "firebug-1.5.0.xpi.xpi") ] prop_hash = { "extensions.chromebug.openalways": True, "extensions.chromebug.showIntroduction": False, "general.warnOnAboutConfig": False, "extensions.venkman.enableChromeFilter": False, # Get rid of default browser check "browser.shell.checkDefaultBrowser": False, # Suppress authentication confirmations "network.http.phishy-userpass-length": 255, # Disable pop-up blocking "browser.allowpopups": True, "dom.disable_open_during_load": False, # Open links in new windows (Firefox 2.0) "browser.link.open_external": 2, "browser.link.open_newwindow": 2, # Configure local proxy "network.proxy.http": "127.0.0.1", "network.proxy.http_port": windmill.settings["SERVER_HTTP_PORT"], "network.proxy.no_proxies_on": "", "network.proxy.type": 1, # "network.http.proxy.pipelining" : True, "network.http.max-connections": 10, "network.http.max-connections-per-server": 8, # "network.http.max-persistent-connections-per-proxy": 2, # "network.http.max-persistent-connections-per-server": 2, "network.http.pipelining.maxrequests": 10, # Turn off favicon requests, no need for even more requests "browser.chrome.favicons": False, "startup.homepage_override_url": test_url, "browser.startup.homepage": test_url, "startup.homepage_welcome_url": "", # Disable security warnings "security.warn_submit_insecure": False, "security.warn_submit_insecure.show_once": False, "security.warn_entering_secure": False, "security.warn_entering_secure.show_once": False, "security.warn_entering_weak": False, "security.warn_entering_weak.show_once": False, "security.warn_leaving_secure": False, "security.warn_leaving_secure.show_once": False, "security.warn_viewing_mixed": False, "security.warn_viewing_mixed.show_once": False, # Disable cache "browser.cache.disk.enable": False, "browser.sessionstore.resume_from_crash": False, # self.user_pref('"browser.cache.memory.enable", false') # Disable "do you want to remember this password?" "signon.rememberSignons": False, "dom.max_script_run_time": 100, # Disable OSCP validation, breaks through proxy. "security.OCSP.enabled": 0, # Make the firefox IDE stop showing the location bar "dom.disable_window_open_feature.location": False, "browser.rights.3.shown": True, } if windmill.has_ssl: prop_hash["network.proxy.ssl"] = "127.0.0.1" prop_hash["network.proxy.ssl_port"] = windmill.settings["SERVER_HTTP_PORT"] windmill.settings["MOZILLA_PREFERENCES"].update(prop_hash) windmill.settings["MOZILLA_CMD_ARGS"] = [test_url] controller = mozrunner.get_moz_from_settings(copy.copy(windmill.settings)) # Override cert8.db with one from windmill which has windmill certificate # in it, that way self-signed certificate warning is suppressed. cert8 = resource_string(__name__, "cert8.db") if sys.platform not in ("win32", "cygwin"): f = open(os.path.join(controller.profile, "cert8.db"), "w") else: f = open(os.path.join(controller.profile, "cert8.db"), "wb") f.write(cert8) f.close() windmill.settings["MOZILLA_PROFILE"] = mozrunner.settings["MOZILLA_PROFILE"] return controller
def get_firefox_controller(): """Get the firefox browser object""" from windmill.dep import mozrunner global_settings = mozrunner.global_settings from windmill.dep import simplesettings mozrunner_settings = simplesettings.initialize_settings(global_settings, mozrunner, local_env_variable=mozrunner.settings_env) for key, value in mozrunner.settings.items(): if not windmill.settings.has_key(key): windmill.settings[key] = value test_url = windmill.get_test_url(windmill.settings['TEST_URL']) if windmill.settings['INSTALL_FIREBUG']: windmill.settings['MOZILLA_PLUGINS'] = [os.path.join(os.path.dirname(__file__), os.path.pardir, 'xpi', 'firebug-1.5.0.xpi')] prop_hash = { 'extensions.chromebug.openalways' : True, 'extensions.chromebug.showIntroduction' : False, 'general.warnOnAboutConfig' : False, 'extensions.venkman.enableChromeFilter' : False, # Get rid of default browser check "browser.shell.checkDefaultBrowser": False, # Suppress authentication confirmations "network.http.phishy-userpass-length": 255, # Disable pop-up blocking "browser.allowpopups": True, "dom.disable_open_during_load": False, # Open links in new windows (Firefox 2.0) "browser.link.open_external": 2, "browser.link.open_newwindow": 2, # Configure local proxy "network.proxy.http": '127.0.0.1', "network.proxy.http_port": windmill.settings['SERVER_HTTP_PORT'], "network.proxy.no_proxies_on": "", "network.proxy.type": 1, #"network.http.proxy.pipelining" : True, "network.http.max-connections": 10, "network.http.max-connections-per-server": 8, # "network.http.max-persistent-connections-per-proxy": 2, # "network.http.max-persistent-connections-per-server": 2, "network.http.pipelining.maxrequests": 10, # Turn off favicon requests, no need for even more requests "browser.chrome.favicons": False, "startup.homepage_override_url": test_url, "browser.startup.homepage": test_url, "startup.homepage_welcome_url": "", # Disable security warnings "security.warn_submit_insecure": False, "security.warn_submit_insecure.show_once": False, "security.warn_entering_secure": False, "security.warn_entering_secure.show_once": False, "security.warn_entering_weak": False, "security.warn_entering_weak.show_once": False, "security.warn_leaving_secure": False, "security.warn_leaving_secure.show_once": False, "security.warn_viewing_mixed": False, "security.warn_viewing_mixed.show_once": False, # Disable cache "browser.cache.disk.enable": False, "browser.sessionstore.resume_from_crash": False, # self.user_pref('"browser.cache.memory.enable", false') # Disable "do you want to remember this password?" "signon.rememberSignons": False, "dom.max_script_run_time": 100, # Disable OSCP validation, breaks through proxy. "security.OCSP.enabled":0, #Make the firefox IDE stop showing the location bar "dom.disable_window_open_feature.location":False, "browser.rights.3.shown": True, } if windmill.has_ssl: prop_hash["network.proxy.ssl"] = '127.0.0.1' prop_hash["network.proxy.ssl_port"] = windmill.settings['SERVER_HTTP_PORT'] windmill.settings['MOZILLA_PREFERENCES'].update(prop_hash) windmill.settings['MOZILLA_CMD_ARGS'] = [test_url] controller = mozrunner.get_moz_from_settings(copy.copy(windmill.settings)) # Override cert8.db with one from windmill which has windmill certificate # in it, that way self-signed certificate warning is suppressed. cert8 = resource_string(__name__, 'cert8.db') if sys.platform not in ('win32', 'cygwin',): f = open(os.path.join(controller.profile, 'cert8.db'), 'w') else: f = open(os.path.join(controller.profile, 'cert8.db'), 'wb') f.write(cert8) f.close() windmill.settings['MOZILLA_PROFILE'] = mozrunner.settings['MOZILLA_PROFILE'] return controller
def main(): """Command Line main function.""" parser = optparse.OptionParser() parser.add_option("-s", "--settings", dest="settings", help="Settings file for mozrunner.", metavar="MOZRUNNER_SETTINGS_FILE") parser.add_option("-n", "--new-profile", dest="new_profile", action="store_true", help="Create fresh profile.", metavar="MOZRUNNER_NEW_PROFILE") parser.add_option("-b", "--binary", dest="binary", help="Binary path.", metavar=None) parser.add_option("-d", "--default-profile", dest="default-profile", help="Default profile path.", metavar=None) parser.add_option('-p', "--profile", dest="profile", help="Profile path.", metavar=None) parser.add_option('-w', "--plugins", dest="plugins", help="Plugin paths to install.", metavar=None) (options, args) = parser.parse_args() settings_path = getattr(options, 'settings', None) if settings_path is not None: settings_path = os.path.abspath(os.path.expanduser(settings_path)) os.environ[settings_env] = settings_path settings = simplesettings.initialize_settings( global_settings, sys.modules[__name__], local_env_variable=settings_env) option_overrides = [ ( 'new_profile', 'MOZILLA_CREATE_NEW_PROFILE', ), ( 'binary', 'MOZILLA_BINARY', ), ( 'profile', 'MOZILLA_PROFILE', ), ( 'default-profile', 'MOZILLA_DEFAULT_PROFILE', ), ] for opt, override in option_overrides: if getattr(options, opt, None) is not None: settings[override] = getattr(options, opt) moz = get_moz_from_settings(settings) # if len(args) is not 0: # objdir = args.pop(0) # # moz.start() print 'Started:', ' '.join(moz.command) try: moz.wait() except KeyboardInterrupt: moz.stop() if settings['MOZILLA_CREATE_NEW_PROFILE']: shutil.rmtree(settings['MOZILLA_PROFILE']) else: install.clean_prefs_file( os.path.join(settings['MOZILLA_PROFILE'], 'prefs.js'))