Skip to content

Commit

Permalink
[chores] Use SeleniumTestMixin from openwisp-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed May 24, 2023
1 parent 2d6e4e6 commit 4310967
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
21 changes: 11 additions & 10 deletions openwisp_network_topology/tests/test_selenium.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -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"
)
Expand Down
3 changes: 1 addition & 2 deletions requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4310967

Please sign in to comment.