Skip to content

Commit fe4394b

Browse files
authored
Merge pull request #648 from seleniumbase/update-chromium-options-and-node
Update default Chromium options and more
2 parents 420b6cc + cb57634 commit fe4394b

File tree

12 files changed

+144
-90
lines changed

12 files changed

+144
-90
lines changed

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<a href="https://github.com/seleniumbase/SeleniumBase/releases">
1616
<img src="https://img.shields.io/github/v/release/seleniumbase/SeleniumBase.svg?color=2277EE" alt="Latest Release on GitHub" /></a> <a href="https://pypi.python.org/pypi/seleniumbase">
1717
<img src="https://img.shields.io/pypi/v/seleniumbase.svg?color=22AAEE" alt="Latest Release on PyPI" /></a> <a href="https://seleniumbase.io">
18-
<img src="https://img.shields.io/badge/docs-%20here-11BBDD.svg" alt="SeleniumBase.io Docs" /></a> <a href="https://travis-ci.org/seleniumbase/SeleniumBase">
18+
<img src="https://img.shields.io/badge/docs-%20seleniumbase.io-11BBDD.svg" alt="SeleniumBase.io Docs" /></a> <a href="https://travis-ci.org/seleniumbase/SeleniumBase">
1919
<img src="https://img.shields.io/travis/seleniumbase/SeleniumBase/master.svg" alt="SeleniumBase on TravisCI" /></a> <a href="https://github.com/seleniumbase/SeleniumBase/actions">
2020
<img src="https://github.com/seleniumbase/SeleniumBase/workflows/CI%20build/badge.svg" alt="SeleniumBase GitHub Actions" /></a> <a href="https://gitter.im/seleniumbase/SeleniumBase">
2121
<img src="https://badges.gitter.im/seleniumbase/SeleniumBase.svg" alt="SeleniumBase" /></a>
@@ -283,7 +283,7 @@ The code above will leave your browser window open in case there's a failure. (i
283283
Here are some useful command-line options that come with ``pytest``:
284284

285285
```bash
286-
-v # Verbose mode. Print the full name of each test run.
286+
-v # Verbose mode. Prints the full name of each test run.
287287
-q # Quiet mode. Print fewer details in the console output when running tests.
288288
-x # Stop running the tests after the first failure is reached.
289289
--html=report.html # Creates a detailed pytest-html report after tests finish.
@@ -298,7 +298,7 @@ Here are some useful command-line options that come with ``pytest``:
298298
SeleniumBase provides additional ``pytest`` command-line options for tests:
299299

300300
```bash
301-
--browser=BROWSER # (The web browser to use. Default: "chrome")
301+
--browser=BROWSER # (The web browser to use. Default: "chrome".)
302302
--cap-file=FILE # (The web browser's desired capabilities to use.)
303303
--cap-string=STRING # (The web browser's desired capabilities to use.)
304304
--settings-file=FILE # (Override default SeleniumBase settings.)
@@ -308,9 +308,10 @@ SeleniumBase provides additional ``pytest`` command-line options for tests:
308308
--var2=DATA # (Extra test data. Access with "self.var2" in tests.)
309309
--var3=DATA # (Extra test data. Access with "self.var3" in tests.)
310310
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
311-
--server=SERVER # (The server / IP address used by the tests.)
312-
--port=PORT # (The port that's used by the test server.)
313-
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
311+
--server=SERVER # (The Selenium Grid server/IP used for tests.)
312+
--port=PORT # (The Selenium Grid port used by the test server.)
313+
--proxy=SERVER:PORT # (Connect to a proxy server:port for tests.)
314+
--proxy=USERNAME:PASSWORD@SERVER:PORT # (Use authenticated proxy server.)
314315
--agent=STRING # (Modify the web browser's User-Agent string.)
315316
--mobile # (Use the mobile device emulator while running tests.)
316317
--metrics=STRING # (Set mobile "CSSWidth,CSSHeight,PixelRatio".)

examples/visual_testing/test_layout_fail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class VisualLayoutFailureTest(BaseCase):
55

6-
def test_applitools_layout_change_failure(self):
6+
def test_applitools_change(self):
77
self.open('https://applitools.com/helloworld?diff1')
88
print('\nCreating baseline in "visual_baseline" folder.')
99
self.check_window(name="helloworld", baseline=True)
@@ -13,15 +13,15 @@ def test_applitools_layout_change_failure(self):
1313
self.click("button")
1414
self.check_window(name="helloworld", level=3)
1515

16-
def test_python_home_layout_change_failure(self):
16+
def test_python_home_change(self):
1717
self.open('https://python.org/')
1818
print('\nCreating baseline in "visual_baseline" folder.')
1919
self.check_window(name="python_home", baseline=True)
2020
# Remove the "Donate" button
2121
self.remove_element('a.donate-button')
2222
self.check_window(name="python_home", level=3)
2323

24-
def test_xkcd_layout_change_failure(self):
24+
def test_xkcd_logo_change(self):
2525
self.open('https://xkcd.com/554/')
2626
print('\nCreating baseline in "visual_baseline" folder.')
2727
self.check_window(name="xkcd_554", baseline=True)

help_docs/customizing_test_runs.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ If you're using ``pytest`` for running tests outside of the SeleniumBase repo, y
7878
Here are some useful command-line options that come with ``pytest``:
7979

8080
```bash
81-
-v # Verbose mode. Print the full name of each test run.
81+
-v # Verbose mode. Prints the full name of each test run.
8282
-q # Quiet mode. Print fewer details in the console output when running tests.
8383
-x # Stop running the tests after the first failure is reached.
8484
--html=report.html # Creates a detailed pytest-html report after tests finish.
@@ -93,7 +93,7 @@ Here are some useful command-line options that come with ``pytest``:
9393
SeleniumBase provides additional ``pytest`` command-line options for tests:
9494

9595
```bash
96-
--browser=BROWSER # (The web browser to use. Default: "chrome")
96+
--browser=BROWSER # (The web browser to use. Default: "chrome".)
9797
--cap-file=FILE # (The web browser's desired capabilities to use.)
9898
--cap-string=STRING # (The web browser's desired capabilities to use.)
9999
--settings-file=FILE # (Override default SeleniumBase settings.)
@@ -103,10 +103,10 @@ SeleniumBase provides additional ``pytest`` command-line options for tests:
103103
--var2=DATA # (Extra test data. Access with "self.var2" in tests.)
104104
--var3=DATA # (Extra test data. Access with "self.var3" in tests.)
105105
--user-data-dir=DIR # (Set the Chrome user data directory to use.)
106-
--server=SERVER # (The server / IP address used by the tests.)
107-
--port=PORT # (The port that's used by the test server.)
108-
--proxy=SERVER:PORT # (This is the proxy server:port combo used by tests.)
109-
--agent=STRING # (Modify the web browser's User-Agent string.)
106+
--server=SERVER # (The Selenium Grid server/IP used for tests.)
107+
--port=PORT # (The Selenium Grid port used by the test server.)
108+
--proxy=SERVER:PORT # (Connect to a proxy server:port for tests.)
109+
--proxy=USERNAME:PASSWORD@SERVER:PORT # (Use authenticated proxy server.)
110110
--mobile # (Use the mobile device emulator while running tests.)
111111
--metrics=STRING # (Set mobile "CSSWidth,CSSHeight,PixelRatio".)
112112
--extension-zip=ZIP # (Load a Chrome Extension .zip file, comma-separated.)

integrations/node_js/ReadMe.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Creating a SeleniumBase Test Launcher by using NodeJS</h2>
1+
<h2><img src="https://seleniumbase.io/img/sb_icon.png" title="SeleniumBase" width="30" /> Creating a SeleniumBase Test Runner with NodeJS</h2>
22

33
You can create a customized web app for running SeleniumBase tests by using NodeJS. (This tutorial assumes that you've already installed SeleniumBase by following the instructions from the [top-level ReadMe](https://github.com/seleniumbase/SeleniumBase/blob/master/README.md) file.)
44

@@ -15,23 +15,23 @@ You can create a customized web app for running SeleniumBase tests by using Node
1515
npm install -g express
1616
```
1717

18-
#### 3. Install the Example Test Launcher for SeleniumBase from the ``integrations/node_js`` folder
18+
#### 3. Install the Example Test Runner for SeleniumBase from the ``integrations/node_js`` folder
1919

2020
```bash
2121
npm install
2222
```
2323

2424
(You should see a ``node_modules`` folder appear in your ``node_js`` folder.)
2525

26-
#### 4. Run the NodeJS server for your SeleniumBase Test Launcher web app
26+
#### 4. Run the NodeJS server for your SeleniumBase Test Runner web app
2727

2828
```bash
2929
node server.js
3030
```
3131

3232
(You can always stop the server by using ``CTRL-C``.)
3333

34-
#### 5. Open the SeleniumBase Test Launcher web app
34+
#### 5. Open the SeleniumBase Test Runner web app
3535

3636
* Navigate to [http://127.0.0.1:3000/](http://127.0.0.1:3000/)
3737

@@ -41,4 +41,4 @@ Click on a button to run a SeleniumBase example test.
4141

4242
#### 7. Expand your web app
4343

44-
Now that you have a web app for launching SeleniumBase tests, you can expand it to run any script that you want after pressing a button.
44+
Now that you have a web app for running SeleniumBase tests, you can expand it to run any script that you want after pressing a button.

integrations/node_js/server.js

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,43 @@
1-
var http = require('http');
2-
var express = require('express');
3-
var path = require('path');
4-
var app = express();
5-
var exec = require('child_process').exec;
6-
7-
function run_my_first_test() {
8-
exec("pytest my_first_test.py");
9-
}
10-
11-
function run_test_demo_site() {
12-
exec("pytest test_demo_site.py");
13-
}
14-
15-
function run_my_first_test_with_demo_mode() {
16-
exec("pytest my_first_test.py --demo_mode");
17-
}
18-
19-
function run_test_demo_site_with_demo_mode() {
20-
exec("pytest test_demo_site.py --demo_mode");
1+
const http = require('http');
2+
const express = require('express');
3+
const path = require('path');
4+
const app = express();
5+
const exec = require('child_process').exec;
6+
var server_info = '\nServer running at http://127.0.0.1:3000/ (CTRL-C to stop)';
7+
8+
function run_command(command) {
9+
console.log("\n" + command);
10+
exec(command, (err, stdout, stderr) => console.log(stdout, server_info));
2111
}
2212

2313
app.get('/', function(req, res) {
2414
res.sendFile(path.join(__dirname + '/index.html'));
25-
})
15+
});
2616

2717
app.get('/run_my_first_test', function(req, res) {
2818
res.sendFile(path.join(__dirname + '/index.html'));
2919
res.redirect('/');
30-
run_my_first_test()
31-
})
20+
run_command("pytest my_first_test.py");
21+
});
3222

3323
app.get('/run_test_demo_site', function(req, res) {
3424
res.sendFile(path.join(__dirname + '/index.html'));
3525
res.redirect('/');
36-
run_test_demo_site()
37-
})
26+
run_command("pytest test_demo_site.py");
27+
});
3828

3929
app.get('/run_my_first_test_with_demo_mode', function(req, res) {
4030
res.sendFile(path.join(__dirname + '/index.html'));
4131
res.redirect('/');
42-
run_my_first_test_with_demo_mode()
43-
})
32+
run_command("pytest my_first_test.py --demo_mode");
33+
});
4434

4535
app.get('/run_test_demo_site_with_demo_mode', function(req, res) {
4636
res.sendFile(path.join(__dirname + '/index.html'));
4737
res.redirect('/');
48-
run_test_demo_site_with_demo_mode()
49-
})
38+
run_command("pytest test_demo_site.py --demo_mode");
39+
});
5040

5141
app.listen(3000, "127.0.0.1", function() {
52-
console.log('Server running at http://127.0.0.1:3000/ (CTRL-C to stop)');
42+
console.log(server_info);
5343
});

requirements.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
pip>=20.2.1
22
packaging>=20.4
33
setuptools>=44.1.1;python_version<"3.5"
4-
setuptools>=49.2.1;python_version>="3.5"
4+
setuptools>=49.3.1;python_version>="3.5"
55
setuptools-scm>=4.1.2
66
wheel>=0.34.2
77
six==1.15.0
@@ -37,6 +37,8 @@ soupsieve==2.0.1;python_version>="3.5"
3737
beautifulsoup4==4.9.1
3838
cryptography==3.0
3939
pyopenssl==19.1.0
40+
prompt-toolkit==1.0.18;python_version<"3.6.1"
41+
prompt-toolkit==3.0.6;python_version>="3.6.1"
4042
pygments==2.5.2;python_version<"3.5"
4143
pygments==2.6.1;python_version>="3.5"
4244
ipython==5.10.0;python_version<"3.5"
@@ -49,7 +51,7 @@ brython>=3.8.9
4951
pyotp==2.4.0
5052
boto==2.49.0
5153
cffi==1.14.1
52-
rich==5.0.0;python_version>="3.6" and python_version<"4.0"
54+
rich==5.1.2;python_version>="3.6" and python_version<"4.0"
5355
flake8==3.7.9;python_version<"3.5"
5456
flake8==3.8.3;python_version>="3.5"
5557
pyflakes==2.1.1;python_version<"3.5"

seleniumbase/console_scripts/run.py

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ def show_options():
443443
c2 = colorama.Fore.BLUE + colorama.Back.LIGHTGREEN_EX
444444
c3 = colorama.Fore.BLUE + colorama.Back.LIGHTYELLOW_EX
445445
cr = colorama.Style.RESET_ALL
446-
sc = ("\n " + c2 + "** " + c3 + "pytest cmd options" + c2 + " **" + cr)
446+
sc = ("\n " + c2 + " ** " + c3 + " pytest CMD Options " + c2 + " ** " + cr)
447447
print(sc)
448448
print("")
449449
line = "Here are some common pytest options to use with SeleniumBase:"
450450
line = c1 + line + cr
451451
print(line)
452452
print("")
453-
print('--browser=BROWSER (The web browser to use. Default: "chrome")')
453+
print('--browser=BROWSER (The web browser to use. Default: "chrome".)')
454454
print('--headless (Run tests headlessly. Default mode on Linux OS.)')
455455
print('--demo (Slow down and visually see test actions as they occur.)')
456456
print('--slow (Slow down the automation. Faster than using Demo Mode.)')
@@ -461,27 +461,35 @@ def show_options():
461461
print("--guest (Enable Chrome's Guest mode.)")
462462
print('-m MARKER (Run tests with the specified pytest marker.)')
463463
print('-n NUM (Multithread the tests using that many threads.)')
464-
print('-v (Verbose mode. Print the full name of each test run.)')
465-
print('--check-js (Check for JavaScript errors after page loads.)')
464+
print('-v (Verbose mode. Prints the full names of each test run.)')
466465
print('--html=report.html (Create a detailed pytest-html report.)')
466+
print('--collect-only / --co (Only show discovered tests. No run.)')
467+
print('--co -q (Only show full names of discovered tests. No run.)')
468+
print('--trace (Enter Debug Mode immediately after starting any test.')
469+
print(' n: Next line of method. s: Step through. c: Continue.)')
470+
print('--pdb (Enter Debug Mode if a test fails. h: Help. c: Continue.')
471+
print(' where: Stacktrace location. u: Up stack. d: Down stack.')
472+
print(' longlist: Stack code. dir(): List objects in namespace.)')
473+
print('-x (Stop running the tests after the first failure is reached.)')
474+
print('--archive-logs (Archive old log files instead of deleting them.)')
475+
print('--save-screenshot (Save a screenshot at the end of each test.)')
476+
print('--check-js (Check for JavaScript errors after page loads.)')
477+
print('--start-page=URL (The browser start page when tests begin.)')
467478
print("--agent=STRING (Modify the web browser's User-Agent string.)")
468479
print('--mobile (Use the mobile device emulator while running tests.)')
469480
print('--metrics=STRING (Set mobile "CSSWidth,CSSHeight,PixelRatio".)')
470481
print('--ad-block (Block some types of display ads after page loads.)')
471-
print('--pdb (Enter Debug Mode if a test fails. h: Help. c: Continue.')
472-
print(' interact: Interactive Mode. CTRL-D: Exit Interactive Mode.)')
473-
print('--archive-logs (Archive old log files instead of deleting them.)')
474-
print('--disable-csp (Disable the Content Security Policy of websites.)')
475-
print('--save-screenshot (Save a screenshot at the end of each test.)')
476-
print('--proxy=SERVER:PORT (Set a proxy server:port combo for tests.)')
477-
print("--settings-file=FILE (Override default SeleniumBase settings.)")
482+
print('--settings-file=FILE (Override default SeleniumBase settings.)')
478483
print('--env=ENV (Set the test env. Access with "self.env" in tests.)')
479484
print('--data=DATA (Extra test data. Access with "self.data" in tests.)')
480-
print('--collect-only -q (Show discovered tests without running them.)')
481-
print('-x (Stop running tests after the first failure is reached.)')
485+
print('--disable-csp (Disable the Content Security Policy of websites.)')
486+
print('--server=SERVER (The Selenium Grid server/IP used for tests.)')
487+
print('--port=PORT (The Selenium Grid port used by the test server.)')
488+
print('--proxy=SERVER:PORT (Connect to a proxy server:port for tests.)')
489+
print('--proxy=USER:PASS@SERVER:PORT (Use authenticated proxy server.)')
482490
print("")
483-
line = 'For the full list of ' + c1 + 'command-line options' + cr
484-
line += ', type: "' + c2 + 'pytest' + cr + ' ' + c3 + '--help' + cr + '".'
491+
line = 'For the full list of ' + c2 + 'command-line options' + cr
492+
line += ', type: "' + c1 + 'pytest' + cr + ' ' + c3 + '--help' + cr + '".'
485493
print(line)
486494
print("")
487495

seleniumbase/core/browser_launcher.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ def _set_chrome_options(
223223
chrome_options.add_argument("--homepage=about:blank")
224224
chrome_options.add_argument("--dns-prefetch-disable")
225225
chrome_options.add_argument("--dom-automation")
226+
chrome_options.add_argument("--disable-hang-monitor")
227+
chrome_options.add_argument("--disable-prompt-on-repost")
226228
if not use_auto_ext: # (It's ON by default. Disable it when not wanted.)
227229
chrome_options.add_experimental_option("useAutomationExtension", False)
228230
if (settings.DISABLE_CSP_ON_CHROME or disable_csp) and not headless:
@@ -695,9 +697,11 @@ def get_local_driver(
695697
print("\nWarning: msedgedriver not found. Installing now:")
696698
sb_install.main(override="edgedriver")
697699
sys.argv = sys_args # Put back the original sys args
700+
# For Microsoft Edge (Chromium) version 79 or lower
698701
return webdriver.Chrome(executable_path=LOCAL_EDGEDRIVER,
699702
options=chrome_options)
700703
except Exception:
704+
# For Microsoft Edge (Chromium) version 80 or higher
701705
from msedge.selenium_tools import Edge, EdgeOptions
702706
if LOCAL_EDGEDRIVER and os.path.exists(LOCAL_EDGEDRIVER):
703707
try:
@@ -707,6 +711,18 @@ def get_local_driver(
707711
" executable: %s" % e)
708712
edge_options = EdgeOptions()
709713
edge_options.use_chromium = True
714+
prefs = {
715+
"download.default_directory": downloads_path,
716+
"local_discovery.notifications_enabled": False,
717+
"credentials_enable_service": False,
718+
"profile": {
719+
"password_manager_enabled": False
720+
}
721+
}
722+
if block_images:
723+
prefs["profile.managed_default_content_settings.images"] = 2
724+
edge_options.add_experimental_option("prefs", prefs)
725+
edge_options.add_experimental_option("w3c", True)
710726
edge_options.add_experimental_option(
711727
"useAutomationExtension", False)
712728
edge_options.add_experimental_option(
@@ -734,13 +750,36 @@ def get_local_driver(
734750
edge_options.add_experimental_option(
735751
"mobileEmulation", emulator_settings)
736752
edge_options.add_argument("--enable-sync")
753+
edge_options.add_argument("--disable-infobars")
754+
edge_options.add_argument("--disable-save-password-bubble")
755+
edge_options.add_argument("--disable-single-click-autofill")
756+
edge_options.add_argument("--disable-translate")
757+
edge_options.add_argument("--disable-web-security")
758+
edge_options.add_argument("--homepage=about:blank")
759+
edge_options.add_argument("--dns-prefetch-disable")
760+
edge_options.add_argument("--dom-automation")
761+
edge_options.add_argument("--disable-hang-monitor")
762+
edge_options.add_argument("--disable-prompt-on-repost")
737763
if proxy_string:
738-
if proxy_auth:
739-
edge_options = _add_chrome_proxy_extension(
740-
edge_options, proxy_string, proxy_user, proxy_pass)
741764
edge_options.add_argument('--proxy-server=%s' % proxy_string)
765+
edge_options.add_argument("--test-type")
766+
edge_options.add_argument("--log-level=3")
767+
edge_options.add_argument("--no-first-run")
768+
edge_options.add_argument("--ignore-certificate-errors")
769+
if devtools and not headless:
770+
edge_options.add_argument("--auto-open-devtools-for-tabs")
771+
edge_options.add_argument("--allow-file-access-from-files")
772+
edge_options.add_argument("--allow-insecure-localhost")
773+
edge_options.add_argument("--allow-running-insecure-content")
742774
if user_agent:
743775
edge_options.add_argument("--user-agent=%s" % user_agent)
776+
edge_options.add_argument("--no-sandbox")
777+
if swiftshader:
778+
edge_options.add_argument("--use-gl=swiftshader")
779+
else:
780+
edge_options.add_argument("--disable-gpu")
781+
if "linux" in PLATFORM:
782+
edge_options.add_argument("--disable-dev-shm-usage")
744783
capabilities = edge_options.to_capabilities()
745784
capabilities["platform"] = ''
746785
return Edge(

0 commit comments

Comments
 (0)