From d46b11f8dab4eba79ec0c9ddb2dff186ced94032 Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Wed, 19 Feb 2020 14:21:37 +0100 Subject: [PATCH] set "accept_languages" and disable "headless" mode It seems that we can't set "accept_languages" in headless mode, see: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3358 --- django_tools/selenium/chromedriver.py | 9 ++++++++- django_tools_tests/test_unittest_selenium.py | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/django_tools/selenium/chromedriver.py b/django_tools/selenium/chromedriver.py index 45cc670..c02847a 100644 --- a/django_tools/selenium/chromedriver.py +++ b/django_tools/selenium/chromedriver.py @@ -43,7 +43,11 @@ def test_admin_login_page(self): """ filename = "chromedriver" - options = ("--no-sandbox", "--headless", "--disable-gpu") + options = ( + "--no-sandbox", + # "--headless", ## see: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3358 + "--disable-gpu" + ) desired_capabilities = { "loggingPrefs": { "browser": "ALL", @@ -53,12 +57,15 @@ def test_admin_login_page(self): "server": "ALL" } } + accept_languages = 'en' @classmethod def setUpClass(cls): options = webdriver.ChromeOptions() options.add_experimental_option('w3c', False) # needed to get browser logs + options.add_experimental_option('prefs', {'intl.accept_languages': cls.accept_languages}) + for argument in cls.options: options.add_argument(argument) diff --git a/django_tools_tests/test_unittest_selenium.py b/django_tools_tests/test_unittest_selenium.py index cc954d1..35d064c 100644 --- a/django_tools_tests/test_unittest_selenium.py +++ b/django_tools_tests/test_unittest_selenium.py @@ -28,6 +28,7 @@ class ExampleChromiumTests(SeleniumChromiumStaticLiveServerTestCase): def test_admin_login_page(self): self.driver.get(self.live_server_url + "/admin/login/") + assert self.driver.execute_script('return window.navigator.languages') == ['en'] self.assert_equal_page_title("Log in | Django site admin") self.assert_in_page_source('
') self.assert_no_javascript_alert() @@ -37,6 +38,7 @@ def test_admin_login_page(self): class ExampleFirefoxTests(SeleniumFirefoxStaticLiveServerTestCase): def test_admin_login_page(self): self.driver.get(self.live_server_url + "/admin/login/") + assert self.driver.execute_script('return window.navigator.languages') == ['en'] self.assert_equal_page_title("Log in | Django site admin") self.assert_in_page_source('') self.assert_no_javascript_alert()