|
15 | 15 | from openwisp_controller.connection.tests.utils import CreateConnectionsMixin |
16 | 16 | from openwisp_controller.geo.tests.utils import TestGeoMixin |
17 | 17 |
|
18 | | -from .utils import SeleniumTestMixin |
19 | | - |
20 | 18 | Device = load_model('config', 'Device') |
21 | 19 | DeviceConnection = load_model('connection', 'DeviceConnection') |
22 | 20 | Location = load_model('geo', 'Location') |
23 | 21 | DeviceLocation = load_model('geo', 'DeviceLocation') |
24 | 22 |
|
25 | 23 |
|
| 24 | +class SeleniumTestMixin: |
| 25 | + """ |
| 26 | + A base test case for Selenium, providing helped methods for generating |
| 27 | + clients and logging in profiles. |
| 28 | + """ |
| 29 | + |
| 30 | + def open(self, url, driver=None): |
| 31 | + """ |
| 32 | + Opens a URL |
| 33 | + Argument: |
| 34 | + url: URL to open |
| 35 | + driver: selenium driver (default: cls.base_driver) |
| 36 | + """ |
| 37 | + if not driver: |
| 38 | + driver = self.web_driver |
| 39 | + driver.get(f'{self.live_server_url}{url}') |
| 40 | + |
| 41 | + def login(self, username=None, password=None, driver=None): |
| 42 | + """ |
| 43 | + Log in to the admin dashboard |
| 44 | + Argument: |
| 45 | + driver: selenium driver (default: cls.web_driver) |
| 46 | + username: username to be used for login (default: cls.admin.username) |
| 47 | + password: password to be used for login (default: cls.admin.password) |
| 48 | + """ |
| 49 | + if not driver: |
| 50 | + driver = self.web_driver |
| 51 | + if not username: |
| 52 | + username = self.admin_username |
| 53 | + if not password: |
| 54 | + password = self.admin_password |
| 55 | + driver.get(f'{self.live_server_url}/admin/login/') |
| 56 | + if 'admin/login' in driver.current_url: |
| 57 | + driver.find_element(by=By.NAME, value='username').send_keys(username) |
| 58 | + driver.find_element(by=By.NAME, value='password').send_keys(password) |
| 59 | + driver.find_element(by=By.XPATH, value='//input[@type="submit"]').click() |
| 60 | + |
| 61 | + |
26 | 62 | class TestDeviceConnectionInlineAdmin( |
27 | 63 | CreateConnectionsMixin, TestGeoMixin, SeleniumTestMixin, StaticLiveServerTestCase |
28 | 64 | ): |
|
0 commit comments