Skip to content

Commit 00d49f1

Browse files
committed
[tests] Added basic test for chrome
1 parent 3a2423c commit 00d49f1

File tree

2 files changed

+20
-17
lines changed

2 files changed

+20
-17
lines changed

openwisp_utils/tests/selenium.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from selenium import webdriver
44
from selenium.common.exceptions import TimeoutException
55
from selenium.webdriver.common.by import By
6-
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
76
from selenium.webdriver.firefox.options import Options
87
from selenium.webdriver.support import expected_conditions as EC
98
from selenium.webdriver.support.ui import WebDriverWait
@@ -80,15 +79,15 @@ def get_firefox_webdriver(cls):
8079

8180
@classmethod
8281
def get_chrome_webdriver(cls):
83-
chrome_options = webdriver.ChromeOptions()
84-
chrome_options.page_load_strategy = 'eager'
82+
options = webdriver.ChromeOptions()
83+
options.page_load_strategy = 'eager'
8584
if os.environ.get('SELENIUM_HEADLESS', False):
86-
chrome_options.add_argument('--headless')
85+
options.add_argument('--headless')
8786
CHROME_BIN = os.environ.get('CHROME_BIN', None)
8887
if CHROME_BIN:
89-
chrome_options.binary_location = CHROME_BIN
90-
chrome_options.add_argument('--window-size=1366,768')
91-
chrome_options.add_argument('--ignore-certificate-errors')
88+
options.binary_location = CHROME_BIN
89+
options.add_argument('--window-size=1366,768')
90+
options.add_argument('--ignore-certificate-errors')
9291
# When running Selenium tests with the "--parallel" flag,
9392
# each TestCase class requires its own browser instance.
9493
# If the same "remote-debugging-port" is used for all
@@ -97,16 +96,11 @@ def get_chrome_webdriver(cls):
9796
# debugging ports for each TestCase. To accomplish this,
9897
# we can leverage the randomized live test server port to
9998
# generate a unique port for each browser instance.
100-
chrome_options.add_argument(
101-
f'--remote-debugging-port={cls.server_thread.port + 100}'
99+
options.add_argument(f'--remote-debugging-port={cls.server_thread.port + 100}')
100+
options.set_capability('goog:loggingPrefs', {'browser': 'ALL'})
101+
return webdriver.Chrome(
102+
options=options,
102103
)
103-
capabilities = DesiredCapabilities.CHROME
104-
capabilities['goog:loggingPrefs'] = {'browser': 'ALL'}
105-
chrome_options.set_capability('cloud:options', capabilities)
106-
web_driver = webdriver.Chrome(
107-
options=chrome_options,
108-
)
109-
return web_driver
110104

111105
@classmethod
112106
def tearDownClass(cls):

tests/test_project/tests/test_selenium.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ def test_autocomplete_owner_filter(self):
708708
)
709709

710710

711-
class TestSeleniumHelpers(SeleniumTestMixin, CreateMixin, StaticLiveServerTestCase):
711+
class TestFirefoxSeleniumHelpers(SeleniumTestMixin, StaticLiveServerTestCase):
712712
def setUp(self):
713713
super().setUp()
714714
self.login()
@@ -736,3 +736,12 @@ def test_get_browser_logs(self):
736736
self.assertEqual(
737737
self.get_browser_logs(), [{'level': 'INFO', 'message': 'test'}]
738738
)
739+
740+
741+
class TestChromeSeleniumHelpers(SeleniumTestMixin, StaticLiveServerTestCase):
742+
browser = 'chrome'
743+
744+
def test_get_browser_logs(self):
745+
self.assertEqual(self.get_browser_logs(), [])
746+
self.web_driver.execute_script('console.log("test")')
747+
self.assertEqual(len(self.get_browser_logs()), 1)

0 commit comments

Comments
 (0)