toaster: Rename wait_until_element_clickable -> wait_under_finder_clickable
PATCH 1/5 toaster: Rename wait_until_element_clickable -> wait_under_finder_clickable
We want a version of the function which accepts elements but we need to fix the naming of the finder variant first to stop things getting too consfusing.
--- .../tests/browser/selenium_helpers_base.py | 2 +- .../tests/functional/test_project_page.py | 34 +++++++++---------- .../test_project_page_tab_config.py | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-)
lib/toaster/tests/browser/selenium_helpers_base.py +1 -1
@@ -247,7 +247,7 @@ class SeleniumTestCaseBase(unittest.TestCase): Wait(self.driver, timeout=timeout).until(is_clickable, msg) return self.find(selector) - def wait_until_element_clickable(self, finder, timeout=Wait._TIMEOUT): + def wait_until_finder_clickable(self, finder, timeout=Wait._TIMEOUT): """ Wait until element is clickable """ WebDriverWait(self.driver, timeout=timeout).until(lambda driver: self.driver.execute_script("return jQuery.active == 0")) is_clickable = lambda driver: (finder(driver).is_displayed() and finder(driver).is_enabled())
lib/toaster/tests/functional/test_project_page.py +17 -17
@@ -93,7 +93,7 @@ class TestProjectPageBase(SeleniumFunctionalTestCase): ): # Check edit column finder = lambda driver: self.find(f'#{edit_btn_id}') - edit_column = self.wait_until_element_clickable(finder) + edit_column = self.wait_until_finder_clickable(finder) self.assertTrue(edit_column.is_displayed()) edit_column.click() # Check dropdown is visible
@@ -282,7 +282,7 @@ class TestProjectPage(TestProjectPageBase): # click on "Edit" icon button self.wait_until_visible('#project-name-container') finder = lambda driver: self.find('#project-change-form-toggle') - edit_button = self.wait_until_element_clickable(finder) + edit_button = self.wait_until_finder_clickable(finder) edit_button.click() project_name_input = self.find('#project-name-change-input') self.assertTrue(project_name_input.is_displayed())
@@ -394,7 +394,7 @@ class TestProjectPage(TestProjectPageBase): ) # check "build recipe" button works finder = lambda driver: self.find_all('#softwarerecipestable tbody tr')[0].find_element(By.XPATH, '//td[@class="add-del-layers"]/a') - build_btn = self.wait_until_element_clickable(finder) + build_btn = self.wait_until_finder_clickable(finder) build_btn.click() build_state = wait_until_build(self, 'queued cloning starting parsing failed') lastest_builds = self.driver.find_elements(
@@ -405,7 +405,7 @@ class TestProjectPage(TestProjectPageBase): # Find the latest builds, the last build and then the cancel button finder = lambda driver: driver.find_elements(By.XPATH, '//div[@id="latest-builds"]/div')[0].find_element(By.XPATH, '//span[@class="cancel-build-btn pull-right alert-link"]') - cancel_button = self.wait_until_element_clickable(finder) + cancel_button = self.wait_until_finder_clickable(finder) cancel_button.click() if 'starting' not in build_state: # change build state when cancelled in starting state wait_until_build_cancelled(self)
@@ -453,7 +453,7 @@ class TestProjectPage(TestProjectPageBase): ) # check "Select machine" button works finder = lambda driver: self.find_all('#machinestable tbody tr')[0].find_element(By.XPATH, '//td[@class="add-del-layers"]') - select_btn = self.wait_until_element_clickable(finder) + select_btn = self.wait_until_finder_clickable(finder) select_btn.click() self.wait_until_visible('#project-machine-name') project_machine_name = self.find('#project-machine-name')
@@ -473,7 +473,7 @@ class TestProjectPage(TestProjectPageBase): self.wait_until_visible('#machinestable tbody tr') # Locate a machine to add button finder = lambda driver: self.find_all('#machinestable tbody tr')[0].find_element(By.XPATH, '//td[@class="add-del-layers"]') - add_btn = self.wait_until_element_clickable(finder) + add_btn = self.wait_until_finder_clickable(finder) add_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -482,7 +482,7 @@ class TestProjectPage(TestProjectPageBase): ) finder = lambda driver: self.find('#hide-alert') - hide_button = self.wait_until_element_clickable(finder) + hide_button = self.wait_until_finder_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification')
@@ -528,14 +528,14 @@ class TestProjectPage(TestProjectPageBase): # check "Add layer" button works self.wait_until_visible('#layerstable tbody tr') finder = lambda driver: self.find_all('#layerstable tbody tr')[0].find_element(By.XPATH, '//td[@class="add-del-layers"]/a[@data-directive="add"]') - add_btn = self.wait_until_element_clickable(finder) + add_btn = self.wait_until_finder_clickable(finder) add_btn.click() # check modal is displayed self.wait_until_visible('#dependencies-modal') list_dependencies = self.find_all('#dependencies-list li') # click on add-layers button finder = lambda driver: self.driver.find_element(By.XPATH, '//form[@id="dependencies-modal-form"]//button[@class="btn btn-primary"]') - add_layers_btn = self.wait_until_element_clickable(finder) + add_layers_btn = self.wait_until_finder_clickable(finder) add_layers_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -544,14 +544,14 @@ class TestProjectPage(TestProjectPageBase): ) finder = lambda driver: self.find('#hide-alert') - hide_button = self.wait_until_element_clickable(finder) + hide_button = self.wait_until_finder_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification') # check "Remove layer" button works self.wait_until_visible('#layerstable tbody tr') finder = lambda driver: self.find_all('#layerstable tbody tr')[0].find_element(By.XPATH, '//td[@class="add-del-layers"]/a[@data-directive="remove"]') - remove_btn = self.wait_until_element_clickable(finder) + remove_btn = self.wait_until_finder_clickable(finder) remove_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -560,7 +560,7 @@ class TestProjectPage(TestProjectPageBase): ) finder = lambda driver: self.find('#hide-alert') - hide_button = self.wait_until_element_clickable(finder) + hide_button = self.wait_until_finder_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification')
@@ -606,7 +606,7 @@ class TestProjectPage(TestProjectPageBase): # check "Add distro" button works self.wait_until_visible(".add-del-layers") finder = lambda driver: self.find_all('#distrostable tbody tr')[0].find_element(By.XPATH, '//td[@class="add-del-layers"]') - add_btn = self.wait_until_element_clickable(finder) + add_btn = self.wait_until_finder_clickable(finder) add_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -652,7 +652,7 @@ class TestProjectPage(TestProjectPageBase): # check remove layer button works finder = lambda driver: self.find('#add-remove-layer-btn') - remove_layer_btn = self.wait_until_element_clickable(finder) + remove_layer_btn = self.wait_until_finder_clickable(finder) remove_layer_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -660,12 +660,12 @@ class TestProjectPage(TestProjectPageBase): f'You have removed 1 layer from your project', str(change_notification.text) ) finder = lambda driver: self.find('#hide-alert') - hide_button = self.wait_until_element_clickable(finder) + hide_button = self.wait_until_finder_clickable(finder) hide_button.click() # check add layer button works self.wait_until_not_visible('#change-notification') finder = lambda driver: self.find('#add-remove-layer-btn') - add_layer_btn = self.wait_until_element_clickable(finder) + add_layer_btn = self.wait_until_finder_clickable(finder) add_layer_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -673,7 +673,7 @@ class TestProjectPage(TestProjectPageBase): f'You have added 1 layer to your project', str(change_notification.text) ) finder = lambda driver: self.find('#hide-alert') - hide_button = self.wait_until_element_clickable(finder) + hide_button = self.wait_until_finder_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification') # check tabs(layers, recipes, machines) are displayed
lib/toaster/tests/functional/test_project_page_tab_config.py +1 -1
@@ -330,7 +330,7 @@ class TestProjectConfigTab(TestProjectConfigTabBase): self.wait_until_visible('#layer-container > form > div > span > div') self.wait_until_visible('.dropdown-menu') finder = lambda driver: driver.find_element(By.XPATH, '//*[@id="layer-container"]/form/div/span/div/div/div') - dropdown_item = self.wait_until_element_clickable(finder) + dropdown_item = self.wait_until_finder_clickable(finder) dropdown_item.click() self.wait_until_clickable('#add-layer-btn') add_layer_btn = layers.find_element(By.ID, 'add-layer-btn')
PATCH 2/5 toaster: Update to django 5.2
Run django-update against the code, which still passes testing afterwards.
--- lib/toaster/bldcollector/admin.py | 8 ++++---- lib/toaster/bldcontrol/admin.py | 2 +- toaster-requirements.txt | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-)
lib/toaster/bldcollector/admin.py +4 -4
@@ -8,6 +8,7 @@ from django import forms import django.db.models as models [email protected](BitbakeVersion) class BitbakeVersionAdmin(admin.ModelAdmin): # we override the formfield for db URLField
@@ -20,18 +21,17 @@ class BitbakeVersionAdmin(admin.ModelAdmin): db_field, **kwargs) [email protected](Release) class ReleaseAdmin(admin.ModelAdmin): pass [email protected](ToasterSetting) class ToasterSettingAdmin(admin.ModelAdmin): pass [email protected](Layer_Version) class LayerVersionsAdmin(admin.ModelAdmin): pass -admin.site.register(Layer_Version, LayerVersionsAdmin) -admin.site.register(BitbakeVersion, BitbakeVersionAdmin) -admin.site.register(Release, ReleaseAdmin) -admin.site.register(ToasterSetting, ToasterSettingAdmin)
lib/toaster/bldcontrol/admin.py +1 -1
@@ -5,7 +5,7 @@ from django.contrib import admin from .models import BuildEnvironment [email protected](BuildEnvironment) class BuildEnvironmentAdmin(admin.ModelAdmin): pass -admin.site.register(BuildEnvironment, BuildEnvironmentAdmin)
toaster-requirements.txt +1 -1
@@ -1,4 +1,4 @@ -Django>4.2,<4.3 +Django>5.2,<5.3 beautifulsoup4>=4.4.0 pytz django-log-viewer==1.1.7
PATCH 3/5 toaster/layerdetails: Add id labels to for to make tests more robust
In reply to Richard PurdieThe two textareas are hard to tell apart in the test code, add id labels to them so the tests can work more effectively/robustly.
--- lib/toaster/toastergui/templates/layerdetails.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
lib/toaster/toastergui/templates/layerdetails.html +4 -4
@@ -328,12 +328,12 @@ <span class="current-value">{{layerversion.layer.summary|default_if_none:''}}</span> <form style="display:none; margin-bottom:20px; margin-top:5px;"> <div class="form-group"> - <textarea class="form-control" rows="2">{% if layerversion.layer.summary %}{{layerversion.layer.summary}}{% endif %}</textarea> + <textarea id="layer-summary" class="form-control" rows="2">{% if layerversion.layer.summary %}{{layerversion.layer.summary}}{% endif %}</textarea> </div> <button class="btn btn-default change-btn" data-layer-prop="summary" type="button">Save</button> <a href="#" class="btn btn-link cancel">Cancel</a> </form> - <span class="glyphicon glyphicon-edit"></span> + <span id="edit-layer-summary" class="glyphicon glyphicon-edit"></span> <span class="glyphicon glyphicon-trash delete-current-value" data-toggle="tooltip" title="Delete"></span> </dd> <dt>
@@ -344,12 +344,12 @@ <span class="current-value">{{layerversion.layer.description|default_if_none:''}}</span> <form style="display:none; margin-bottom:20px; margin-top:5px;"> <div class="form-group"> - <textarea class="form-control" rows="6">{% if layerversion.layer.description %}{{layerversion.layer.description}}{% endif %}</textarea> + <textarea id="layer-description" class="form-control" rows="6">{% if layerversion.layer.description %}{{layerversion.layer.description}}{% endif %}</textarea> </div> <button class="btn btn-default change-btn" data-layer-prop="description" type="button" >Save</button> <a href="#" class="btn btn-link cancel">Cancel</a> </form> - <span class="glyphicon glyphicon-edit"></span> + <span id="edit-layer-description" class="glyphicon glyphicon-edit"></span> <span class="glyphicon glyphicon-trash delete-current-value" data-toggle="tooltip" title="Delete"></span> </dd> {% if layerversion.layer_source == layer_source.TYPE_LAYERINDEX %}
PATCH 4/5 tests/selenium_helpers_base: Add wait_until_element_clickable
In reply to Richard PurdieAdd a version of the wait function that works on a specific element but can also scroll to make the element clickable. To do this we need to add an optional scroll function to the core wait function, but this may be useful in other functions here eventually.
--- .../tests/browser/selenium_helpers_base.py | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
lib/toaster/tests/browser/selenium_helpers_base.py +18 -2
@@ -27,7 +27,9 @@ from selenium.webdriver.common.by import By from selenium.webdriver.common.desired_capabilities import DesiredCapabilities from selenium.common.exceptions import NoSuchElementException, \ StaleElementReferenceException, TimeoutException, \ - SessionNotCreatedException, WebDriverException + SessionNotCreatedException, WebDriverException, \ + ElementNotInteractableException +from selenium.webdriver.common.action_chains import ActionChains def create_selenium_driver(cls,browser='chrome'): # set default browser string based on env (if available)
@@ -98,7 +100,7 @@ class Wait(WebDriverWait): self._POLL_FREQUENCY = poll super(Wait, self).__init__(driver, self._TIMEOUT, self._POLL_FREQUENCY) - def until(self, method, message=''): + def until(self, method, message='', scroll=None): """ Calls the method provided with the driver as an argument until the return value is not False.
@@ -107,9 +109,14 @@ class Wait(WebDriverWait): end_time = time.time() + self._timeout while True: try: + if scroll: + scroll(self._driver) value = method(self._driver) if value: return value + + except ElementNotInteractableException: + pass except NoSuchElementException: pass except StaleElementReferenceException:
@@ -255,6 +262,15 @@ class SeleniumTestCaseBase(unittest.TestCase): Wait(self.driver, timeout=timeout).until(is_clickable, msg) return finder(self.driver) + def wait_until_element_clickable(self, element, timeout=Wait._TIMEOUT): + """ Wait until element is clickable """ + WebDriverWait(self.driver, timeout=timeout).until(lambda driver: self.driver.execute_script("return jQuery.active == 0")) + is_clickable = lambda driver: (element.is_displayed() and element.is_enabled()) + scroll = lambda driver: ActionChains(driver).move_to_element(element).perform() + msg = 'A matching element never became be clickable' + Wait(self.driver, timeout=timeout).until(is_clickable, msg, scroll=scroll) + return + def wait_until_focused(self, selector): """ Wait until element matching CSS selector has focus """ is_focused = \
PATCH 5/5 toaster/tests/layerdetails: Update tests to use labels and scrolling function
In reply to Richard Purdiewait_until_element_clickable attempts to scroll the viewport if needed which improves the test robustness from timing issues.
Also switch to dedicated element labels added in a previous patch to remove ambiguity from the test over the different textareas so we don't randonly iterate them (which caused some test issues).
--- .../tests/browser/test_layerdetails_page.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
lib/toaster/tests/browser/test_layerdetails_page.py +9 -6
@@ -78,17 +78,20 @@ class TestLayerDetailsPage(SeleniumTestCase): self.wait_until_visible("#layer-git-repo-url") # Open every edit box - for btn in self.find_all("dd .glyphicon-edit"): - btn.click() + self.wait_until_element_clickable(self.find("#edit-layer-description")) + self.click("#edit-layer-description") + self.wait_until_element_clickable(self.find("#edit-layer-summary")) + self.click("#edit-layer-summary") # Wait for the inputs to become visible after animation - self.wait_until_visible("#layer-git input[type=text]") - self.wait_until_visible("dd textarea") + self.wait_until_visible("#layer-git-repo-url") self.wait_until_visible("dd .change-btn") + self.wait_until_element_clickable(self.find("#layer-description")) + self.wait_until_element_clickable(self.find("#layer-summary")) # Edit each value for inputs in self.find_all("#layer-git input[type=text]") + \ - self.find_all("dd textarea"): + [self.find("#layer-summary"), self.find("#layer-description")]: # ignore the tt inputs (twitter typeahead input) if "tt-" in inputs.get_attribute("class"): continue
@@ -100,7 +103,7 @@ class TestLayerDetailsPage(SeleniumTestCase): (self.initial_values, value)) # Make sure the input visible beofre sending keys - self.wait_until_element_visible(inputs) + self.wait_until_element_clickable(inputs) inputs.send_keys("-edited") # Save the new values