Skip to content

Commit f57b593

Browse files
committed
[tests] Added wait_for_presence, updated tests to use helpers
1 parent 24e4426 commit f57b593

File tree

2 files changed

+77
-187
lines changed

2 files changed

+77
-187
lines changed

openwisp_utils/test_selenium_mixins.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,23 @@ def login(self, username=None, password=None, driver=None):
8989
driver.find_element(by=By.NAME, value='password').send_keys(password)
9090
driver.find_element(by=By.XPATH, value='//input[@type="submit"]').click()
9191

92-
def find_element(self, by, value, timeout=2):
93-
self.wait_for_visibility(by, value, timeout)
92+
def find_element(self, by, value, timeout=2, wait_for='visibility'):
93+
method = f'wait_for_{wait_for}'
94+
getattr(self, method)(by, value, timeout)
9495
return self.web_driver.find_element(by=by, value=value)
9596

9697
def wait_for_visibility(self, by, value, timeout=2):
97-
self.wait_for('visibility_of_element_located', by, value)
98+
return self.wait_for('visibility_of_element_located', by, value)
9899

99100
def wait_for_invisibility(self, by, value, timeout=2):
100-
self.wait_for('invisibility_of_element_located', by, value)
101+
return self.wait_for('invisibility_of_element_located', by, value)
102+
103+
def wait_for_presence(self, by, value, timeout=2):
104+
return self.wait_for('presence_of_element_located', by, value)
101105

102106
def wait_for(self, method, by, value, timeout=2):
103107
try:
104-
WebDriverWait(self.web_driver, timeout).until(
108+
return WebDriverWait(self.web_driver, timeout).until(
105109
getattr(EC, method)(((by, value)))
106110
)
107111
except TimeoutException as e:

0 commit comments

Comments
 (0)