Skip to content

Commit 36bdf14

Browse files
authored
Merge pull request #3452 from seleniumbase/download-browsers-and-more
Add support for downloading browsers, and more
2 parents 7c21383 + 98cfdfa commit 36bdf14

23 files changed

+624
-51
lines changed

.gitignore

+14
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ msedgedriver.exe
8282
operadriver.exe
8383
uc_driver.exe
8484

85+
# Chrome for Testing folders
86+
chrome-mac-arm64
87+
chrome-mac-x64
88+
chrome-linux64
89+
chrome-win64
90+
chrome-win32
91+
92+
# Chrome-Headless-Shell folders
93+
chrome-headless-shell-mac-arm64
94+
chrome-headless-shell-mac-x64
95+
chrome-headless-shell-linux64
96+
chrome-headless-shell-win64
97+
chrome-headless-shell-win32
98+
8599
# msedgedriver requirements
86100
libc++.dylib
87101

examples/proxy_test.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,30 @@ def test_proxy(self):
1313
if not self.page_load_strategy == "none" and not self.undetectable:
1414
# This page takes too long to load otherwise
1515
self.get_new_driver(page_load_strategy="none")
16+
self.open("https://api.ipify.org/")
17+
ip_address = self.get_text("body")
1618
self.open("https://ipinfo.io/")
17-
self.wait_for_non_empty_text("form input", timeout=20)
18-
ip_address = self.get_text('#ip-string span[class*="primary"] span')
19+
self.type('input[name="search"]', ip_address, timeout=20)
20+
self.click("form button span")
21+
self.sleep(2)
22+
self.click_if_visible("span.cursor-pointer", timeout=4)
1923
print("\n\nMy IP Address = %s\n" % ip_address)
2024
print("Displaying Host Info:")
21-
text = self.get_text("#widget-scrollable-container").split("asn:")[0]
25+
text = self.get_text("#block-summary").split("Hosted domains")[0]
26+
rows = text.split("\n")
27+
data = []
28+
for row in rows:
29+
if row.strip() != "":
30+
data.append(row.strip())
31+
print("\n".join(data).replace('\n"', " "))
32+
print("\nDisplaying Geolocation Info:")
33+
text = self.get_text("#block-geolocation").split("Coordinates")[0]
2234
rows = text.split("\n")
2335
data = []
2436
for row in rows:
2537
if row.strip() != "":
2638
data.append(row.strip())
2739
print("\n".join(data).replace('\n"', " "))
2840
if not self.headless:
29-
print("\nThe browser will close automatically in 7 seconds...")
30-
self.sleep(7)
41+
print("\nThe browser will close automatically in 3 seconds...")
42+
self.sleep(3)

examples/test_cdp_ad_blocking.py

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ def test_cdp_network_blocking(self):
2424
]})
2525
self.execute_cdp_cmd('Network.enable', {})
2626
self.open('https://www.w3schools.com/jquery/default.asp')
27+
self.ad_block()
2728
source = self.get_page_source()
2829
self.assert_true("doubleclick.net" not in source)
2930
self.assert_true("google-analytics.com" not in source)

examples/youtube_search_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def test_youtube_autocomplete_results(self):
1111
self.skip("Unsupported mode for this test.")
1212
self.open("https://www.youtube.com/c/MichaelMintz")
1313
search_term = "seleniumbase"
14-
search_selector = "input#search"
14+
search_selector = 'input[name="search_query"]'
1515
results_selector = '[role="listbox"]'
1616
self.click_if_visible('button[aria-label="Close"]')
1717
self.double_click(search_selector)

help_docs/customizing_test_runs.md

+37
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,22 @@ pytest --headless -n8 --dashboard --html=report.html -v --rs --crumbs
337337

338338
The above not only runs tests in parallel processes, but it also tells tests in the same process to share the same browser session, runs the tests in headless mode, displays the full name of each test on a separate line, creates a real-time dashboard of the test results, and creates a full report after all tests complete.
339339

340+
🎛️ For extra speed, run your tests using `chrome-headless-shell`:
341+
342+
First, get `chrome-headless-shell` if you don't already have it:
343+
344+
```bash
345+
sbase get chs
346+
```
347+
348+
Then, run scripts with `binary_location` / `bl` set to `"chs"`:
349+
350+
```bash
351+
pytest --bl="chs" -n8 --dashboard --html=report.html -v --rs
352+
```
353+
354+
That makes your tests run very quickly in headless mode.
355+
340356
--------
341357

342358
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> The SeleniumBase Dashboard:</h3>
@@ -449,6 +465,27 @@ Note that different options could lead to the same result. (Eg. If you have the
449465

450466
--------
451467

468+
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Setting the binary location:</h3>
469+
470+
🔵 By default, SeleniumBase uses the browser binary detected on the System PATH.
471+
472+
🎛️ To change this default behavior, you can use:
473+
474+
```bash
475+
pytest --binary-location=PATH
476+
```
477+
478+
The `PATH` in `--binary-location=PATH` / `--bl=PATH` can be:
479+
* A relative or exact path to the browser binary.
480+
* `"cft"` as a special option for `Chrome for Testing`.
481+
* `"chs"` as a special option for `Chrome-Headless-Shell`.
482+
483+
Before using the `"cft"` / `"chs"` options, call `sbase get cft` / `sbase get chs` in order to download the specified binaries into the `seleniumbase/drivers` folder. The default version is the latest stable version on https://googlechromelabs.github.io/chrome-for-testing/. You can change that by specifying the arg as a parameter. (Eg. `sbase get cft 131`, `sbase get chs 132`, etc.)
484+
485+
With the `SB()` and `Driver()` formats, the binary location is set via the `binary_location` parameter.
486+
487+
--------
488+
452489
<h3><img src="https://seleniumbase.github.io/img/green_logo.png" title="SeleniumBase" width="32" /> Customizing default settings:</h3>
453490

454491
🎛️ An easy way to override [seleniumbase/config/settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) is by using a custom settings file.

help_docs/webdriver_installation.md

+26-8
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
To run web automation, you need webdrivers for each browser you plan on using. With SeleniumBase, drivers are downloaded automatically (as needed) into the SeleniumBase `drivers/` folder.
66

7-
You can also download drivers manually with these commands:
7+
🎛️ You can also download drivers manually with these commands:
88

99
```bash
1010
seleniumbase get chromedriver
@@ -16,7 +16,7 @@ After running the commands above, web drivers will get downloaded into the `sele
1616

1717
If the necessary driver is not found in this location while running tests, SeleniumBase will instead look for the driver on the System PATH. If the necessary driver is not on the System PATH either, SeleniumBase will automatically attempt to download the required driver.
1818

19-
* You can also download specific versions of drivers. Examples:
19+
🎛️ You can also download specific versions of drivers. Examples:
2020

2121
```bash
2222
sbase get chromedriver 114
@@ -30,7 +30,7 @@ sbase get chromedriver mlatest # Milestone latest version for detected browser
3030
sbase get edgedriver 115.0.1901.183
3131
```
3232

33-
(NOTE: ``sbase`` is a shortcut for ``seleniumbase``)
33+
(NOTE: `sbase` is a shortcut for `seleniumbase`)
3434

3535
--------
3636

@@ -48,15 +48,15 @@ Here's where you can go to manually get web drivers from the source:
4848

4949
**macOS shortcuts**:
5050

51-
* You can also install drivers by using ``brew`` (aka ``homebrew``):
51+
🎛️ You can also install drivers by using ``brew`` (aka ``homebrew``):
5252

5353
```bash
5454
brew install --cask chromedriver
5555

5656
brew install geckodriver
5757
```
5858

59-
You can also upgrade existing webdrivers:
59+
🎛️ You can also upgrade existing webdrivers:
6060

6161
```bash
6262
brew upgrade --cask chromedriver
@@ -66,7 +66,7 @@ brew upgrade geckodriver
6666

6767
**Linux shortcuts**:
6868

69-
If you still need drivers, these scripts download ``chromedriver`` and ``geckodriver`` to a Linux machine:
69+
🎛️ If you still need drivers, these scripts download `chromedriver` and `geckodriver` to a Linux machine:
7070

7171
```bash
7272
wget https://chromedriver.storage.googleapis.com/114.0.5735.90/chromedriver_linux64.zip
@@ -76,12 +76,30 @@ chmod +x /usr/local/bin/chromedriver
7676
```
7777

7878
```bash
79-
wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux64.tar.gz
80-
tar xvfz geckodriver-v0.34.0-linux64.tar.gz
79+
wget https://github.com/mozilla/geckodriver/releases/download/v0.35.0/geckodriver-v0.35.0-linux64.tar.gz
80+
tar xvfz geckodriver-v0.35.0-linux64.tar.gz
8181
mv geckodriver /usr/local/bin/
8282
chmod +x /usr/local/bin/geckodriver
8383
```
8484

8585
To verify that web drivers are working, **[follow these instructions](https://github.com/seleniumbase/SeleniumBase/blob/master/help_docs/verify_webdriver.md)**.
8686

87+
--------
88+
89+
**Browser Binaries**:
90+
91+
🎛️ Use the `sbase get` command to download the `Chrome for Testing` and `Chrome-Headless-Shell` browser binaries. Example:
92+
93+
```bash
94+
sbase get cft # (For `Chrome for Testing`)
95+
sbase get chs # (For `Chrome-Headless-Shell`)
96+
```
97+
98+
Those commands download those binaries into the `seleniumbase/drivers` folder.
99+
To use the binaries from there in SeleniumBase scripts, set the `binary_location` to `cft` or `chs`.
100+
101+
(Source: https://googlechromelabs.github.io/chrome-for-testing/)
102+
103+
--------
104+
87105
[<img src="https://seleniumbase.github.io/cdn/img/sb_logo_b.png" title="SeleniumBase" width="280">](https://github.com/seleniumbase/SeleniumBase)

mkdocs_build/requirements.txt

-4
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ pymdown-extensions>=10.14.1
66
pipdeptree>=2.24.0
77
python-dateutil>=2.8.2
88
Markdown==3.7
9-
markdown2==2.5.2
109
click==8.1.8
1110
ghp-import==2.1.0
1211
watchdog==6.0.0
1312
cairocffi==1.7.1
1413
pathspec==0.12.1
1514
Babel==2.16.0
1615
paginate==0.5.7
17-
lxml==5.3.0
18-
pyquery==2.0.1
19-
readtime==3.0.0
2016
mkdocs==1.6.1
2117
mkdocs-material==9.5.50
2218
mkdocs-exclude-search==0.6.6

requirements.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ trio-websocket==0.11.1
4343
wsproto==1.2.0
4444
websocket-client==1.8.0
4545
selenium==4.27.1;python_version<"3.9"
46-
selenium==4.28.0;python_version>="3.9"
46+
selenium==4.28.1;python_version>="3.9"
4747
cssselect==1.2.0
4848
sortedcontainers==2.4.0
4949
execnet==2.1.1

seleniumbase/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# seleniumbase package
2-
__version__ = "4.34.1"
2+
__version__ = "4.34.2"

seleniumbase/behave/behave_sb.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,8 @@ def get_configured_sb(context):
482482
extension_dir = sb.extension_dir # revert to default
483483
sb.extension_dir = extension_dir
484484
continue
485-
# Handle: -D binary-location=PATH / binary_location=PATH
486-
if low_key in ["binary-location", "binary_location"]:
485+
# Handle: -D binary-location=PATH / binary_location=PATH / bl=PATH
486+
if low_key in ["binary-location", "binary_location", "bl"]:
487487
binary_location = userdata[key]
488488
if binary_location == "true":
489489
binary_location = sb.binary_location # revert to default
@@ -884,6 +884,14 @@ def get_configured_sb(context):
884884
sb.headless = True # Firefox has regular headless
885885
elif sb.browser not in ["chrome", "edge"]:
886886
sb.headless2 = False # Only for Chromium browsers
887+
if (
888+
sb.binary_location
889+
and sb.binary_location.lower() == "chs"
890+
and sb.browser == "chrome"
891+
):
892+
sb.headless = True
893+
sb.headless1 = False
894+
sb.headless2 = False
887895
# Recorder Mode only supports Chromium browsers.
888896
if sb.recorder_ext and (sb.browser not in ["chrome", "edge"]):
889897
raise Exception(

seleniumbase/console_scripts/ReadMe.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,12 @@ sbase get chromedriver 114.0.5735.90
6868
sbase get chromedriver stable
6969
sbase get chromedriver beta
7070
sbase get chromedriver -p
71+
sbase get cft 131
72+
sbase get chs
7173
```
7274

73-
(Drivers: ``chromedriver``, ``geckodriver``, ``edgedriver``,
74-
``iedriver``, ``uc_driver``)
75+
(Drivers: ``chromedriver``, ``cft``, ``uc_driver``,
76+
``edgedriver``, ``chs``, ``geckodriver``)
7577

7678
(Options: A specific driver version or major version integer.
7779
If not set, the driver version matches the browser.

seleniumbase/console_scripts/run.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ def show_install_usage():
139139
print(" OR: seleniumbase get [DRIVER_NAME] [OPTIONS]")
140140
print(" OR: sbase install [DRIVER_NAME] [OPTIONS]")
141141
print(" OR: sbase get [DRIVER_NAME] [OPTIONS]")
142-
print(" (Drivers: chromedriver, geckodriver,")
143-
print(" edgedriver, iedriver, uc_driver)")
142+
print(" (Drivers: chromedriver, cft, uc_driver,")
143+
print(" edgedriver, chs, geckodriver)")
144144
print(" Options:")
145145
print(" VERSION Specify the version to download.")
146146
print(" Tries to detect the needed version.")
@@ -157,11 +157,15 @@ def show_install_usage():
157157
print(" sbase get chromedriver stable")
158158
print(" sbase get chromedriver beta")
159159
print(" sbase get chromedriver -p")
160+
print(" sbase get cft 131")
161+
print(" sbase get chs")
160162
print(" Output:")
161163
print(" Downloads the webdriver to seleniumbase/drivers/")
162164
print(" (chromedriver is required for Chrome automation)")
163165
print(" (geckodriver is required for Firefox automation)")
164166
print(" (edgedriver is required for MS__Edge automation)")
167+
print(" (cft is for the `Chrome for Testing` binary exe)")
168+
print(" (chs is for the `Chrome-Headless-Shell` binary.)")
165169
print("")
166170

167171

0 commit comments

Comments
 (0)