22import os
33import uuid
44
5- from django .conf import settings
65from django .contrib .auth import get_user_model
76from django .contrib .auth .models import AnonymousUser
8- from selenium import webdriver
7+ from openwisp_utils .test_selenium_mixins import (
8+ SeleniumTestMixin as BaseSeleniumTestMixin ,
9+ )
910from selenium .common .exceptions import NoSuchElementException
1011from selenium .webdriver .common .by import By
11- from selenium .webdriver .common .desired_capabilities import DesiredCapabilities
1212from selenium .webdriver .support import expected_conditions as EC
1313from selenium .webdriver .support .wait import WebDriverWait
1414
@@ -26,44 +26,7 @@ class TestConfigMixin(object):
2626 config = json .load (json_file )
2727
2828
29- class SeleniumTestMixin (TestConfigMixin ):
30- @classmethod
31- def setUpClass (cls ):
32- super ().setUpClass ()
33- chrome_options = webdriver .ChromeOptions ()
34- if getattr (settings , 'SELENIUM_HEADLESS' , True ):
35- chrome_options .add_argument ('--headless' )
36- chrome_options .add_argument ('--window-size=1366,768' )
37- chrome_options .add_argument ('--ignore-certificate-errors' )
38- chrome_options .add_argument ('--remote-debugging-port=9222' )
39- capabilities = DesiredCapabilities .CHROME
40- capabilities ['goog:loggingPrefs' ] = {'browser' : 'ALL' }
41- cls .web_driver = webdriver .Chrome (
42- options = chrome_options ,
43- desired_capabilities = capabilities ,
44- )
45-
46- @classmethod
47- def tearDownClass (cls ):
48- cls .web_driver .quit ()
49- super ().tearDownClass ()
50-
51- def open (self , url , driver = None ):
52- """
53- Opens a URL
54- Argument:
55- url: URL to open
56- driver: selenium driver (default: cls.base_driver)
57- """
58- if not driver :
59- driver = self .web_driver
60- driver .get (f'{ self .live_server_url } { url } ' )
61- WebDriverWait (self .web_driver , 2 ).until (
62- EC .visibility_of_element_located (
63- (By .CSS_SELECTOR , self .config ['main_content_css_selector' ])
64- )
65- )
66-
29+ class SeleniumTestMixin (BaseSeleniumTestMixin , TestConfigMixin ):
6730 def _create_user (self , ** kwargs ):
6831 opts = dict (
6932 username = self .config ['tester_username' ],
@@ -88,27 +51,6 @@ def _create_admin(self, **kwargs):
8851 opts .update (kwargs )
8952 return self ._create_user (** opts )
9053
91- def login (self , username = None , password = None , driver = None ):
92- """
93- Log in to the admin dashboard
94- Argument:
95- driver: selenium driver (default: cls.web_driver)
96- username: username to be used for login (default: cls.admin.username)
97- password: password to be used for login (default: cls.admin.password)
98- """
99- if not driver :
100- driver = self .web_driver
101- if not username :
102- username = self .config ['admin_username' ]
103- if not password :
104- password = self .config ['admin_password' ]
105- url = self .live_server_url + self .config ['login_url' ]
106- driver .get (url )
107- if 'admin/login' in driver .current_url :
108- driver .find_element (By .NAME , 'username' ).send_keys (username )
109- driver .find_element (By .NAME , 'password' ).send_keys (password )
110- driver .find_element (By .XPATH , '//input[@type="submit"]' ).click ()
111-
11254 def logout (self ):
11355 account_button = self ._get_account_button ()
11456 account_button .click ()
0 commit comments