Skip to content

Commit 903dd10

Browse files
authored
Merge pull request #192 from chilli-axe/switch-to-selenium-built-in-webdriver-manager
Switch to selenium's built-in webdriver manager from `webdriver_manager`
2 parents 47fa9e7 + eb16952 commit 903dd10

File tree

10 files changed

+36
-41
lines changed

10 files changed

+36
-41
lines changed

.github/workflows/test-desktop-tool.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ on:
77
jobs:
88
test-backend:
99
name: Desktop tool tests
10-
runs-on: ubuntu-latest
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
include:
14+
- os: macos-latest
15+
- os: windows-latest
16+
- os: ubuntu-latest
1117
steps:
1218
- uses: actions/checkout@v3
1319
- uses: ./.github/actions/test-desktop-tool

.github/workflows/tests.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ jobs:
2828
google-drive-api-key: ${{ secrets.GOOGLE_DRIVE_API_KEY }}
2929
test-desktop-tool:
3030
name: Desktop tool tests
31-
runs-on: ubuntu-latest
31+
runs-on: ${{ matrix.os }}
32+
strategy:
33+
matrix:
34+
include:
35+
- os: macos-latest
36+
- os: windows-latest
37+
- os: ubuntu-latest
3238
steps:
3339
- uses: actions/checkout@v3
3440
- uses: ./.github/actions/test-desktop-tool

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ repos:
3838
"pytest~=7.3",
3939
"ratelimit~=2.2",
4040
# desktop tool
41-
"aenum~=3.1.15",
4241
"attrs~=23.1",
4342
"click==8.0.4",
4443
"enlighten~=1.11",

MPCAutofill/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pytest-elasticsearch~=3.0
2929
python-dotenv~=1.0.0
3030
ratelimit~=2.2.1
3131
requests~=2.31.0
32-
selenium~=4.11.0
32+
selenium~=4.14.0
3333
sentry-sdk~=1.30.0
3434
syrupy~=3.0
3535
tqdm~=4.65.0

desktop-tool/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,5 @@ pytest-retry~=1.5
1414
ratelimit~=2.2.1
1515
requests~=2.31.0
1616
sanitize-filename~=1.2.0
17-
selenium~=4.11.0
18-
webdriver-manager==4.0.1
17+
selenium~=4.14.0
1918
wakepy==0.6.0

desktop-tool/src/webdrivers/brave.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1+
import sys
12
from typing import Optional
23

34
from selenium.webdriver import Chrome
45
from selenium.webdriver.chrome.options import Options
5-
from selenium.webdriver.chrome.service import Service
6-
from webdriver_manager.chrome import ChromeDriverManager, ChromeType
7-
from webdriver_manager.core.os_manager import OperationSystemManager, OSType
86

97

108
def get_brave_driver(headless: bool = False, binary_location: Optional[str] = None) -> Chrome:
@@ -13,23 +11,25 @@ def get_brave_driver(headless: bool = False, binary_location: Optional[str] = No
1311
options.add_argument("--log-level=3")
1412
options.add_argument("--disable-dev-shm-usage")
1513
if headless:
16-
options.headless = True
14+
options.add_argument("--headless=new")
1715
options.add_experimental_option("excludeSwitches", ["enable-logging"])
1816
options.add_experimental_option("detach", True)
1917

20-
# the binary location for brave must be manually specified
21-
# the below code block is partially borrowed from webdriver-manager tests:
22-
# https://github.com/SergeyPirogov/webdriver_manager/blob/master/tests/test_brave_driver.py
18+
# the binary location for brave must be manually specified (otherwise chrome will open instead)
2319
if binary_location is not None:
2420
options.binary_location = binary_location
2521
else:
26-
default_binary_location = {
27-
OSType.LINUX: "/usr/bin/brave-browser",
28-
OSType.MAC: "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
29-
OSType.WIN: "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe",
30-
}[OperationSystemManager.get_os_name()]
31-
options.binary_location = default_binary_location
22+
default_binary_locations = {
23+
"linux": "/usr/bin/brave-browser",
24+
"darwin": "/Applications/Brave Browser.app/Contents/MacOS/Brave Browser",
25+
"win32": "C:\\Program Files\\BraveSoftware\\Brave-Browser\\Application\\brave.exe",
26+
}
27+
if sys.platform not in default_binary_locations.keys():
28+
raise KeyError(
29+
f"Cannot determine the default Brave binary location for the operating system {sys.platform}!"
30+
)
31+
options.binary_location = default_binary_locations[sys.platform]
3232

33-
driver = Chrome(service=Service(ChromeDriverManager(chrome_type=ChromeType.BRAVE).install()), options=options) # type: ignore
33+
driver = Chrome(options=options)
3434
driver.set_network_conditions(offline=False, latency=5, throughput=5 * 125000)
3535
return driver

desktop-tool/src/webdrivers/chrome.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
from selenium.webdriver import Chrome
44
from selenium.webdriver.chrome.options import Options
5-
from selenium.webdriver.chrome.service import Service
6-
from webdriver_manager.chrome import ChromeDriverManager
7-
from webdriver_manager.core.os_manager import OperationSystemManager, OSType
85

96

107
def get_chrome_driver(headless: bool = False, binary_location: Optional[str] = None) -> Chrome:
@@ -13,19 +10,11 @@ def get_chrome_driver(headless: bool = False, binary_location: Optional[str] = N
1310
options.add_argument("--log-level=3")
1411
options.add_argument("--disable-dev-shm-usage")
1512
if headless:
16-
options.headless = True
13+
options.add_argument("--headless=new")
1714
options.add_experimental_option("excludeSwitches", ["enable-logging"])
1815
options.add_experimental_option("detach", True)
1916
if binary_location is not None:
2017
options.binary_location = binary_location
21-
else:
22-
# here, we specifically hardcode the binary location in macOS to work around this issue:
23-
# https://github.com/seleniumHQ/selenium/issues/12381, which is caused by
24-
# https://github.com/GoogleChromeLabs/chrome-for-testing/issues/30
25-
# the issue is marked as resolved in the selenium repository but still occurs for me on selenium==4.11.2
26-
# perhaps something is broken on the webdriver_manager side here
27-
if OperationSystemManager.get_os_name() == OSType.MAC:
28-
options.binary_location = "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
29-
driver = Chrome(service=Service(ChromeDriverManager().install()), options=options) # type: ignore
18+
driver = Chrome(options=options)
3019
driver.set_network_conditions(offline=False, latency=5, throughput=5 * 125000)
3120
return driver

desktop-tool/src/webdrivers/edge.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
from selenium.webdriver.chromium.options import ChromiumOptions
55
from selenium.webdriver.chromium.webdriver import ChromiumDriver
66
from selenium.webdriver.edge.options import Options
7-
from selenium.webdriver.edge.service import Service
8-
from webdriver_manager.microsoft import EdgeChromiumDriverManager
97

108

119
def get_edge_driver(headless: bool = False, binary_location: Optional[str] = None) -> ChromiumDriver:
@@ -14,11 +12,11 @@ def get_edge_driver(headless: bool = False, binary_location: Optional[str] = Non
1412
options.add_argument("--log-level=3")
1513
options.add_argument("--disable-dev-shm-usage")
1614
if headless:
17-
options.headless = True
15+
options.add_argument("--headless=new")
1816
options.add_experimental_option("excludeSwitches", ["enable-logging"])
1917
options.add_experimental_option("detach", True)
2018
if binary_location is not None:
2119
options.binary_location = binary_location
22-
driver: ChromiumDriver = Edge(service=Service(EdgeChromiumDriverManager().install()), options=options) # type: ignore
20+
driver: ChromiumDriver = Edge(options=options) # type: ignore
2321
driver.set_network_conditions(offline=False, latency=5, throughput=5 * 125000)
2422
return driver

desktop-tool/src/webdrivers/firefox.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from selenium.webdriver import Firefox
44
from selenium.webdriver.firefox.options import Options
5-
from selenium.webdriver.firefox.service import Service
6-
from webdriver_manager.firefox import GeckoDriverManager
75

86

97
# note: firefox is not currently supported
@@ -14,5 +12,5 @@ def get_firefox_driver(headless: bool = False, binary_location: Optional[str] =
1412
options.add_argument("--headless")
1513
if binary_location is not None:
1614
options.binary_location = binary_location
17-
driver = Firefox(service=Service(GeckoDriverManager().install()), options=options) # type: ignore
15+
driver = Firefox(options=options)
1816
return driver

desktop-tool/tests/test_desktop_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ def do_nothing(_):
890890

891891

892892
@pytest.mark.flaky(retries=3, delay=1)
893-
@pytest.mark.parametrize("browser", [constants.Browsers.chrome])
893+
@pytest.mark.parametrize("browser", [constants.Browsers.chrome, constants.Browsers.edge])
894894
@pytest.mark.parametrize(
895895
"site",
896896
[

0 commit comments

Comments
 (0)