From 4310967dd3ed89fa6ad12765e36afa882d42c8b5 Mon Sep 17 00:00:00 2001 From: Gagan Deep Date: Wed, 24 May 2023 20:23:36 +0530 Subject: [PATCH] [chores] Use SeleniumTestMixin from openwisp-utils --- .../tests/test_selenium.py | 21 ++++++++++--------- requirements-test.txt | 3 +-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/openwisp_network_topology/tests/test_selenium.py b/openwisp_network_topology/tests/test_selenium.py index c72be2af..1fab8de4 100644 --- a/openwisp_network_topology/tests/test_selenium.py +++ b/openwisp_network_topology/tests/test_selenium.py @@ -1,7 +1,6 @@ from django.conf import settings from django.contrib.staticfiles.testing import StaticLiveServerTestCase from django.urls import reverse -from openwisp_controller.tests.utils import SeleniumTestMixin from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.desired_capabilities import DesiredCapabilities @@ -10,6 +9,7 @@ from swapper import load_model from openwisp_users.tests.utils import TestOrganizationMixin +from openwisp_utils.test_selenium_mixins import SeleniumTestMixin from .utils import CreateGraphObjectsMixin, LoadMixin @@ -26,8 +26,6 @@ class TestTopologyGraphVisualizer( StaticLiveServerTestCase, ): app_label = 'topology' - admin_username = 'admin' - admin_password = 'password' node_model = Node link_model = Link topology_model = Topology @@ -40,23 +38,26 @@ def prefix(self): @classmethod def setUpClass(cls): super().setUpClass() + cls.web_driver.quit() + # Workaround for https://github.com/openwisp/openwisp-network-topology/issues/193 + # The "automation" info-bar causes the visualizer to error. + # TODO: Remove this when the bug is fixed. chrome_options = webdriver.ChromeOptions() if getattr(settings, 'SELENIUM_HEADLESS', True): chrome_options.add_argument('--headless') chrome_options.add_argument('--window-size=1366,768') chrome_options.add_argument('--ignore-certificate-errors') chrome_options.add_argument('--remote-debugging-port=9222') + # Disable the info-bar in chrome browser + chrome_options.add_experimental_option("useAutomationExtension", False) + chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"]) capabilities = DesiredCapabilities.CHROME capabilities['goog:loggingPrefs'] = {'browser': 'ALL'} cls.web_driver = webdriver.Chrome( - options=chrome_options, desired_capabilities=capabilities + options=chrome_options, + desired_capabilities=capabilities, ) - @classmethod - def tearDownClass(cls): - cls.web_driver.quit() - super().tearDownClass() - def setUp(self): org = self._create_org() self.admin = self._create_admin( @@ -144,7 +145,7 @@ def test_topology_admin_view_graph_visualizer(self): def test_topology_non_admin_view_graph_visualizer(self): path = reverse('topology_list') self.login(username=self.admin_username, password=self.admin_password) - self.open(path) + self.web_driver.get(f'{self.live_server_url}{path}') topology_graph_element = self.web_driver.find_element( By.XPATH, "//ul[@id='menu']/li/a" ) diff --git a/requirements-test.txt b/requirements-test.txt index 96ded011..682dbadf 100644 --- a/requirements-test.txt +++ b/requirements-test.txt @@ -2,8 +2,7 @@ responses~=0.16.0 pytest-asyncio~=0.14.0 pytest-django~=4.5.2 freezegun~=1.1.0 -selenium~=4.9.0 # Needed to test integrations openwisp-monitoring @ https://github.com/openwisp/openwisp-monitoring/tarball/master openwisp-controller @ https://github.com/openwisp/openwisp-controller/tarball/master -openwisp-utils[qa] @ https://github.com/openwisp/openwisp-utils/tarball/master +openwisp-utils[qa,selenium] @ https://github.com/openwisp/openwisp-utils/tarball/master