Skip to content

Commit 3281b80

Browse files
committed
Prepare SeleniumBase for Selenium4
1 parent 89b1878 commit 3281b80

File tree

2 files changed

+29
-23
lines changed

2 files changed

+29
-23
lines changed

seleniumbase/core/browser_launcher.py

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,6 @@ def _set_chrome_options(
458458
return chrome_options
459459

460460

461-
def _set_safari_capabilities():
462-
from selenium.webdriver.safari.webdriver import DesiredCapabilities as SDC
463-
464-
safari_capabilities = SDC.SAFARI.copy()
465-
safari_capabilities["cleanSession"] = True
466-
return safari_capabilities
467-
468-
469461
def _set_firefox_options(
470462
downloads_path,
471463
headless,
@@ -1130,6 +1122,7 @@ def get_local_driver(
11301122
)
11311123
else:
11321124
if os.path.exists(LOCAL_GECKODRIVER):
1125+
warnings.simplefilter("ignore", category=DeprecationWarning)
11331126
return webdriver.Firefox(
11341127
executable_path=LOCAL_GECKODRIVER,
11351128
options=firefox_options,
@@ -1189,6 +1182,7 @@ def get_local_driver(
11891182
if not headless:
11901183
return webdriver.Ie(capabilities=ie_capabilities)
11911184
else:
1185+
warnings.simplefilter("ignore", category=DeprecationWarning)
11921186
return webdriver.Ie(
11931187
executable_path=LOCAL_HEADLESS_IEDRIVER,
11941188
capabilities=ie_capabilities,
@@ -1265,11 +1259,15 @@ def get_local_driver(
12651259
sb_install.main(override="edgedriver")
12661260
sys.argv = sys_args # Put back the original sys args
12671261

1262+
selenium4 = False
1263+
if sys.version_info[0] == 3 and sys.version_info[1] >= 7:
1264+
selenium4 = True
1265+
12681266
# For Microsoft Edge (Chromium) version 80 or higher
1269-
try:
1270-
from msedge.selenium_tools import Edge, EdgeOptions
1271-
except Exception:
1272-
os.system("pip install msedge-selenium-tools")
1267+
if selenium4:
1268+
Edge = webdriver.edge.webdriver.WebDriver
1269+
EdgeOptions = webdriver.edge.webdriver.Options
1270+
else:
12731271
from msedge.selenium_tools import Edge, EdgeOptions
12741272

12751273
if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
@@ -1401,18 +1399,26 @@ def get_local_driver(
14011399
chromium_arg_item = "--" + chromium_arg_item
14021400
if len(chromium_arg_item) >= 3:
14031401
edge_options.add_argument(chromium_arg_item)
1404-
capabilities = edge_options.to_capabilities()
1405-
capabilities["platform"] = ""
1406-
return Edge(
1407-
executable_path=LOCAL_EDGEDRIVER, capabilities=capabilities
1408-
)
1402+
if selenium4:
1403+
warnings.simplefilter("ignore", category=DeprecationWarning)
1404+
return Edge(
1405+
executable_path=LOCAL_EDGEDRIVER,
1406+
options=edge_options,
1407+
)
1408+
else:
1409+
capabilities = edge_options.to_capabilities()
1410+
capabilities["platform"] = ""
1411+
return Edge(
1412+
executable_path=LOCAL_EDGEDRIVER,
1413+
capabilities=capabilities,
1414+
)
14091415
elif browser_name == constants.Browser.SAFARI:
14101416
arg_join = " ".join(sys.argv)
14111417
if ("-n" in sys.argv) or (" -n=" in arg_join) or (arg_join == "-c"):
14121418
# Skip if multithreaded
14131419
raise Exception("Can't run Safari tests in multi-threaded mode!")
1414-
safari_capabilities = _set_safari_capabilities()
1415-
return webdriver.Safari(desired_capabilities=safari_capabilities)
1420+
warnings.simplefilter("ignore", category=DeprecationWarning)
1421+
return webdriver.safari.webdriver.WebDriver(quiet=False)
14161422
elif browser_name == constants.Browser.OPERA:
14171423
try:
14181424
if LOCAL_OPERADRIVER and os.path.exists(LOCAL_OPERADRIVER):
@@ -1539,6 +1545,8 @@ def get_local_driver(
15391545
if not headless or "linux" not in PLATFORM:
15401546
try:
15411547
if os.path.exists(LOCAL_CHROMEDRIVER):
1548+
warnings.simplefilter(
1549+
"ignore", category=DeprecationWarning)
15421550
driver = webdriver.Chrome(
15431551
executable_path=LOCAL_CHROMEDRIVER,
15441552
options=chrome_options,
@@ -1610,6 +1618,8 @@ def get_local_driver(
16101618
)
16111619
_mark_chromedriver_repaired()
16121620
if os.path.exists(LOCAL_CHROMEDRIVER):
1621+
warnings.simplefilter(
1622+
"ignore", category=DeprecationWarning)
16131623
driver = webdriver.Chrome(
16141624
executable_path=LOCAL_CHROMEDRIVER,
16151625
options=chrome_options,

seleniumbase/fixtures/base_case.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,6 @@ def open(self, url):
153153
if ("http:") in c_url or ("https:") in c_url or ("file:") in c_url:
154154
if self.get_domain_url(url) != self.get_domain_url(c_url):
155155
self.open_new_window(switch_to=True)
156-
if self.browser == "safari" and url.startswith("data:"):
157-
url = re.escape(url)
158-
url = self.__escape_quotes_if_needed(url)
159-
self.execute_script("window.location.href='%s';" % url)
160156
else:
161157
self.driver.get(url)
162158
if settings.WAIT_FOR_RSC_ON_PAGE_LOADS:

0 commit comments

Comments
 (0)