Skip to content

Commit

Permalink
[tests] Improve Selenium test efficiency #868
Browse files Browse the repository at this point in the history
Refactored WebDriverWait usage to use built-in expected conditions.

Fixes #868
  • Loading branch information
dee077 committed Jan 22, 2025
1 parent 937f2f2 commit ade1905
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions openwisp_controller/config/tests/test_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,11 @@ def test_create_new_device(self):
)

def test_device_preview_keyboard_shortcuts(self):
self._create_config(device=self._create_device(name='Test'))
device = self._create_config(device=self._create_device(name='Test')).device
self.login()
self.open(reverse('admin:config_device_changelist'))

# open first device in the list
self.web_driver.find_element(
by=By.CSS_SELECTOR, value='tbody tr:nth-child(1) th a'
).click()
try:
WebDriverWait(self.web_driver, 2).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#content-main'))
)
self.open(reverse('admin:config_device_change', args=[device.id]))
except TimeoutException:
self.fail('Device detail page did not load in time')

Expand All @@ -153,10 +146,9 @@ def test_device_preview_keyboard_shortcuts(self):
actions.key_down(Keys.ALT).send_keys('p').key_up(Keys.ALT).perform()
try:
WebDriverWait(self.web_driver, 2).until(
lambda driver: driver.find_element(
By.CSS_SELECTOR, '.djnjc-overlay:not(.loading)'
).value_of_css_property('display')
!= 'none'
EC.invisibility_of_element_located(
(By.CSS_SELECTOR, '.djnjc-overlay:not(.loading)')
)
)
except TimeoutException:
self.fail('The preview overlay is unexpectedly not visible')
Expand All @@ -166,10 +158,9 @@ def test_device_preview_keyboard_shortcuts(self):
actions.send_keys(Keys.ESCAPE).perform()
try:
WebDriverWait(self.web_driver, 2).until(
lambda driver: driver.find_element(
By.CSS_SELECTOR, '.djnjc-overlay:not(.loading)'
).value_of_css_property('display')
== 'none'
EC.invisibility_of_element_located(
(By.CSS_SELECTOR, '.djnjc-overlay:not(.loading)')
)
)
except TimeoutException:
self.fail('The preview overlay has not been closed as expected')
Expand Down

0 comments on commit ade1905

Please sign in to comment.