From 075ffca0e2c1a80e4eef32e75e7b9172c0bb6bd5 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 9 Jul 2018 20:59:03 -0400 Subject: [PATCH] Handle catching Javascript exceptions in a unified way --- test/conftest.py | 8 ++++++++ test/test_python.py | 8 +++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/test/conftest.py b/test/conftest.py index 302d61641..fe50ee3dd 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -73,9 +73,13 @@ class FirefoxWrapper(SeleniumWrapper): def get_driver(self): from selenium.webdriver import Firefox from selenium.webdriver.firefox.options import Options + from selenium.common.exceptions import JavascriptException options = Options() options.add_argument('-headless') + + self.JavascriptException = JavascriptException + return Firefox( executable_path='geckodriver', firefox_options=options) @@ -84,9 +88,13 @@ class ChromeWrapper(SeleniumWrapper): def get_driver(self): from selenium.webdriver import Chrome from selenium.webdriver.chrome.options import Options + from selenium.common.exceptions import WebDriverException options = Options() options.add_argument('--headless') + + self.JavascriptException = WebDriverException + return Chrome(chrome_options=options) diff --git a/test/test_python.py b/test/test_python.py index d47fc20ed..e8ac04f69 100644 --- a/test/test_python.py +++ b/test/test_python.py @@ -2,8 +2,6 @@ import os import pathlib import time -from selenium.common.exceptions import JavascriptException - def test_init(selenium): assert 'Python initialization complete' in selenium.logs @@ -50,7 +48,7 @@ def test_python2js(selenium): def test_pythonexc2js(selenium): try: selenium.run_js('return pyodide.runPython("5 / 0")') - except JavascriptException as e: + except selenium.JavascriptException as e: assert('ZeroDivisionError' in str(e)) else: assert False, 'Expected exception' @@ -147,7 +145,7 @@ def test_pyproxy_destroy(selenium): "console.assert(f.get_value(1) === 64);\n" "f.destroy();\n" "f.get_value();\n") - except JavascriptException as e: + except selenium.JavascriptException as e: assert 'Object has already been destroyed' in str(e) else: assert False, 'Expected exception' @@ -186,7 +184,7 @@ def test_run_core_python_test(python_test, selenium): selenium.run( "from test.libregrtest import main\n" "main(['{}'], verbose=True, verbose3=True)".format(python_test)) - except JavascriptException as e: + except selenium.JavascriptException as e: assert str(e).strip().endswith('SystemExit: 0')