From 40d59c44f8488ab6445b626637bfb3135cbbfd56 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Wed, 18 May 2016 11:44:43 +0100 Subject: [PATCH] Clean up Firefox WebDriver constructor --- py/selenium/webdriver/firefox/webdriver.py | 42 ++++++---------------- 1 file changed, 10 insertions(+), 32 deletions(-) diff --git a/py/selenium/webdriver/firefox/webdriver.py b/py/selenium/webdriver/firefox/webdriver.py index 1a73f11da8a81..80018bce6e425 100644 --- a/py/selenium/webdriver/firefox/webdriver.py +++ b/py/selenium/webdriver/firefox/webdriver.py @@ -47,38 +47,22 @@ class WebDriver(RemoteWebDriver): def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30, capabilities=None, proxy=None, executable_path="wires", firefox_options=None): - self.profile = firefox_profile - self.binary = firefox_binary - if firefox_options is None: + capabilities = capabilities or DesiredCapabilities.FIREFOX.copy() - if self.profile is None: - self.profile = FirefoxProfile() + self.profile = firefox_profile or FirefoxProfile() + self.profile.native_events_enabled = ( + self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled) - self.profile.native_events_enabled = ( - self.NATIVE_EVENTS_ALLOWED and self.profile.native_events_enabled) + self.binary = firefox_binary or capabilities.get("binary", FirefoxBinary()) - if capabilities is None: - capabilities = DesiredCapabilities.FIREFOX - - if self.binary is None: - self.binary = capabilities.get("binary") or FirefoxBinary() - - firefox_options = Options() - firefox_options.binary_location = self.binary if isinstance(self.binary, basestring) else self.binary._get_firefox_start_cmd() - firefox_options.profile = self.profile - - if capabilities is None: - capabilities = firefox_options.to_capabilities() - else: - capabilities.update(firefox_options.to_capabilities()) + self.options = firefox_options or Options() + self.options.binary_location = self.binary if isinstance(self.binary, basestring) else self.binary._get_firefox_start_cmd() + self.options.profile = self.profile + capabilities.update(self.options.to_capabilities()) # marionette if capabilities.get("marionette"): - self.binary = firefox_options.binary_location - if isinstance(firefox_options.binary_location, FirefoxBinary): - self.binary = firefox_options.binary_location._get_firefox_start_cmd() - - self.service = Service(executable_path, firefox_binary=self.binary) + self.service = Service(executable_path, firefox_binary=self.options.binary_location) self.service.start() executor = FirefoxRemoteConnection( @@ -93,12 +77,6 @@ def __init__(self, firefox_profile=None, firefox_binary=None, timeout=30, if proxy is not None: proxy.add_to_capabilities(capabilities) - if self.binary is None: - self.binary = firefox_options.binary_location or FirefoxBinary() - - if self.profile is None: - self.profile = firefox_options.profile or FirefoxProfile() - executor = ExtensionConnection("127.0.0.1", self.profile, self.binary, timeout) RemoteWebDriver.__init__(self,