diff --git a/src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py b/src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py index ee357f764..6fa9d0eb8 100644 --- a/src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py +++ b/src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py @@ -63,7 +63,7 @@ class WebDriverCreator: def __init__(self, log_dir): self.log_dir = log_dir self.selenium_options = SeleniumOptions() - self.selenium_service = SeleniumService() + #self.selenium_service = SeleniumService() def create_driver( self, @@ -80,7 +80,6 @@ def create_driver( desired_capabilities = self._parse_capabilities(desired_capabilities, browser) service_log_path = self._get_log_path(service_log_path) options = self.selenium_options.create(self.browser_names.get(browser), options) - service = self.selenium_service.create(self.browser_names.get(browser), service_log_path, executable_path) if service_log_path: logger.info(f"Browser driver log file created to: {service_log_path}") self._create_directory(service_log_path) @@ -100,7 +99,6 @@ def create_driver( desired_capabilities, remote_url, options=options, - # service=service, service_log_path=service_log_path, executable_path=executable_path, ) @@ -154,7 +152,6 @@ def create_chrome( return self._remote(desired_capabilities, remote_url, options=options) if not executable_path: executable_path = self._get_executable_path(webdriver.chrome.service.Service) - # service = self.selenium_service.create('chrome', executable_path=executable_path, service_log_path=service_log_path) service = ChromeService(executable_path=executable_path, log_path=service_log_path) return webdriver.Chrome( options=options, @@ -194,6 +191,15 @@ def create_firefox( executable_path="geckodriver", ): profile = self._get_ff_profile(ff_profile_dir) + if not options: + options = webdriver.FirefoxOptions() + options.profile = profile # <- moved to here :) + + # Something I question here is/was whether or not we should create the option, not + # only on whether it exists, but if there is a profile provided. That is previously we just pass + # None along as options if there were none. But now no matter what we create an Options class so + # as to attach the profile to it. If there a scenario in which we don't want to do this??? + if remote_url: default_caps = webdriver.DesiredCapabilities.FIREFOX.copy() desired_capabilities = self._remote_capabilities_resolver( @@ -205,7 +211,7 @@ def create_firefox( ) if not executable_path: executable_path = self._get_executable_path(webdriver.firefox.service.Service) - service = self.selenium_service.create('firefox', executable_path=executable_path, service_log_path=service_log_path) + service = FirefoxService(executable_path=executable_path, log_path=service_log_path) return webdriver.Firefox( options=options, #firefox_profile=profile, # need to move @@ -231,7 +237,7 @@ def _get_ff_profile(self, ff_profile_dir): else: setattr(ff_profile, key, *option[key]) return ff_profile - + @property def _geckodriver_log(self): log_file = self._get_log_path( @@ -277,7 +283,7 @@ def create_ie( return self._remote(desired_capabilities, remote_url, options=options) if not executable_path: executable_path = self._get_executable_path(webdriver.ie.service.Service) - service = self.selenium_service.create('ie', executable_path=executable_path, service_log_path=service_log_path) + service = IeService(executable_path=executable_path, log_path=service_log_path) return webdriver.Ie( options=options, service=service, @@ -304,7 +310,7 @@ def create_edge( return self._remote(desired_capabilities, remote_url) if not executable_path: executable_path = self._get_executable_path(webdriver.edge.service.Service) - service = self.selenium_service.create('edge', executable_path=executable_path, service_log_path=service_log_path) + service = EdgeService(executable_path=executable_path, log_path=service_log_path) return webdriver.Edge( options=options, service=service, @@ -327,7 +333,7 @@ def create_safari( return self._remote(desired_capabilities, remote_url) if not executable_path: executable_path = self._get_executable_path(webdriver.Safari) - service = self.selenium_service.create('safari', executable_path=executable_path, service_log_path=service_log_path) + service = SafariService(executable_path=executable_path, log_path=service_log_path) return webdriver.Safari(options=options, service=service) def create_phantomjs( @@ -435,10 +441,10 @@ def _remote(self, desired_capabilities, remote_url, profile_dir=None, options=No file_detector = self._get_sl_file_detector() return webdriver.Remote( command_executor=remote_url, - browser_profile=profile_dir, + # browser_profile=profile_dir, options=options, file_detector=file_detector, - **desired_capabilities, + # **desired_capabilities, ) def _get_sl_file_detector(self): @@ -547,52 +553,53 @@ def _get_index(self, alias_or_index): except ValueError: return None -class SeleniumService: - """ executable_path: str = DEFAULT_EXECUTABLE_PATH, - port: int = 0, - log_path: typing.Optional[str] = None, - service_args: typing.Optional[typing.List[str]] = None, - env: typing.Optional[typing.Mapping[str, str]] = None, - **kwargs, - - executable_path = None, port, service_log_path, service_args, env - """ - def create(self, browser, - executable_path=None, - port=0, - service_log_path=None, - service_args=None, - env=None, - start_error_message=None, # chromium, chrome, edge - quiet=False, reuse_service=False, # safari - ): - selenium_service = self._import_service(browser) - # chrome, chromium, firefox, edge - if any(chromium_based in browser.lower() for chromium_based in ('chromium', 'chrome', 'edge')): - service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, - service_args=service_args,env=env,start_error_message=start_error_message - ) - return service - elif 'safari' in browser.lower(): - service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, - service_args=service_args,env=env,quiet=quiet,reuse_service=reuse_service - ) - return service - elif 'firefox' in browser.lower(): - service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, - service_args=service_args,env=env - ) - return service - else: - service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, - service_args=service_args,env=env - ) - return service - - def _import_service(self, browser): - browser = browser.replace("headless_", "", 1) - service = importlib.import_module(f"selenium.webdriver.{browser}.service") - return service.Service +# Temporarily removing as not going to use with initial 4.10.0 hotfixq +# class SeleniumService: +# """ executable_path: str = DEFAULT_EXECUTABLE_PATH, +# port: int = 0, +# log_path: typing.Optional[str] = None, +# service_args: typing.Optional[typing.List[str]] = None, +# env: typing.Optional[typing.Mapping[str, str]] = None, +# **kwargs, + +# executable_path = None, port, service_log_path, service_args, env +# """ +# def create(self, browser, +# executable_path=None, +# port=0, +# service_log_path=None, +# service_args=None, +# env=None, +# start_error_message=None, # chromium, chrome, edge +# quiet=False, reuse_service=False, # safari +# ): +# selenium_service = self._import_service(browser) +# # chrome, chromium, firefox, edge +# if any(chromium_based in browser.lower() for chromium_based in ('chromium', 'chrome', 'edge')): +# service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, +# service_args=service_args,env=env,start_error_message=start_error_message +# ) +# return service +# elif 'safari' in browser.lower(): +# service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, +# service_args=service_args,env=env,quiet=quiet,reuse_service=reuse_service +# ) +# return service +# elif 'firefox' in browser.lower(): +# service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, +# service_args=service_args,env=env +# ) +# return service +# else: +# service = selenium_service(executable_path=executable_path, port=port,log_path=service_log_path, +# service_args=service_args,env=env +# ) +# return service + +# def _import_service(self, browser): +# browser = browser.replace("headless_", "", 1) +# service = importlib.import_module(f"selenium.webdriver.{browser}.service") +# return service.Service class SeleniumOptions: def create(self, browser, options):