From 338f28d60bdd44f3cc2de9e2209a1d2b3327f9b9 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 23 Jan 2022 23:38:46 -0500 Subject: [PATCH 1/5] Add "--external-pdf" option to open PDFs externally --- examples/raw_parameter_script.py | 1 + seleniumbase/core/browser_launcher.py | 14 ++++++++++++++ seleniumbase/fixtures/base_case.py | 7 +++++++ seleniumbase/plugins/pytest_plugin.py | 21 +++++++++++++++++---- seleniumbase/plugins/selenium_plugin.py | 16 ++++++++++++++-- 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/examples/raw_parameter_script.py b/examples/raw_parameter_script.py index 32b86c7814e..392e3a5e572 100755 --- a/examples/raw_parameter_script.py +++ b/examples/raw_parameter_script.py @@ -82,6 +82,7 @@ sb._dash_initialized = False sb.message_duration = 2 sb.block_images = False + sb.external_pdf = False sb.remote_debug = False sb.settings_file = None sb.user_data_dir = None diff --git a/seleniumbase/core/browser_launcher.py b/seleniumbase/core/browser_launcher.py index 581853a51f4..ec7b3e46757 100755 --- a/seleniumbase/core/browser_launcher.py +++ b/seleniumbase/core/browser_launcher.py @@ -273,6 +273,7 @@ def _set_chrome_options( user_data_dir, extension_zip, extension_dir, + external_pdf, servername, mobile_emulator, device_width, @@ -302,6 +303,8 @@ def _set_chrome_options( prefs["intl.accept_languages"] = locale_code if block_images: prefs["profile.managed_default_content_settings.images"] = 2 + if external_pdf: + prefs["plugins.always_open_pdf_externally"] = True chrome_options.add_experimental_option("prefs", prefs) chrome_options.add_experimental_option("w3c", True) if enable_sync: @@ -728,6 +731,7 @@ def get_driver( user_data_dir=None, extension_zip=None, extension_dir=None, + external_pdf=None, test_id=None, mobile_emulator=False, device_width=None, @@ -803,6 +807,7 @@ def get_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, test_id, mobile_emulator, device_width, @@ -841,6 +846,7 @@ def get_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, mobile_emulator, device_width, device_height, @@ -883,6 +889,7 @@ def get_remote_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, test_id, mobile_emulator, device_width, @@ -971,6 +978,7 @@ def get_remote_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, servername, mobile_emulator, device_width, @@ -1298,6 +1306,7 @@ def get_local_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, mobile_emulator, device_width, device_height, @@ -1490,6 +1499,8 @@ def get_local_driver( prefs["intl.accept_languages"] = locale_code if block_images: prefs["profile.managed_default_content_settings.images"] = 2 + if external_pdf: + prefs["plugins.always_open_pdf_externally"] = True edge_options.add_experimental_option("prefs", prefs) edge_options.add_experimental_option("w3c", True) edge_options.add_argument( @@ -1738,6 +1749,7 @@ def get_local_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, servername, mobile_emulator, device_width, @@ -1791,6 +1803,7 @@ def get_local_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, servername, mobile_emulator, device_width, @@ -1888,6 +1901,7 @@ def get_local_driver( user_data_dir, extension_zip, extension_dir, + external_pdf, servername, mobile_emulator, device_width, diff --git a/seleniumbase/fixtures/base_case.py b/seleniumbase/fixtures/base_case.py index c03d8188dee..5470d35eeaf 100755 --- a/seleniumbase/fixtures/base_case.py +++ b/seleniumbase/fixtures/base_case.py @@ -2762,6 +2762,7 @@ def get_new_driver( user_data_dir=None, extension_zip=None, extension_dir=None, + external_pdf=None, is_mobile=None, d_width=None, d_height=None, @@ -2803,6 +2804,7 @@ def get_new_driver( user_data_dir - Chrome's User Data Directory to use (Chrome-only) extension_zip - A Chrome Extension ZIP file to use (Chrome-only) extension_dir - A Chrome Extension folder to use (Chrome-only) + external_pdf - "plugins.always_open_pdf_externally": True. (Chrome) is_mobile - the option to use the mobile emulator (Chrome-only) d_width - the device width of the mobile emulator (Chrome-only) d_height - the device height of the mobile emulator (Chrome-only) @@ -2899,6 +2901,8 @@ def get_new_driver( extension_zip = self.extension_zip if extension_dir is None: extension_dir = self.extension_dir + if external_pdf is None: + external_pdf = self.external_pdf test_id = self.__get_test_id() if cap_file is None: cap_file = self.cap_file @@ -2954,6 +2958,7 @@ def get_new_driver( user_data_dir=user_data_dir, extension_zip=extension_zip, extension_dir=extension_dir, + external_pdf=external_pdf, test_id=test_id, mobile_emulator=is_mobile, device_width=d_width, @@ -10899,6 +10904,7 @@ def setUp(self, masterqa_mode=False): self.user_data_dir = sb_config.user_data_dir self.extension_zip = sb_config.extension_zip self.extension_dir = sb_config.extension_dir + self.external_pdf = sb_config.external_pdf self.maximize_option = sb_config.maximize_option self.save_screenshot_after_test = sb_config.save_screenshot self.visual_baseline = sb_config.visual_baseline @@ -11159,6 +11165,7 @@ def setUp(self, masterqa_mode=False): user_data_dir=self.user_data_dir, extension_zip=self.extension_zip, extension_dir=self.extension_dir, + external_pdf=self.external_pdf, is_mobile=self.mobile_emulator, d_width=self.__device_width, d_height=self.__device_height, diff --git a/seleniumbase/plugins/pytest_plugin.py b/seleniumbase/plugins/pytest_plugin.py index 12ca726f602..854448026f1 100644 --- a/seleniumbase/plugins/pytest_plugin.py +++ b/seleniumbase/plugins/pytest_plugin.py @@ -81,6 +81,7 @@ def pytest_addoption(parser): --maximize (Start tests with the web browser window maximized.) --save-screenshot (Save a screenshot at the end of each test.) --visual-baseline (Set the visual baseline for Visual/Layout tests.) + --external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.) --timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.) """ c1 = "" @@ -831,8 +832,8 @@ def pytest_addoption(parser): dest="crumbs", default=False, help="""The option to delete all cookies between tests - that reuse the same browser session. This option - is only needed when using "--reuse-session".""", + that reuse the same browser session. This option + is only needed when using "--reuse-session".""", ) parser.addoption( "--maximize_window", @@ -853,8 +854,8 @@ def pytest_addoption(parser): action="store_true", dest="save_screenshot", default=False, - help="""Take a screenshot on last page after the last step - of the test. (Added to the "latest_logs" folder.)""", + help="""Save a screenshot at the end of the test. + (Added to the "latest_logs/" folder.)""", ) parser.addoption( "--visual_baseline", @@ -867,6 +868,17 @@ def pytest_addoption(parser): When a test calls self.check_window(), it will rebuild its files in the visual_baseline folder.""", ) + parser.addoption( + "--external_pdf", + "--external-pdf", + action="store_true", + dest="external_pdf", + default=False, + help="""This option sets the following on Chromium: + "plugins.always_open_pdf_externally": True, + which causes opened PDF URLs to download immediately, + instead of being displayed in the browser window.""", + ) parser.addoption( "--timeout_multiplier", "--timeout-multiplier", @@ -1114,6 +1126,7 @@ def pytest_configure(config): sb_config.maximize_option = config.getoption("maximize_option") sb_config.save_screenshot = config.getoption("save_screenshot") sb_config.visual_baseline = config.getoption("visual_baseline") + sb_config.external_pdf = config.getoption("external_pdf") sb_config.timeout_multiplier = config.getoption("timeout_multiplier") sb_config._is_timeout_changed = False sb_config._SMALL_TIMEOUT = settings.SMALL_TIMEOUT diff --git a/seleniumbase/plugins/selenium_plugin.py b/seleniumbase/plugins/selenium_plugin.py index 2b2ec5eea7a..8e7213bcee3 100755 --- a/seleniumbase/plugins/selenium_plugin.py +++ b/seleniumbase/plugins/selenium_plugin.py @@ -60,6 +60,7 @@ class SeleniumBrowser(Plugin): --maximize (Start tests with the web browser window maximized.) --save-screenshot (Save a screenshot at the end of each test.) --visual-baseline (Set the visual baseline for Visual/Layout tests.) + --external-pdf (Set Chromium "plugins.always_open_pdf_externally": True.) --timeout-multiplier=MULTIPLIER (Multiplies the default timeout values.) """ @@ -585,8 +586,7 @@ def options(self, parser, env): action="store_true", dest="save_screenshot", default=False, - help="""(DEPRECATED) - Screenshots are enabled by default now. - This option saves screenshots during test failures. + help="""Save a screenshot at the end of the test. (Added to the "latest_logs/" folder.)""", ) parser.add_option( @@ -600,6 +600,17 @@ def options(self, parser, env): When a test calls self.check_window(), it will rebuild its files in the visual_baseline folder.""", ) + parser.add_option( + "--external_pdf", + "--external-pdf", + action="store_true", + dest="external_pdf", + default=False, + help="""This option sets the following on Chromium: + "plugins.always_open_pdf_externally": True, + which causes opened PDF URLs to download immediately, + instead of being displayed in the browser window.""", + ) parser.add_option( "--timeout_multiplier", "--timeout-multiplier", @@ -677,6 +688,7 @@ def beforeTest(self, test): test.test.maximize_option = self.options.maximize_option test.test.save_screenshot_after_test = self.options.save_screenshot test.test.visual_baseline = self.options.visual_baseline + test.test.external_pdf = self.options.external_pdf test.test.timeout_multiplier = self.options.timeout_multiplier test.test.dashboard = False test.test._multithreaded = False From 27d92afc2a5ccc4be917e7c3b3b9d32b873ea4d0 Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 23 Jan 2022 23:39:50 -0500 Subject: [PATCH 2/5] Update the docs --- README.md | 1 + help_docs/customizing_test_runs.md | 1 + mkdocs_build/requirements.txt | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 005de5cf681..97d15ff5db8 100755 --- a/README.md +++ b/README.md @@ -351,6 +351,7 @@ The code above will leave your browser window open in case there's a failure. (i --maximize-window # (Start tests with the web browser window maximized.) --save-screenshot # (Save a screenshot at the end of each test.) --visual-baseline # (Set the visual baseline for Visual/Layout tests.) +--external-pdf # (Set Chrome "plugins.always_open_pdf_externally": True.) --timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.) ``` diff --git a/help_docs/customizing_test_runs.md b/help_docs/customizing_test_runs.md index 99d15fb144f..a748da70fbe 100755 --- a/help_docs/customizing_test_runs.md +++ b/help_docs/customizing_test_runs.md @@ -164,6 +164,7 @@ SeleniumBase provides additional ``pytest`` command-line options for tests: --maximize-window # (Start tests with the web browser window maximized.) --save-screenshot # (Save a screenshot at the end of each test.) --visual-baseline # (Set the visual baseline for Visual/Layout tests.) +--external-pdf # (Set Chrome "plugins.always_open_pdf_externally": True.) --timeout-multiplier=MULTIPLIER # (Multiplies the default timeout values.) ``` diff --git a/mkdocs_build/requirements.txt b/mkdocs_build/requirements.txt index 2020433f46f..3d805e05e21 100644 --- a/mkdocs_build/requirements.txt +++ b/mkdocs_build/requirements.txt @@ -6,7 +6,7 @@ livereload==2.6.3;python_version>="3.6" joblib==1.1.0;python_version>="3.6" Markdown==3.3.6;python_version>="3.6" MarkupSafe==2.0.1;python_version>="3.6" -pyparsing==3.0.6;python_version>="3.6" +pyparsing==3.0.7;python_version>="3.6" keyring==23.5.0;python_version>="3.7" pkginfo==1.8.2;python_version>="3.6" Jinja2==3.0.3;python_version>="3.6" @@ -21,7 +21,7 @@ lunr==0.6.1;python_version>="3.6" nltk==3.6.7;python_version>="3.6" watchdog==2.1.6;python_version>="3.6" mkdocs==1.2.3;python_version>="3.6" -mkdocs-material==8.1.7;python_version>="3.6" +mkdocs-material==8.1.8;python_version>="3.6" mkdocs-exclude-search==0.6.4;python_version>="3.6" mkdocs-simple-hooks==0.1.5 mkdocs-material-extensions==1.0.3;python_version>="3.6" From 26af2b2f130fdaddca7154ff6f29f07bdaf0b6af Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 23 Jan 2022 23:40:56 -0500 Subject: [PATCH 3/5] Pin a Python dependency --- requirements.txt | 1 + setup.py | 1 + 2 files changed, 2 insertions(+) diff --git a/requirements.txt b/requirements.txt index 6d18d74d45b..93886c41dc2 100755 --- a/requirements.txt +++ b/requirements.txt @@ -135,6 +135,7 @@ pytest-cov==3.0.0;python_version>="3.6" flake8==3.7.9;python_version<"3.5" flake8==3.9.2;python_version>="3.5" and python_version<"3.6" flake8==4.0.1;python_version>="3.6" +mccabe==0.6.1 pyflakes==2.1.1;python_version<"3.5" pyflakes==2.3.1;python_version>="3.5" and python_version<"3.6" pyflakes==2.4.0;python_version>="3.6" diff --git a/setup.py b/setup.py index e92ef476e42..5d883621b79 100755 --- a/setup.py +++ b/setup.py @@ -263,6 +263,7 @@ 'flake8==3.7.9;python_version<"3.5"', 'flake8==3.9.2;python_version>="3.5" and python_version<"3.6"', 'flake8==4.0.1;python_version>="3.6"', + 'mccabe==0.6.1', 'pyflakes==2.1.1;python_version<"3.5"', 'pyflakes==2.3.1;python_version>="3.5" and python_version<"3.6"', 'pyflakes==2.4.0;python_version>="3.6"', From c35a37f369bb87967193cceeac43a3a76f8faa0a Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 23 Jan 2022 23:41:12 -0500 Subject: [PATCH 4/5] Refresh Python dependencies --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 93886c41dc2..c7f73781ac1 100755 --- a/requirements.txt +++ b/requirements.txt @@ -94,7 +94,7 @@ decorator==5.1.1;python_version>="3.5" ipython==5.10.0;python_version<"3.5" ipython==7.9.0;python_version>="3.5" and python_version<"3.6" ipython==7.16.1;python_version>="3.6" and python_version<"3.7" -ipython==7.31.0;python_version>="3.7" +ipython==7.31.1;python_version>="3.7" matplotlib-inline==0.1.3;python_version>="3.7" colorama==0.4.4 platformdirs==2.0.2;python_version<"3.6" diff --git a/setup.py b/setup.py index 5d883621b79..ce6e75ce371 100755 --- a/setup.py +++ b/setup.py @@ -219,7 +219,7 @@ 'ipython==5.10.0;python_version<"3.5"', 'ipython==7.9.0;python_version>="3.5" and python_version<"3.6"', 'ipython==7.16.1;python_version>="3.6" and python_version<"3.7"', - 'ipython==7.31.0;python_version>="3.7"', # Requires matplotlib-inline + 'ipython==7.31.1;python_version>="3.7"', # Requires matplotlib-inline 'matplotlib-inline==0.1.3;python_version>="3.7"', # ipython needs this "colorama==0.4.4", 'platformdirs==2.0.2;python_version<"3.6"', From 0bd4410ca74d3765822d389dd41f86b90c375dbc Mon Sep 17 00:00:00 2001 From: Michael Mintz Date: Sun, 23 Jan 2022 23:41:27 -0500 Subject: [PATCH 5/5] Version 2.4.1 --- seleniumbase/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index afcbf9c9608..341c1a98bf8 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "2.4.0" +__version__ = "2.4.1"