Skip to content
Snippets Groups Projects
Commit ad6beb6c authored by Marc Egger's avatar Marc Egger
Browse files

Refs #11035 clean up selenium tests

parent 64db22fa
No related branches found
No related tags found
2 merge requests!302Develop,!296Marc: Form/Report As File, Path class, Config class, Typo3 v9 compatability
Pipeline #3749 failed
......@@ -41,6 +41,7 @@ class QfqSeleniumTestCase(unittest.TestCase):
gecko_driver_path = "geckodriver"
chrome_browser_name = "chrome"
chrome_driver_path = "chromedriver"
alert_button_press_delay_seconds = 0.5 # NOTE Window freezes if button is clicked to fast
# these variables can be overwritten by environment variables of the same name
SELENIUM_BROWSER = chrome_browser_name
......@@ -109,7 +110,7 @@ class QfqSeleniumTestCase(unittest.TestCase):
capabilities=desired_capabilities)
cls.driver.set_window_size(1920, 1080)
cls.driver.implicitly_wait(30)
cls.driver.implicitly_wait(5)
@classmethod
def tearDownClass(cls):
......@@ -208,6 +209,15 @@ class QfqSeleniumTestCase(unittest.TestCase):
"""
self.assertFalse(bool)
def qfq_assert_header_exists(self, text):
"""
Assert whether a header (h1 tag) with given text is present.
"""
try:
self.qfq_get_element_by_tag_and_text('h1', text)
except TimeoutException:
raise AssertionError("Header (<h1>) with given text not found: " + text)
def qfq_assert_element_visible(self, data_reference):
"""
Asserts that the element with the given data_reference is visible to the user.
......@@ -272,6 +282,12 @@ class QfqSeleniumTestCase(unittest.TestCase):
else:
raise ValueError("The element with the given selector is not visible on screen")
def qfq_get_element_by_tag_and_text(self, element_tag, text):
"""
Return element with given tag and text. Text must be exactly equal.
"""
return self.qfq_get_element_by_xpath("//" + element_tag + "[text()='" + text + "']")
# ----- ACTIONS ----- #
@_slow_available
......@@ -283,7 +299,7 @@ class QfqSeleniumTestCase(unittest.TestCase):
self.driver.get(url)
@_slow_available
def qfq_fill_textfield(self, data_reference, text):
def qfq_fill_text_field(self, data_reference, text):
"""
fills a given string into a text field which
is identified by the given data reference
......@@ -383,12 +399,34 @@ class QfqSeleniumTestCase(unittest.TestCase):
"""
self.qfq_click_element_with_id('save-button')
def qfq_alert_click_ok(self):
def qfq_click_alert_ok(self):
"""
Clicks the OK button on a QFQ alert.
"""
self.qfq_wait(self.alert_button_press_delay_seconds)
self.qfq_click_element_with_text("button", "Ok")
def qfq_click_alert_cancel(self):
"""
Clicks the cancel button on a QFQ alert.
"""
self.qfq_wait(self.alert_button_press_delay_seconds)
self.qfq_click_element_with_text("button", "Cancel")
def qfq_click_alert_yes(self):
"""
Clicks the yes button on a QFQ alert.
"""
self.qfq_wait(self.alert_button_press_delay_seconds)
self.qfq_click_element_with_text("button", "Yes")
def qfq_click_alert_no(self):
"""
Clicks the no button on a QFQ alert.
"""
self.qfq_wait(self.alert_button_press_delay_seconds)
self.qfq_click_element_with_text("button", "No")
@_slow_available
def qfq_click_element_with_text(self, element_tag, text):
"""
......@@ -396,9 +434,7 @@ class QfqSeleniumTestCase(unittest.TestCase):
the given text
"""
def f():
self.qfq_get_element_by_xpath(
"//" + element_tag + "[text()='" + text + "']"
).click()
self.qfq_get_element_by_tag_and_text(element_tag, text).click()
self._retry_on_certain_exceptions(f)
@_slow_available
......
#!/bin/bash
# run a single test function. e.g. "test_basic_functionality.TestBasicFunctionality.test_qfq_form_switch_pill"
TEST_FUNCTION="test_basic_functionality.TestBasicFunctionality.test_qfq_form_switch_pill" # NOTE: make sure there are no trailing spaces!
export SELENIUM_URL="https://webwork16.math.uzh.ch/megger/qfq/typo3conf/ext/qfq/NoT3Page"
export SELENIUM_BROWSER="chrome"
export SELENIUM_DRIVER_PATH="${PWD}/chromedriver"
export SELENIUM_HEADLESS="no"
export SELENIUM_SLOWDOWN=0
# download chromedriver (Chrome)
if [ ! -f "chromedriver" ]; then
wget -O /tmp/chromedriver.zip http://chromedriver.storage.googleapis.com/`curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE`/chromedriver_linux64.zip &> /dev/null
unzip /tmp/chromedriver.zip chromedriver &> /dev/null
chmod +x chromedriver &> /dev/null
echo -e "Successfully downloaded chromedriver"
fi
if [ -z "$TEST_FUNCTION" ]; then
python3 -W ignore -m unittest discover
else
python3 -W ignore -m unittest "$TEST_FUNCTION"
fi
exit 0
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment