Skip to content

Commit

Permalink
Updated browser creator arguments for Chrome, Firefox, Edge and IE
Browse files Browse the repository at this point in the history
Selenium 4.10.0 removed the deprecated arguments to the various borwser
creation classes. This starts to move to the newer version.

There are a few things still to do
- Fix the unit tests as I know these are failing. This is in progress.
- Add in the firefox_profile argument for Firefox
- Safari has not only a similar issue, the creation code is a bit behind
  in that options are now allowed as of v4.1.3/v4.1.4
- [.. add I recall something else but can't remember at the moment..]
  • Loading branch information
emanlove committed Jun 10, 2023
1 parent 3560c5f commit 2c1575b
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions src/SeleniumLibrary/keywords/webdrivertools/webdrivertools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
from selenium import webdriver
from selenium.webdriver import FirefoxProfile

from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.ie.service import Service as IeService

from SeleniumLibrary.keywords.webdrivertools.sl_file_detector import (
SelLibLocalFileDetector,
)
Expand Down Expand Up @@ -144,12 +149,11 @@ def create_chrome(
)
return self._remote(desired_capabilities, remote_url, options=options)
if not executable_path:
executable_path = self._get_executable_path(webdriver.Chrome)
executable_path = self._get_executable_path(webdriver.chrome.service.Service)
service = ChromeService(executable_path=executable_path, log_path=service_log_path)
return webdriver.Chrome(
options=options,
service_log_path=service_log_path,
executable_path=executable_path,
**desired_capabilities,
service=service,
)

def create_headless_chrome(
Expand Down Expand Up @@ -195,13 +199,13 @@ def create_firefox(
service_log_path if service_log_path else self._geckodriver_log
)
if not executable_path:
executable_path = self._get_executable_path(webdriver.Firefox)
executable_path = self._get_executable_path(webdriver.firefox.service.Service)
service = FirefoxService(executable_path=executable_path, log_path=service_log_path)
return webdriver.Firefox(
options=options,
firefox_profile=profile,
service_log_path=service_log_path,
executable_path=executable_path,
**desired_capabilities,
#firefox_profile=profile, # need to move
service=service,
#**desired_capabilities,
)

def _get_ff_profile(self, ff_profile_dir):
Expand Down Expand Up @@ -267,12 +271,12 @@ def create_ie(
)
return self._remote(desired_capabilities, remote_url, options=options)
if not executable_path:
executable_path = self._get_executable_path(webdriver.Ie)
executable_path = self._get_executable_path(webdriver.ie.service.Service)
service = IeService(executable_path=executable_path, log_path=service_log_path)
return webdriver.Ie(
options=options,
service_log_path=service_log_path,
executable_path=executable_path,
**desired_capabilities,
service=service,
#**desired_capabilities,
)

def _has_options(self, web_driver):
Expand All @@ -294,20 +298,12 @@ def create_edge(
)
return self._remote(desired_capabilities, remote_url)
if not executable_path:
executable_path = self._get_executable_path(webdriver.Edge)
if self._has_options(webdriver.Edge):
# options is supported from Selenium 4.0 onwards
# If can be removed when minimum Selenium version is 4.0 or greater
return webdriver.Edge(
options=options,
service_log_path=service_log_path,
executable_path=executable_path,
**desired_capabilities,
)
executable_path = self._get_executable_path(webdriver.edge.service.Service)
service = EdgeService(executable_path=executable_path, log_path=service_log_path)
return webdriver.Edge(
service_log_path=service_log_path,
executable_path=executable_path,
**desired_capabilities,
options=options,
service=service,
#**desired_capabilities,
)

def create_safari(
Expand Down

0 comments on commit 2c1575b

Please sign in to comment.