toaster/test/functional: Move _create_test_new_project to base class as helper
PATCH 1/28 toaster/test/functional: Move _create_test_new_project to base class as helper
The test project creation is needed by mutliple tests. Move it to the base class as a helper function for reuse.
--- .../tests/functional/functional_helpers.py | 72 +++++++++++++++++++ .../functional/test_create_new_project.py | 69 ------------------ 2 files changed, 72 insertions(+), 69 deletions(-)
lib/toaster/tests/functional/functional_helpers.py +72 -0
@@ -12,9 +12,12 @@ import logging import subprocess import signal import re +import requests +from django.urls import reverse from tests.browser.selenium_helpers_base import SeleniumTestCaseBase from selenium.webdriver.common.by import By +from selenium.webdriver.support.select import Select from selenium.common.exceptions import NoSuchElementException logger = logging.getLogger("toaster")
@@ -136,3 +139,72 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase): except NoSuchElementException: return False return element + + def _create_test_new_project( + self, + project_name, + release, + release_title, + merge_toaster_settings, + ): + """ Create/Test new project using: + - Project Name: Any string + - Release: Any string + - Merge Toaster settings: True or False + """ + + # Obtain a CSRF token from a suitable URL + projs = requests.get(self.live_server_url + reverse('newproject')) + csrftoken = projs.cookies.get('csrftoken') + + # Use the projects typeahead to find out if the project already exists + req = requests.get(self.live_server_url + reverse('xhr_projectstypeahead'), {'search': project_name, 'format' : 'json'}) + data = req.json() + # Delete any existing projects + for result in data['results']: + del_url = reverse('xhr_project', args=(result['id'],)) + del_response = requests.delete(self.live_server_url + del_url, cookies={'csrftoken': csrftoken}, headers={'X-CSRFToken': csrftoken}) + self.assertEqual(del_response.status_code, 200) + + self.get(reverse('newproject')) + self.wait_until_visible('#new-project-name', poll=3) + self.driver.find_element(By.ID, + "new-project-name").send_keys(project_name) + + select = Select(self.find('#projectversion')) + select.select_by_value(release) + + # check merge toaster settings + checkbox = self.find('.checkbox-mergeattr') + if merge_toaster_settings: + if not checkbox.is_selected(): + checkbox.click() + else: + if checkbox.is_selected(): + checkbox.click() + + self.driver.find_element(By.ID, "create-project-button").click() + + element = self.wait_until_visible('#project-created-notification', poll=3) + self.assertTrue( + self.element_exists('#project-created-notification'), + f"Project:{project_name} creation notification not shown" + ) + self.assertTrue( + project_name in element.text, + f"New project name:{project_name} not in new project notification" + ) + + # Use the projects typeahead again to check the project now exists + req = requests.get(self.live_server_url + reverse('xhr_projectstypeahead'), {'search': project_name, 'format' : 'json'}) + data = req.json() + self.assertGreater(len(data['results']), 0, f"New project:{project_name} not found in database") + + # check release + self.assertTrue(re.search( + release_title, + self.driver.find_element(By.XPATH, + "//span[@id='project-release-title']" + ).text), + 'The project release is not defined') +
lib/toaster/tests/functional/test_create_new_project.py +0 -69
81 lines not on this page · raw message
PATCH 2/28 toaster/tests/functional: Tweak the project creation function for better reuse
Tweak the function name and return the created project ID.
Allow the release_name test to be skipped with a value of None.
Add an extra wait call to ensure the create project button is ready before clicking it.
--- .../tests/functional/functional_helpers.py | 18 +++++++++++++----- .../functional/test_create_new_project.py | 8 ++++---- 2 files changed, 17 insertions(+), 9 deletions(-)
lib/toaster/tests/functional/functional_helpers.py +13 -5
@@ -140,7 +140,7 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase): return False return element - def _create_test_new_project( + def create_new_project( self, project_name, release,
@@ -183,6 +183,8 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase): if checkbox.is_selected(): checkbox.click() + self.wait_until_clickable('#create-project-button') + self.driver.find_element(By.ID, "create-project-button").click() element = self.wait_until_visible('#project-created-notification', poll=3)
@@ -200,11 +202,17 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase): data = req.json() self.assertGreater(len(data['results']), 0, f"New project:{project_name} not found in database") + project_id = data['results'][0]['id'] + + self.wait_until_visible('#project-release-title') + # check release - self.assertTrue(re.search( - release_title, - self.driver.find_element(By.XPATH, + if release_title is not None: + self.assertTrue(re.search( + release_title, + self.driver.find_element(By.XPATH, "//span[@id='project-release-title']" ).text), - 'The project release is not defined') + 'The project release is not defined') + return project_id
lib/toaster/tests/functional/test_create_new_project.py +4 -4
@@ -24,7 +24,7 @@ class TestCreateNewProject(SeleniumFunctionalTestCase): release = '3' release_title = 'Yocto Project master' project_name = 'projectmaster' - self._create_test_new_project( + self.create_new_project( project_name, release, release_title,
@@ -40,7 +40,7 @@ class TestCreateNewProject(SeleniumFunctionalTestCase): release = '1' release_title = 'Yocto Project 5.0 "Scarthgap"' project_name = 'projectscarthgap' - self._create_test_new_project( + self.create_new_project( project_name, release, release_title,
@@ -56,7 +56,7 @@ class TestCreateNewProject(SeleniumFunctionalTestCase): release = '5' release_title = 'Yocto Project 4.0 "Kirkstone"' project_name = 'projectkirkstone' - self._create_test_new_project( + self.create_new_project( project_name, release, release_title,
@@ -72,7 +72,7 @@ class TestCreateNewProject(SeleniumFunctionalTestCase): release = '2' release_title = 'Local Yocto Project' project_name = 'projectlocal' - self._create_test_new_project( + self.create_new_project( project_name, release, release_title,
PATCH 3/28 toaster/tests/functional_basic: Reuse common project creation code
In reply to Richard PurdieSwitch this test module to use the common project creation code which contains race fixes. That code requires the database access wrapper be dropped and we no longer have ordering constraints.
--- .../tests/functional/test_functional_basic.py | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-)
lib/toaster/tests/functional/test_functional_basic.py +1 -21
@@ -17,8 +17,6 @@ from selenium.webdriver.common.by import By from tests.functional.utils import get_projectId_from_url [email protected]_db [email protected]("second_to_last") class FuntionalTestBasic(SeleniumFunctionalTestCase): """Basic functional tests for Toaster""" project_id = None
@@ -26,25 +24,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): def setUp(self): super(FuntionalTestBasic, self).setUp() if not FuntionalTestBasic.project_id: - self._create_slenium_project() - current_url = self.driver.current_url - FuntionalTestBasic.project_id = get_projectId_from_url(current_url) - -# testcase (1514) - def _create_slenium_project(self): - project_name = 'selenium-project' - self.get(reverse('newproject')) - self.wait_until_visible('#new-project-name', poll=3) - self.driver.find_element(By.ID, "new-project-name").send_keys(project_name) - self.driver.find_element(By.ID, 'projectversion').click() - self.driver.find_element(By.ID, "create-project-button").click() - element = self.wait_until_visible('#project-created-notification', poll=10) - self.assertTrue(self.element_exists('#project-created-notification'),'Project creation notification not shown') - self.assertTrue(project_name in element.text, - "New project name not in new project notification") - self.assertTrue(Project.objects.filter(name=project_name).count(), - "New project not found in database") - return Project.objects.last().id + FuntionalTestBasic.project_id = self.create_new_project('selenium-project', '3', None, False) # testcase (1515) def test_verify_left_bar_menu(self):
PATCH 4/28 toaster/tests/project_config: Reuse common project creation code
In reply to Richard PurdieSwitch this test module to use the common project creation code which contains race fixes. That code requires the database access wrapper be dropped and we no longer have ordering constraints.
--- .../tests/functional/test_project_config.py | 50 ++----------------- 1 file changed, 4 insertions(+), 46 deletions(-)
lib/toaster/tests/functional/test_project_config.py +4 -46
@@ -7,7 +7,6 @@ # import string -import random import pytest from django.urls import reverse from selenium.webdriver import Keys
@@ -18,9 +17,6 @@ from selenium.webdriver.common.by import By from .utils import get_projectId_from_url - [email protected]_db [email protected]("last") class TestProjectConfig(SeleniumFunctionalTestCase): project_id = None PROJECT_NAME = 'TestProjectConfig'
@@ -28,42 +24,6 @@ class TestProjectConfig(SeleniumFunctionalTestCase): INVALID_PATH_CHAR_TEXT = 'The directory path cannot include spaces or ' \ 'any of these characters' - def _create_project(self, project_name): - """ Create/Test new project using: - - Project Name: Any string - - Release: Any string - - Merge Toaster settings: True or False - """ - self.get(reverse('newproject')) - self.wait_until_visible('#new-project-name', poll=2) - self.find("#new-project-name").send_keys(project_name) - select = Select(self.find("#projectversion")) - select.select_by_value('3') - - # check merge toaster settings - checkbox = self.find('.checkbox-mergeattr') - if not checkbox.is_selected(): - checkbox.click() - - if self.PROJECT_NAME != 'TestProjectConfig': - # Reset project name if it's not the default one - self.PROJECT_NAME = 'TestProjectConfig' - - self.find("#create-project-button").click() - - try: - self.wait_until_visible('#hint-error-project-name', poll=2) - url = reverse('project', args=(TestProjectConfig.project_id, )) - self.get(url) - self.wait_until_visible('#config-nav', poll=3) - except TimeoutException: - self.wait_until_visible('#config-nav', poll=3) - - def _random_string(self, length): - return ''.join( - random.choice(string.ascii_letters) for _ in range(length) - ) - def _get_config_nav_item(self, index): config_nav = self.find('#config-nav') return config_nav.find_elements(By.TAG_NAME, 'li')[index]
@@ -72,12 +32,10 @@ class TestProjectConfig(SeleniumFunctionalTestCase): """ Navigate to project BitBake variables page """ # check if the menu is displayed if TestProjectConfig.project_id is None: - self._create_project(project_name=self._random_string(10)) - current_url = self.driver.current_url - TestProjectConfig.project_id = get_projectId_from_url(current_url) - else: - url = reverse('projectconf', args=(TestProjectConfig.project_id,)) - self.get(url) + TestProjectConfig.project_id = self.create_new_project(self.PROJECT_NAME, '3', None, True) + + url = reverse('projectconf', args=(TestProjectConfig.project_id,)) + self.get(url) self.wait_until_visible('#config-nav', poll=3) bbv_page_link = self._get_config_nav_item(9) bbv_page_link.click()
PATCH 5/28 toaster/tests/function/basic: Improve exception handling for error readability
In reply to Richard PurdieThe 'fail' calls are useful for find() failures but not for wrapping existing asserts where they hide more useful error messages. Rework the code flow to give more readable error reporting.
--- .../tests/functional/test_functional_basic.py | 108 ++++++++++-------- 1 file changed, 59 insertions(+), 49 deletions(-)
lib/toaster/tests/functional/test_functional_basic.py +59 -49
@@ -40,44 +40,44 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'customimages/"'+"]").click() self.wait_until_present('#config-nav', poll=10) - self.assertTrue(re.search("Custom images",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'Custom images information is not loading properly') except: self.fail(msg='No Custom images tab available') + self.assertTrue(re.search("Custom images",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'Custom images information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'images/"'+"]").click() self.wait_until_present('#config-nav', poll=10) - self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible image recipes information is not loading properly') except: self.fail(msg='No Compatible image tab available') + self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible image recipes information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'softwarerecipes/"'+"]").click() self.wait_until_present('#config-nav', poll=10) - self.assertTrue(re.search("Compatible software recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible software recipe information is not loading properly') except: self.fail(msg='No Compatible software recipe tab available') + self.assertTrue(re.search("Compatible software recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible software recipe information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'machines/"'+"]").click() self.wait_until_present('#config-nav', poll=10) - self.assertTrue(re.search("Compatible machines",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible machine information is not loading properly') except: self.fail(msg='No Compatible machines tab available') + self.assertTrue(re.search("Compatible machines",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible machine information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'layers/"'+"]").click() self.wait_until_present('#config-nav', poll=10) - self.assertTrue(re.search("Compatible layers",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible layer information is not loading properly') except: self.fail(msg='No Compatible layers tab available') + self.assertTrue(re.search("Compatible layers",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible layer information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'configuration"'+"]").click() self.wait_until_present('#config-nav', poll=10) - self.assertTrue(re.search("Bitbake variables",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Bitbake variables information is not loading properly') except: self.fail(msg='No Bitbake variables tab available') + self.assertTrue(re.search("Bitbake variables",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Bitbake variables information is not loading properly') # testcase (1516) def test_review_configuration_information(self):
@@ -86,9 +86,11 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() project_URL=self.get_URL() self.wait_until_present('#config-nav', poll=10) + + # Machine section of page + self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist') + self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.XPATH, "//span[@id='project-machine-name']").text),'The machine type is not assigned') try: - self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist') - self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.XPATH, "//span[@id='project-machine-name']").text),'The machine type is not assigned') self.driver.find_element(By.XPATH, "//span[@id='change-machine-toggle']").click() self.wait_until_visible('#select-machine-form', poll=10) self.wait_until_visible('#cancel-machine-change', poll=10)
@@ -96,33 +98,34 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): except: self.fail(msg='The machine information is wrong in the configuration page') + # Most built recipes section try: self.driver.find_element(By.ID, 'no-most-built') except: self.fail(msg='No Most built information in project detail page') - try: - self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.XPATH, "//span[@id='project-release-title']").text),'The project release is not defined') - except: - self.fail(msg='No project release title information in project detail page') + # Project Release title + self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.XPATH, "//span[@id='project-release-title']").text), 'The project release is not defined in the project detail page') + # List of layers in project + self.driver.find_element(By.XPATH, "//div[@id='layer-container']") + self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count') try: - self.driver.find_element(By.XPATH, "//div[@id='layer-container']") - self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count') layer_list = self.driver.find_element(By.ID, "layers-in-project-list") layers = layer_list.find_elements(By.TAG_NAME, "li") - for layer in layers: - if re.match ("openembedded-core",layer.text): - print ("openembedded-core layer is a default layer in the project configuration") - elif re.match ("meta-poky",layer.text): - print ("meta-poky layer is a default layer in the project configuration") - elif re.match ("meta-yocto-bsp",layer.text): - print ("meta-yocto-bsp is a default layer in the project configuratoin") - else: - self.fail(msg='default layers are missing from the project configuration') except: self.fail(msg='No Layer information in project detail page') + for layer in layers: + if re.match ("openembedded-core", layer.text): + print ("openembedded-core layer is a default layer in the project configuration") + elif re.match ("meta-poky", layer.text): + print ("meta-poky layer is a default layer in the project configuration") + elif re.match ("meta-yocto-bsp", layer.text): + print ("meta-yocto-bsp is a default layer in the project configuratoin") + else: + self.fail(msg='default layers are missing from the project configuration') + # testcase (1517) def test_verify_machine_information(self): self.get(reverse('all-projects'))
@@ -130,9 +133,9 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav', poll=10) + self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist') + self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.ID, "project-machine-name").text),'The machine type is not assigned') try: - self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist') - self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.ID, "project-machine-name").text),'The machine type is not assigned') self.driver.find_element(By.ID, "change-machine-toggle").click() self.wait_until_visible('#select-machine-form', poll=10) self.wait_until_visible('#cancel-machine-change', poll=10)
@@ -147,13 +150,13 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav', poll=10) project_URL=self.get_URL() + self.assertTrue(re.search("You haven't built any recipes yet",self.driver.find_element(By.ID, "no-most-built").text),'Default message of no builds is not present') try: - self.assertTrue(re.search("You haven't built any recipes yet",self.driver.find_element(By.ID, "no-most-built").text),'Default message of no builds is not present') self.driver.find_element(By.XPATH, "//div[@id='no-most-built']/p/a[@href="+'"'+project_URL+'images/"'+"]").click() - self.wait_until_present('#config-nav', poll=10) - self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Choose a recipe to build link is not working properly') except: self.fail(msg='No Most built information in project detail page') + self.wait_until_present('#config-nav', poll=10) + self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Choose a recipe to build link is not working properly') # testcase (1519) def test_verify_project_release_information(self):
@@ -161,11 +164,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav', poll=10) - - try: - self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.ID, "project-release-title").text),'The project release is not defined') - except: - self.fail(msg='No project release title information in project detail page') + self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.ID, "project-release-title").text), 'No project release title information in project detail page') # testcase (1520) def test_verify_layer_information(self):
@@ -174,28 +173,32 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav', poll=10) project_URL=self.get_URL() + self.driver.find_element(By.XPATH, "//div[@id='layer-container']") + self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count') + try: - self.driver.find_element(By.XPATH, "//div[@id='layer-container']") - self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count') layer_list = self.driver.find_element(By.ID, "layers-in-project-list") layers = layer_list.find_elements(By.TAG_NAME, "li") + except: + self.fail(msg='No Layer information in project detail page') - for layer in layers: - if re.match ("openembedded-core",layer.text): - print ("openembedded-core layer is a default layer in the project configuration") - elif re.match ("meta-poky",layer.text): - print ("meta-poky layer is a default layer in the project configuration") - elif re.match ("meta-yocto-bsp",layer.text): - print ("meta-yocto-bsp is a default layer in the project configuratoin") - else: - self.fail(msg='default layers are missing from the project configuration') + for layer in layers: + if re.match ("openembedded-core",layer.text): + print ("openembedded-core layer is a default layer in the project configuration") + elif re.match ("meta-poky",layer.text): + print ("meta-poky layer is a default layer in the project configuration") + elif re.match ("meta-yocto-bsp",layer.text): + print ("meta-yocto-bsp is a default layer in the project configuratoin") + else: + self.fail(msg='default layers are missing from the project configuration') + try: self.driver.find_element(By.XPATH, "//input[@id='layer-add-input']") self.driver.find_element(By.XPATH, "//button[@id='add-layer-btn']") self.driver.find_element(By.XPATH, "//div[@id='layer-container']/form[@class='form-inline']/p/a[@id='view-compatible-layers']") self.driver.find_element(By.XPATH, "//div[@id='layer-container']/form[@class='form-inline']/p/a[@href="+'"'+project_URL+'importlayer"'+"]") except: - self.fail(msg='No Layer information in project detail page') + self.fail(msg='Layer configuration controls missing') # testcase (1521) def test_verify_project_detail_links(self):
@@ -211,7 +214,11 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): try: self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'builds/"'+"]").click() self.wait_until_visible('#project-topbar', poll=10) - self.assertTrue(re.search("Builds",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'builds/"'+"]").text), 'Builds tab in project topbar is misspelled') + except: + self.fail(msg='Builds tab information is not present') + + self.assertTrue(re.search("Builds",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'builds/"'+"]").text), 'Builds tab in project topbar is misspelled') + try: self.driver.find_element(By.XPATH, "//div[@id='empty-state-projectbuildstable']") except: self.fail(msg='Builds tab information is not present')
@@ -219,7 +226,10 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): try: self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'importlayer"'+"]").click() self.wait_until_visible('#project-topbar', poll=10) - self.assertTrue(re.search("Import layer",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'importlayer"'+"]").text), 'Import layer tab in project topbar is misspelled') + except: + self.fail(msg='Import layer tab not loading properly') + self.assertTrue(re.search("Import layer",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'importlayer"'+"]").text), 'Import layer tab in project topbar is misspelled') + try: self.driver.find_element(By.XPATH, "//fieldset[@id='repo-select']") self.driver.find_element(By.XPATH, "//fieldset[@id='git-repo']") except:
@@ -228,10 +238,10 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): try: self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'newcustomimage/"'+"]").click() self.wait_until_visible('#project-topbar', poll=10) - self.assertTrue(re.search("New custom image",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'newcustomimage/"'+"]").text), 'New custom image tab in project topbar is misspelled') - self.assertTrue(re.search("Select the image recipe you want to customise",self.driver.find_element(By.XPATH, "//div[@class='col-md-12']/h2").text),'The new custom image tab is not loading correctly') except: self.fail(msg='New custom image tab not loading properly') + self.assertTrue(re.search("New custom image",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'newcustomimage/"'+"]").text), 'New custom image tab in project topbar is misspelled') + self.assertTrue(re.search("Select the image recipe you want to customise",self.driver.find_element(By.XPATH, "//div[@class='col-md-12']/h2").text),'The new custom image tab is not loading correctly')
PATCH 6/28 toaster/tests/function/basic: Make element detection more specific
In reply to Richard PurdieThe tests would race and potentially fail as the elements on the page being waited for were not specific enough.
Add suitable elements to wait for and drop the remainder of the poll parameters since these are no longer needed since we no longer need to sleep for things to appear.
--- .../tests/functional/test_functional_basic.py | 55 +++++++++++-------- 1 file changed, 32 insertions(+), 23 deletions(-)
lib/toaster/tests/functional/test_functional_basic.py +32 -23
@@ -31,50 +31,50 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.get(reverse('all-projects')) self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#config-nav') self.assertTrue(self.element_exists('#config-nav'),'Configuration Tab does not exist') project_URL=self.get_URL() self.driver.find_element(By.XPATH, '//a[@href="'+project_URL+'"]').click() - self.wait_until_present('#config-nav', poll=10) try: + self.wait_until_present('#config-nav') self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'customimages/"'+"]").click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#filter-modal-customimagestable') except: self.fail(msg='No Custom images tab available') self.assertTrue(re.search("Custom images",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'Custom images information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'images/"'+"]").click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#filter-modal-imagerecipestable') except: self.fail(msg='No Compatible image tab available') self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible image recipes information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'softwarerecipes/"'+"]").click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#filter-modal-softwarerecipestable') except: self.fail(msg='No Compatible software recipe tab available') self.assertTrue(re.search("Compatible software recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible software recipe information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'machines/"'+"]").click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#filter-modal-machinestable') except: self.fail(msg='No Compatible machines tab available') self.assertTrue(re.search("Compatible machines",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible machine information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'layers/"'+"]").click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#filter-modal-layerstable') except: self.fail(msg='No Compatible layers tab available') self.assertTrue(re.search("Compatible layers",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Compatible layer information is not loading properly') try: self.driver.find_element(By.XPATH, "//*[@id='config-nav']/ul/li/a[@href="+'"'+project_URL+'configuration"'+"]").click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#configvar-list') except: self.fail(msg='No Bitbake variables tab available') self.assertTrue(re.search("Bitbake variables",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Bitbake variables information is not loading properly')
@@ -85,20 +85,21 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() project_URL=self.get_URL() - self.wait_until_present('#config-nav', poll=10) # Machine section of page + self.wait_until_visible('#machine-section') self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist') self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.XPATH, "//span[@id='project-machine-name']").text),'The machine type is not assigned') try: self.driver.find_element(By.XPATH, "//span[@id='change-machine-toggle']").click() - self.wait_until_visible('#select-machine-form', poll=10) - self.wait_until_visible('#cancel-machine-change', poll=10) + self.wait_until_visible('#select-machine-form') + self.wait_until_visible('#cancel-machine-change') self.driver.find_element(By.XPATH, "//form[@id='select-machine-form']/a[@id='cancel-machine-change']").click() except: self.fail(msg='The machine information is wrong in the configuration page') # Most built recipes section + self.wait_until_visible('#no-most-built') try: self.driver.find_element(By.ID, 'no-most-built') except:
@@ -108,6 +109,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.XPATH, "//span[@id='project-release-title']").text), 'The project release is not defined in the project detail page') # List of layers in project + self.wait_until_visible('#layer-container') self.driver.find_element(By.XPATH, "//div[@id='layer-container']") self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count') try:
@@ -131,14 +133,15 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.get(reverse('all-projects')) self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_visible('#machine-section') self.assertTrue(self.element_exists('#machine-section'),'Machine section for the project configuration page does not exist') + self.wait_until_visible('#project-machine-name') self.assertTrue(re.search("qemux86-64",self.driver.find_element(By.ID, "project-machine-name").text),'The machine type is not assigned') try: self.driver.find_element(By.ID, "change-machine-toggle").click() - self.wait_until_visible('#select-machine-form', poll=10) - self.wait_until_visible('#cancel-machine-change', poll=10) + self.wait_until_visible('#select-machine-form') + self.wait_until_visible('#cancel-machine-change') self.driver.find_element(By.ID, "cancel-machine-change").click() except: self.fail(msg='The machine information is wrong in the configuration page')
@@ -148,14 +151,16 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.get(reverse('all-projects')) self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#config-nav') project_URL=self.get_URL() + + self.wait_until_visible('#no-most-built') self.assertTrue(re.search("You haven't built any recipes yet",self.driver.find_element(By.ID, "no-most-built").text),'Default message of no builds is not present') try: self.driver.find_element(By.XPATH, "//div[@id='no-most-built']/p/a[@href="+'"'+project_URL+'images/"'+"]").click() except: self.fail(msg='No Most built information in project detail page') - self.wait_until_present('#config-nav', poll=10) + self.wait_until_visible('#config-nav') self.assertTrue(re.search("Compatible image recipes",self.driver.find_element(By.XPATH, "//div[@class='col-md-10']").text),'The Choose a recipe to build link is not working properly') # testcase (1519)
@@ -163,7 +168,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.get(reverse('all-projects')) self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_visible('#project-release-title') self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.ID, "project-release-title").text), 'No project release title information in project detail page') # testcase (1520)
@@ -171,9 +176,11 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.get(reverse('all-projects')) self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#config-nav') project_URL=self.get_URL() + self.wait_until_visible('#layer-container') self.driver.find_element(By.XPATH, "//div[@id='layer-container']") + self.wait_until_visible('#project-layers-count') self.assertTrue(re.search("3",self.driver.find_element(By.ID, "project-layers-count").text),'There should be 3 layers listed in the layer count') try:
@@ -205,18 +212,18 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): self.get(reverse('all-projects')) self.wait_until_present('#projectstable', poll=10) self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_present('#config-nav') project_URL=self.get_URL() self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li[@id='topbar-configuration-tab']/a[@href="+'"'+project_URL+'"'+"]").click() - self.wait_until_present('#config-nav', poll=10) + self.wait_until_visible('#topbar-configuration-tab') self.assertTrue(re.search("Configuration",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li[@id='topbar-configuration-tab']/a[@href="+'"'+project_URL+'"'+"]").text), 'Configuration tab in project topbar is misspelled') try: self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'builds/"'+"]").click() - self.wait_until_visible('#project-topbar', poll=10) except: self.fail(msg='Builds tab information is not present') + self.wait_until_visible('#project-topbar') self.assertTrue(re.search("Builds",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'builds/"'+"]").text), 'Builds tab in project topbar is misspelled') try: self.driver.find_element(By.XPATH, "//div[@id='empty-state-projectbuildstable']")
@@ -225,9 +232,10 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): try: self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'importlayer"'+"]").click() - self.wait_until_visible('#project-topbar', poll=10) except: self.fail(msg='Import layer tab not loading properly') + + self.wait_until_visible('#project-topbar') self.assertTrue(re.search("Import layer",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'importlayer"'+"]").text), 'Import layer tab in project topbar is misspelled') try: self.driver.find_element(By.XPATH, "//fieldset[@id='repo-select']")
@@ -237,9 +245,10 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): try: self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'newcustomimage/"'+"]").click() - self.wait_until_visible('#project-topbar', poll=10) except: self.fail(msg='New custom image tab not loading properly') + + self.wait_until_visible('#project-topbar') self.assertTrue(re.search("New custom image",self.driver.find_element(By.XPATH, "//div[@id='project-topbar']/ul[@class='nav nav-tabs']/li/a[@href="+'"'+project_URL+'newcustomimage/"'+"]").text), 'New custom image tab in project topbar is misspelled') self.assertTrue(re.search("Select the image recipe you want to customise",self.driver.find_element(By.XPATH, "//div[@class='col-md-12']/h2").text),'The new custom image tab is not loading correctly')
PATCH 7/28 toaster/tests/browser: Increase the default wait timeout
In reply to Richard PurdieRather than hardcoded poll and sleep values, we want an overall long timeout and to drop all the other 'sleeping' code.
To facilitate this, increase the overall timeout so we can then start to remove the other values.
--- lib/toaster/tests/browser/selenium_helpers_base.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/toaster/tests/browser/selenium_helpers_base.py +1 -1
@@ -90,7 +90,7 @@ class Wait(WebDriverWait): Subclass of WebDriverWait with predetermined timeout and poll frequency. Also deals with a wider variety of exceptions. """ - _TIMEOUT = 10 + _TIMEOUT = 20 _POLL_FREQUENCY = 0.5 def __init__(self, driver, timeout=_TIMEOUT, poll=_POLL_FREQUENCY):
PATCH 8/28 toaster/tests/browser: Drop unneeded poll parameters
In reply to Richard PurdieIn my testing I wasn't able to see issues needing the poll parameter in the browser tests. Drop those.
--- lib/toaster/tests/browser/test_all_builds_page.py | 6 +++--- lib/toaster/tests/browser/test_all_projects_page.py | 12 ++++++------ .../tests/browser/test_builddashboard_page.py | 2 +- lib/toaster/tests/browser/test_landing_page.py | 2 +- lib/toaster/tests/browser/test_layerdetails_page.py | 8 ++++---- .../tests/browser/test_new_custom_image_page.py | 2 +- lib/toaster/tests/browser/test_new_project_page.py | 8 ++++---- 7 files changed, 20 insertions(+), 20 deletions(-)
lib/toaster/tests/browser/test_all_builds_page.py +3 -3
@@ -224,7 +224,7 @@ class TestAllBuildsPage(SeleniumTestCase): url = reverse('all-builds') self.get(url) - self.wait_until_visible('#allbuildstable', poll=3) + self.wait_until_visible('#allbuildstable') # get the project name cells from the table cells = self.find_all('#allbuildstable td[class="project"]')
@@ -257,7 +257,7 @@ class TestAllBuildsPage(SeleniumTestCase): url = reverse('all-builds') self.get(url) - self.wait_until_visible('#allbuildstable', poll=3) + self.wait_until_visible('#allbuildstable') # test recent builds area for successful build element = self._get_build_time_element(build1)
@@ -452,7 +452,7 @@ class TestAllBuildsPage(SeleniumTestCase): def test_show_rows(row_to_show, show_row_link): # Check that we can show rows == row_to_show show_row_link.select_by_value(str(row_to_show)) - self.wait_until_visible('#allbuildstable tbody tr', poll=3) + self.wait_until_visible('#allbuildstable tbody tr') # check at least some rows are visible self.assertTrue( len(self.find_all('#allbuildstable tbody tr')) > 0
lib/toaster/tests/browser/test_all_projects_page.py +6 -6
@@ -81,7 +81,7 @@ class TestAllProjectsPage(SeleniumTestCase): def _get_row_for_project(self, project_name): """ Get the HTML row for a project, or None if not found """ - self.wait_until_visible('#projectstable tbody tr', poll=3) + self.wait_until_visible('#projectstable tbody tr') rows = self.find_all('#projectstable tbody tr') # find the row with a project name matching the one supplied
@@ -236,7 +236,7 @@ class TestAllProjectsPage(SeleniumTestCase): self.get(url) # Chseck search box is present and works - self.wait_until_visible('#projectstable tbody tr', poll=3) + self.wait_until_visible('#projectstable tbody tr') search_box = self.find('#search-input-projectstable') self.assertTrue(search_box.is_displayed())
@@ -244,7 +244,7 @@ class TestAllProjectsPage(SeleniumTestCase): search_box.send_keys('test project 10') search_btn = self.find('#search-submit-projectstable') search_btn.click() - self.wait_until_visible('#projectstable tbody tr', poll=3) + self.wait_until_visible('#projectstable tbody tr') rows = self.find_all('#projectstable tbody tr') self.assertTrue(len(rows) == 1)
@@ -290,7 +290,7 @@ class TestAllProjectsPage(SeleniumTestCase): ) url = reverse('all-projects') self.get(url) - self.wait_until_visible('#projectstable tbody tr', poll=3) + self.wait_until_visible('#projectstable tbody tr') # Check edit column edit_column = self.find('#edit-columns-button')
@@ -313,7 +313,7 @@ class TestAllProjectsPage(SeleniumTestCase): def test_show_rows(row_to_show, show_row_link): # Check that we can show rows == row_to_show show_row_link.select_by_value(str(row_to_show)) - self.wait_until_visible('#projectstable tbody tr', poll=3) + self.wait_until_visible('#projectstable tbody tr') # check at least some rows are visible self.assertTrue( len(self.find_all('#projectstable tbody tr')) > 0
@@ -321,7 +321,7 @@ class TestAllProjectsPage(SeleniumTestCase): url = reverse('all-projects') self.get(url) - self.wait_until_visible('#projectstable tbody tr', poll=3) + self.wait_until_visible('#projectstable tbody tr') show_rows = self.driver.find_elements( By.XPATH,
lib/toaster/tests/browser/test_builddashboard_page.py +1 -1
@@ -162,7 +162,7 @@ class TestBuildDashboardPage(SeleniumTestCase): """ url = reverse('builddashboard', args=(build.id,)) self.get(url) - self.wait_until_visible('#global-nav', poll=3) + self.wait_until_visible('#global-nav') def _get_build_dashboard_errors(self, build): """
lib/toaster/tests/browser/test_landing_page.py +1 -1
@@ -224,7 +224,7 @@ class TestLandingPage(SeleniumTestCase): self.get(reverse('landing')) - self.wait_until_visible("#latest-builds", poll=3) + self.wait_until_visible("#latest-builds") elements = self.find_all('#allbuildstable') self.assertEqual(len(elements), 1, 'should redirect to builds') content = self.get_page_source()
lib/toaster/tests/browser/test_layerdetails_page.py +4 -4
@@ -108,9 +108,9 @@ class TestLayerDetailsPage(SeleniumTestCase): save_btn.click() try: - self.wait_until_visible("#save-changes-for-switch", poll=3) + self.wait_until_visible("#save-changes-for-switch") btn_save_chg_for_switch = self.wait_until_clickable( - "#save-changes-for-switch", poll=3) + "#save-changes-for-switch") btn_save_chg_for_switch.click() except ElementClickInterceptedException: self.skipTest(
@@ -148,9 +148,9 @@ class TestLayerDetailsPage(SeleniumTestCase): dir_input.send_keys(new_dir) try: - self.wait_until_visible("#save-changes-for-switch", poll=3) + self.wait_until_visible("#save-changes-for-switch") btn_save_chg_for_switch = self.wait_until_clickable( - "#save-changes-for-switch", poll=3) + "#save-changes-for-switch") btn_save_chg_for_switch.click() except ElementClickInterceptedException: self.skipTest(
lib/toaster/tests/browser/test_new_custom_image_page.py +1 -1
@@ -90,7 +90,7 @@ class TestNewCustomImagePage(SeleniumTestCase): """ url = reverse('newcustomimage', args=(self.project.id,)) self.get(url) - self.wait_until_visible('#global-nav', poll=3) + self.wait_until_visible('#global-nav') self.click('button[data-recipe="%s"]' % self.recipe.id)
lib/toaster/tests/browser/test_new_project_page.py +4 -4
@@ -47,7 +47,7 @@ class TestNewProjectPage(SeleniumTestCase): url = reverse('newproject') self.get(url) - self.wait_until_visible('#new-project-name', poll=3) + self.wait_until_visible('#new-project-name') self.enter_text('#new-project-name', project_name) select = Select(self.find('#projectversion'))
@@ -58,7 +58,7 @@ class TestNewProjectPage(SeleniumTestCase): # We should get redirected to the new project's page with the # notification at the top element = self.wait_until_visible( - '#project-created-notification', poll=3) + '#project-created-notification') self.assertTrue(project_name in element.text, "New project name not in new project notification")
@@ -79,7 +79,7 @@ class TestNewProjectPage(SeleniumTestCase): url = reverse('newproject') self.get(url) - self.wait_until_visible('#new-project-name', poll=3) + self.wait_until_visible('#new-project-name') self.enter_text('#new-project-name', project_name)
@@ -91,7 +91,7 @@ class TestNewProjectPage(SeleniumTestCase): self.click("#create-project-button") - self.wait_until_present('#hint-error-project-name', poll=3) + self.wait_until_present('#hint-error-project-name') element = self.find('#hint-error-project-name') self.assertTrue(("Project names must be unique" in element.text),
PATCH 9/28 toaster/tests/functional/helpers: Drop unneeded poll values and sleep
In reply to Richard PurdieDrop the remaining poll values and the sleep within the main wait function as the races this was working around now seem to be resolved with the preceeding patches.
--- lib/toaster/tests/browser/selenium_helpers_base.py | 1 - lib/toaster/tests/functional/functional_helpers.py | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
lib/toaster/tests/browser/selenium_helpers_base.py +0 -1
@@ -225,7 +225,6 @@ class SeleniumTestCaseBase(unittest.TestCase): is_visible = lambda driver: self.find(selector).is_displayed() msg = 'An element matching "%s" should be visible' % selector Wait(self.driver, poll=poll).until(is_visible, msg) - time.sleep(poll) # wait for visibility to settle return self.find(selector) def wait_until_clickable(self, selector, poll=1):
lib/toaster/tests/functional/functional_helpers.py +2 -2
@@ -167,7 +167,7 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase): self.assertEqual(del_response.status_code, 200) self.get(reverse('newproject')) - self.wait_until_visible('#new-project-name', poll=3) + self.wait_until_visible('#new-project-name') self.driver.find_element(By.ID, "new-project-name").send_keys(project_name)
@@ -187,7 +187,7 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase): self.driver.find_element(By.ID, "create-project-button").click() - element = self.wait_until_visible('#project-created-notification', poll=3) + element = self.wait_until_visible('#project-created-notification') self.assertTrue( self.element_exists('#project-created-notification'), f"Project:{project_name} creation notification not shown"
PATCH 10/28 toaster/tests/functional/basic: Improve the projects table selection to a common function
In reply to Richard PurdieThe project page selection code is race prone. Create a common function to resolve the race issue and use it from all the call sites rather than duplicate code.
--- .../tests/functional/functional_helpers.py | 6 ++++++ .../tests/functional/test_functional_basic.py | 15 ++++++++------- 2 files changed, 14 insertions(+), 7 deletions(-)
lib/toaster/tests/functional/functional_helpers.py +6 -0
@@ -216,3 +216,9 @@ class SeleniumFunctionalTestCase(SeleniumTestCaseBase): 'The project release is not defined') return project_id + + def load_projects_page_helper(self): + self.wait_until_present('#projectstable') + # Need to wait for some data in the table too + self.wait_until_present('td[class="updated"]') +
lib/toaster/tests/functional/test_functional_basic.py +8 -7
@@ -20,6 +20,7 @@ from tests.functional.utils import get_projectId_from_url class FuntionalTestBasic(SeleniumFunctionalTestCase): """Basic functional tests for Toaster""" project_id = None + project_url = None def setUp(self): super(FuntionalTestBasic, self).setUp()
@@ -29,7 +30,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): # testcase (1515) def test_verify_left_bar_menu(self): self.get(reverse('all-projects')) - self.wait_until_present('#projectstable', poll=10) + self.load_projects_page_helper() self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav') self.assertTrue(self.element_exists('#config-nav'),'Configuration Tab does not exist')
@@ -82,7 +83,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): # testcase (1516) def test_review_configuration_information(self): self.get(reverse('all-projects')) - self.wait_until_present('#projectstable', poll=10) + self.load_projects_page_helper() self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() project_URL=self.get_URL()
@@ -131,7 +132,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): # testcase (1517) def test_verify_machine_information(self): self.get(reverse('all-projects')) - self.wait_until_present('#projectstable', poll=10) + self.load_projects_page_helper() self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_visible('#machine-section')
@@ -149,7 +150,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): # testcase (1518) def test_verify_most_built_recipes_information(self): self.get(reverse('all-projects')) - self.wait_until_present('#projectstable', poll=10) + self.load_projects_page_helper() self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav') project_URL=self.get_URL()
@@ -166,7 +167,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): # testcase (1519) def test_verify_project_release_information(self): self.get(reverse('all-projects')) - self.wait_until_present('#projectstable', poll=10) + self.load_projects_page_helper() self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_visible('#project-release-title') self.assertTrue(re.search("Yocto Project master",self.driver.find_element(By.ID, "project-release-title").text), 'No project release title information in project detail page')
@@ -174,7 +175,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): # testcase (1520) def test_verify_layer_information(self): self.get(reverse('all-projects')) - self.wait_until_present('#projectstable', poll=10) + self.load_projects_page_helper() self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav') project_URL=self.get_URL()
@@ -210,7 +211,7 @@ class FuntionalTestBasic(SeleniumFunctionalTestCase): # testcase (1521) def test_verify_project_detail_links(self): self.get(reverse('all-projects')) - self.wait_until_present('#projectstable', poll=10) + self.load_projects_page_helper() self.find_element_by_link_text_in_table('projectstable', 'selenium-project').click() self.wait_until_present('#config-nav') project_URL=self.get_URL()
PATCH 11/28 toaster/tests/functional/project_config: Fix the wait calls to avoid polling
In reply to Richard PurdieDrop poll calls within the module, adding wait calls for elements of the page where testing showed it was needed.
--- .../tests/functional/test_project_config.py | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-)
lib/toaster/tests/functional/test_project_config.py +21 -26
@@ -36,10 +36,10 @@ class TestProjectConfig(SeleniumFunctionalTestCase): url = reverse('projectconf', args=(TestProjectConfig.project_id,)) self.get(url) - self.wait_until_visible('#config-nav', poll=3) + self.wait_until_visible('#config-nav') bbv_page_link = self._get_config_nav_item(9) bbv_page_link.click() - self.wait_until_visible('#config-nav', poll=3) + self.wait_until_visible('#config-nav') def test_no_underscore_iamgefs_type(self): """
@@ -48,13 +48,13 @@ class TestProjectConfig(SeleniumFunctionalTestCase): self._navigate_bbv_page() imagefs_type = "foo_bar" - self.wait_until_visible('#change-image_fstypes-icon', poll=2) + self.wait_until_visible('#change-image_fstypes-icon') self.click('#change-image_fstypes-icon') self.enter_text('#new-imagefs_types', imagefs_type) - element = self.wait_until_visible('#hintError-image-fs_type', poll=2) + element = self.wait_until_visible('#hintError-image-fs_type') self.assertTrue(("A valid image type cannot include underscores" in element.text), "Did not find underscore error message")
@@ -68,7 +68,7 @@ class TestProjectConfig(SeleniumFunctionalTestCase): imagefs_type = "btrfs" - self.wait_until_visible('#change-image_fstypes-icon', poll=2) + self.wait_until_visible('#change-image_fstypes-icon') self.click('#change-image_fstypes-icon')
@@ -87,22 +87,20 @@ class TestProjectConfig(SeleniumFunctionalTestCase): """ self._navigate_bbv_page() - self.wait_until_visible('#change-image_fstypes-icon', poll=2) - + self.wait_until_visible('#change-image_fstypes-icon') self.click('#change-image_fstypes-icon') checkboxes_selector = '.fs-checkbox-fstypes' - self.wait_until_visible(checkboxes_selector, poll=2) + self.wait_until_visible(checkboxes_selector) checkboxes = self.find_all(checkboxes_selector) for checkbox in checkboxes: if checkbox.get_attribute("value") == "cpio": checkbox.click() + self.wait_until_visible('#new-imagefs_types') element = self.driver.find_element(By.ID, 'new-imagefs_types') - self.wait_until_visible('#new-imagefs_types', poll=2) - self.assertTrue(("cpio" in element.get_attribute('value'), "Imagefs not added into the textbox")) checkbox.click()
@@ -118,20 +116,19 @@ class TestProjectConfig(SeleniumFunctionalTestCase): # activate the input to edit download dir try: - change_dl_dir_btn = self.wait_until_visible('#change-dl_dir-icon', poll=2) + change_dl_dir_btn = self.wait_until_visible('#change-dl_dir-icon') except TimeoutException: # If download dir is not displayed, test is skipped change_dl_dir_btn = None if change_dl_dir_btn: - change_dl_dir_btn = self.wait_until_visible('#change-dl_dir-icon', poll=2) change_dl_dir_btn.click() # downloads dir path doesn't start with / or ${...} - input_field = self.wait_until_visible('#new-dl_dir', poll=2) + input_field = self.wait_until_visible('#new-dl_dir') input_field.clear() self.enter_text('#new-dl_dir', 'home/foo') - element = self.wait_until_visible('#hintError-initialChar-dl_dir', poll=2) + element = self.wait_until_visible('#hintError-initialChar-dl_dir') msg = 'downloads directory path starts with invalid character but ' \ 'treated as valid'
@@ -141,7 +138,7 @@ class TestProjectConfig(SeleniumFunctionalTestCase): self.driver.find_element(By.ID, 'new-dl_dir').clear() self.enter_text('#new-dl_dir', '/foo/bar a') - element = self.wait_until_visible('#hintError-dl_dir', poll=2) + element = self.wait_until_visible('#hintError-dl_dir') msg = 'downloads directory path characters invalid but treated as valid' self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
@@ -149,7 +146,7 @@ class TestProjectConfig(SeleniumFunctionalTestCase): self.driver.find_element(By.ID,'new-dl_dir').clear() self.enter_text('#new-dl_dir', '${TOPDIR}/down foo') - element = self.wait_until_visible('#hintError-dl_dir', poll=2) + element = self.wait_until_visible('#hintError-dl_dir') msg = 'downloads directory path characters invalid but treated as valid' self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
@@ -177,10 +174,7 @@ class TestProjectConfig(SeleniumFunctionalTestCase): self._navigate_bbv_page() try: - btn_chg_sstate_dir = self.wait_until_visible( - '#change-sstate_dir-icon', - poll=2 - ) + btn_chg_sstate_dir = self.wait_until_visible('#change-sstate_dir-icon') self.click('#change-sstate_dir-icon') except TimeoutException: # If sstate_dir is not displayed, test is skipped
@@ -188,10 +182,10 @@ class TestProjectConfig(SeleniumFunctionalTestCase): if btn_chg_sstate_dir: # Skip continuation if sstate_dir is not displayed # path doesn't start with / or ${...} - input_field = self.wait_until_visible('#new-sstate_dir', poll=2) + input_field = self.wait_until_visible('#new-sstate_dir') input_field.clear() self.enter_text('#new-sstate_dir', 'home/foo') - element = self.wait_until_visible('#hintError-initialChar-sstate_dir', poll=2) + element = self.wait_until_visible('#hintError-initialChar-sstate_dir') msg = 'sstate directory path starts with invalid character but ' \ 'treated as valid'
@@ -201,7 +195,7 @@ class TestProjectConfig(SeleniumFunctionalTestCase): self.driver.find_element(By.ID, 'new-sstate_dir').clear() self.enter_text('#new-sstate_dir', '/foo/bar a') - element = self.wait_until_visible('#hintError-sstate_dir', poll=2) + element = self.wait_until_visible('#hintError-sstate_dir') msg = 'sstate directory path characters invalid but treated as valid' self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
@@ -209,7 +203,7 @@ class TestProjectConfig(SeleniumFunctionalTestCase): self.driver.find_element(By.ID,'new-sstate_dir').clear() self.enter_text('#new-sstate_dir', '${TOPDIR}/down foo') - element = self.wait_until_visible('#hintError-sstate_dir', poll=2) + element = self.wait_until_visible('#hintError-sstate_dir') msg = 'sstate directory path characters invalid but treated as valid' self.assertTrue((self.INVALID_PATH_CHAR_TEXT in element.text), msg)
@@ -233,13 +227,14 @@ class TestProjectConfig(SeleniumFunctionalTestCase): var_name, field, btn_id, input_id, value, save_btn, *_ = kwargs.values() """ Change bitbake variable value """ self._navigate_bbv_page() - self.wait_until_visible(f'#{btn_id}', poll=2) + self.wait_until_visible(f'#{btn_id}') if kwargs.get('new_variable'): self.find(f"#{btn_id}").clear() self.enter_text(f"#{btn_id}", f"{var_name}") else: self.click(f'#{btn_id}') - self.wait_until_visible(f'#{input_id}', poll=2) + + self.wait_until_visible(f'#{input_id}') if kwargs.get('is_select'): select = Select(self.find(f'#{input_id}'))
PATCH 12/28 toaster/tests/functiona/project_page: Switch to using library create_project function
In reply to Richard PurdieSwitch this test module to use the common project creation code which contains race fixes. That code requires the database access wrapper be dropped and we no longer have ordering constraints.
There are two tests that do require database access. Move these to a separate class and allow database access there. Use ordering constraints to allow them to run after the main code. They depend on the project creation from the other class which isn't ideal but good enough for now.
--- .../tests/functional/test_project_page.py | 118 +++++++----------- 1 file changed, 42 insertions(+), 76 deletions(-)
lib/toaster/tests/functional/test_project_page.py +42 -76
@@ -7,7 +7,6 @@ # import os -import random import string from unittest import skip import pytest
@@ -22,58 +21,17 @@ from selenium.webdriver.common.by import By from .utils import get_projectId_from_url, wait_until_build, wait_until_build_cancelled - [email protected]_db [email protected]("last") -class TestProjectPage(SeleniumFunctionalTestCase): +class TestProjectPageBase(SeleniumFunctionalTestCase): project_id = None PROJECT_NAME = 'TestProjectPage' - def _create_project(self, project_name): - """ Create/Test new project using: - - Project Name: Any string - - Release: Any string - - Merge Toaster settings: True or False - """ - self.get(reverse('newproject')) - self.wait_until_visible('#new-project-name') - self.find("#new-project-name").send_keys(project_name) - select = Select(self.find("#projectversion")) - select.select_by_value('3') - - # check merge toaster settings - checkbox = self.find('.checkbox-mergeattr') - if not checkbox.is_selected(): - checkbox.click() - - if self.PROJECT_NAME != 'TestProjectPage': - # Reset project name if it's not the default one - self.PROJECT_NAME = 'TestProjectPage' - - self.find("#create-project-button").click() - - try: - self.wait_until_visible('#hint-error-project-name') - url = reverse('project', args=(TestProjectPage.project_id, )) - self.get(url) - self.wait_until_visible('#config-nav', poll=3) - except TimeoutException: - self.wait_until_visible('#config-nav', poll=3) - - def _random_string(self, length): - return ''.join( - random.choice(string.ascii_letters) for _ in range(length) - ) - def _navigate_to_project_page(self): # Navigate to project page - if TestProjectPage.project_id is None: - self._create_project(project_name=self._random_string(10)) - current_url = self.driver.current_url - TestProjectPage.project_id = get_projectId_from_url(current_url) - else: - url = reverse('project', args=(TestProjectPage.project_id,)) - self.get(url) + if TestProjectPageBase.project_id is None: + TestProjectPageBase.project_id = self.create_new_project(self.PROJECT_NAME, '3', None, True) + + url = reverse('project', args=(TestProjectPageBase.project_id,)) + self.get(url) self.wait_until_visible('#config-nav') def _get_create_builds(self, **kwargs):
@@ -81,14 +39,14 @@ class TestProjectPage(SeleniumFunctionalTestCase): # parameters for builds to associate with the projects now = timezone.now() self.project1_build_success = { - 'project': Project.objects.get(id=TestProjectPage.project_id), + 'project': Project.objects.get(id=TestProjectPageBase.project_id), 'started_on': now, 'completed_on': now, 'outcome': Build.SUCCEEDED } self.project1_build_failure = { - 'project': Project.objects.get(id=TestProjectPage.project_id), + 'project': Project.objects.get(id=TestProjectPageBase.project_id), 'started_on': now, 'completed_on': now, 'outcome': Build.FAILED
@@ -222,6 +180,8 @@ class TestProjectPage(SeleniumFunctionalTestCase): rows = self.find_all(f'#{table_selector} tbody tr') self.assertTrue(len(rows) > 0) +class TestProjectPage(TestProjectPageBase): + def test_create_project(self): """ Create/Test new project using: - Project Name: Any string
@@ -230,26 +190,6 @@ class TestProjectPage(SeleniumFunctionalTestCase): """ self._create_project(project_name=self.PROJECT_NAME) - def test_image_recipe_editColumn(self): - """ Test the edit column feature in image recipe table on project page """ - self._get_create_builds(success=10, failure=10) - - url = reverse('projectimagerecipes', args=(TestProjectPage.project_id,)) - self.get(url) - self.wait_until_present('#imagerecipestable tbody tr') - - column_list = [ - 'get_description_or_summary', 'layer_version__get_vcs_reference', - 'layer_version__layer__name', 'license', 'recipe-file', 'section', - 'version' - ] - - # Check that we can hide the edit column - self._mixin_test_table_edit_column( - 'imagerecipestable', - 'edit-columns-button', - [f'checkbox-{column}' for column in column_list] - ) def test_page_header_on_project_page(self): """ Check page header in project page:
@@ -379,7 +319,7 @@ class TestProjectPage(SeleniumFunctionalTestCase): self.assertEqual(config_tab.get_attribute('class'), 'active') self.assertIn('Configuration', str(config_tab.text)) self.assertIn( - f"/toastergui/project/{TestProjectPage.project_id}", str(self.driver.current_url) + f"/toastergui/project/{TestProjectPageBase.project_id}", str(self.driver.current_url) ) def get_tabs():
@@ -402,7 +342,7 @@ class TestProjectPage(SeleniumFunctionalTestCase): check_tab_link( 1, 'Builds', - f"/toastergui/project/{TestProjectPage.project_id}/builds" + f"/toastergui/project/{TestProjectPageBase.project_id}/builds" ) # check "Import layers" tab
@@ -411,7 +351,7 @@ class TestProjectPage(SeleniumFunctionalTestCase): check_tab_link( 2, 'Import layer', - f"/toastergui/project/{TestProjectPage.project_id}/importlayer" + f"/toastergui/project/{TestProjectPageBase.project_id}/importlayer" ) # check "New custom image" tab
@@ -420,7 +360,7 @@ class TestProjectPage(SeleniumFunctionalTestCase): check_tab_link( 3, 'New custom image', - f"/toastergui/project/{TestProjectPage.project_id}/newcustomimage" + f"/toastergui/project/{TestProjectPageBase.project_id}/newcustomimage" ) # check search box can be use to build recipes
@@ -766,6 +706,10 @@ class TestProjectPage(SeleniumFunctionalTestCase): # Check layer description self.assertIn("Description", section.text) [email protected]_db [email protected]("last") +class TestProjectPageRecipes(TestProjectPageBase): + def test_single_recipe_page(self): """ Test recipe page - Check if title is displayed
@@ -777,9 +721,9 @@ class TestProjectPage(SeleniumFunctionalTestCase): # Use a recipe which is likely to exist in the layer index but not enabled # in poky out the box - xen-image-minimal from meta-virtualization self._navigate_to_project_page() - prj = Project.objects.get(pk=TestProjectPage.project_id) + prj = Project.objects.get(pk=TestProjectPageBase.project_id) recipe_id = prj.get_all_compatible_recipes().get(name="xen-image-minimal").pk - url = reverse("recipedetails", args=(TestProjectPage.project_id, recipe_id)) + url = reverse("recipedetails", args=(TestProjectPageBase.project_id, recipe_id)) self.get(url) self.wait_until_visible('.page-header') # check title is displayed
@@ -802,3 +746,25 @@ class TestProjectPage(SeleniumFunctionalTestCase): self.assertIn("Approx. packages included", section.text) self.assertIn("Approx. package size", section.text) self.assertIn("Recipe file", section.text) + + def test_image_recipe_editColumn(self): + """ Test the edit column feature in image recipe table on project page """ + self._get_create_builds(success=10, failure=10) + + url = reverse('projectimagerecipes', args=(TestProjectPageBase.project_id,)) + self.get(url) + self.wait_until_present('#imagerecipestable tbody tr') + + column_list = [ + 'get_description_or_summary', 'layer_version__get_vcs_reference', + 'layer_version__layer__name', 'license', 'recipe-file', 'section', + 'version' + ] + + # Check that we can hide the edit column + self._mixin_test_table_edit_column( + 'imagerecipestable', + 'edit-columns-button', + [f'checkbox-{column}' for column in column_list] + ) +
PATCH 13/28 toaster/tests/functiona/project_page: Drop pointless test covered elsewhere
In reply to Richard PurdieThe project creation test is well covered in another module so just drop this one as there isn't any extra value added here.
--- lib/toaster/tests/functional/test_project_page.py | 9 --------- 1 file changed, 9 deletions(-)
lib/toaster/tests/functional/test_project_page.py +0 -9
@@ -182,15 +182,6 @@ class TestProjectPageBase(SeleniumFunctionalTestCase): class TestProjectPage(TestProjectPageBase): - def test_create_project(self): - """ Create/Test new project using: - - Project Name: Any string - - Release: Any string - - Merge Toaster settings: True or False - """ - self._create_project(project_name=self.PROJECT_NAME) - - def test_page_header_on_project_page(self): """ Check page header in project page: - AT LEFT -> Logo of Yocto project, displayed, clickable
PATCH 14/28 toaster/tests/functiona/project_page: Improve waits and drop polling
In reply to Richard PurdieThese changes:
* Drop the poll parameters
* Add waits where needed or make them more specific
* Add calls to close notification boxes since they can obscure other page elements
* In one case wait for a "Loading" message to be replaced
--- .../tests/functional/test_project_page.py | 53 ++++++++++++++----- 1 file changed, 40 insertions(+), 13 deletions(-)
lib/toaster/tests/functional/test_project_page.py +40 -13
@@ -8,6 +8,7 @@ import os import string +import time from unittest import skip import pytest from django.urls import reverse
@@ -150,7 +151,7 @@ class TestProjectPageBase(SeleniumFunctionalTestCase): def test_show_rows(row_to_show, show_row_link): # Check that we can show rows == row_to_show show_row_link.select_by_value(str(row_to_show)) - self.wait_until_visible(f'#{table_selector} tbody tr', poll=3) + self.wait_until_visible(f'#{table_selector} tbody tr') # check at least some rows are visible self.assertTrue( len(self.find_all(f'#{table_selector} tbody tr')) > 0
@@ -359,11 +360,15 @@ class TestProjectPage(TestProjectPageBase): search_box.send_keys('core-image-minimal') self.find('#build-button').click() self.wait_until_visible('#latest-builds') - lastest_builds = self.driver.find_elements( - By.XPATH, - '//div[@id="latest-builds"]', - ) - last_build = lastest_builds[0] + buildtext = "Loading" + while "Loading" in buildtext: + time.sleep(1) + lastest_builds = self.driver.find_elements( + By.XPATH, + '//div[@id="latest-builds"]', + ) + last_build = lastest_builds[0] + buildtext = last_build.text self.assertIn( 'core-image-minimal', str(last_build.text) )
@@ -471,7 +476,8 @@ class TestProjectPage(TestProjectPageBase): searchBtn_selector='search-submit-machinestable', table_selector='machinestable' ) - self.wait_until_visible('#machinestable tbody tr', poll=3) + + self.wait_until_visible('#machinestable tbody tr') rows = self.find_all('#machinestable tbody tr') machine_to_add = rows[0] add_btn = machine_to_add.find_element(By.XPATH, '//td[@class="add-del-layers"]')
@@ -481,6 +487,11 @@ class TestProjectPage(TestProjectPageBase): self.assertIn( f'You have added 1 layer to your project', str(change_notification.text) ) + + hide_button = self.find('#hide-alert') + hide_button.click() + self.wait_until_not_visible('#change-notification') + # check Machine table feature(show/hide column, pagination) self._navigate_to_config_nav('machinestable', 5) column_list = [
@@ -521,7 +532,7 @@ class TestProjectPage(TestProjectPageBase): table_selector='layerstable' ) # check "Add layer" button works - self.wait_until_visible('#layerstable tbody tr', poll=3) + self.wait_until_visible('#layerstable tbody tr') rows = self.find_all('#layerstable tbody tr') layer_to_add = rows[0] add_btn = layer_to_add.find_element(
@@ -530,7 +541,7 @@ class TestProjectPage(TestProjectPageBase): ) add_btn.click() # check modal is displayed - self.wait_until_visible('#dependencies-modal', poll=3) + self.wait_until_visible('#dependencies-modal') list_dependencies = self.find_all('#dependencies-list li') # click on add-layers button add_layers_btn = self.driver.find_element(
@@ -543,8 +554,13 @@ class TestProjectPage(TestProjectPageBase): self.assertIn( f'You have added {len(list_dependencies)+1} layers to your project: {input_text} and its dependencies', str(change_notification.text) ) + + hide_button = self.find('#hide-alert') + hide_button.click() + self.wait_until_not_visible('#change-notification') + # check "Remove layer" button works - self.wait_until_visible('#layerstable tbody tr', poll=3) + self.wait_until_visible('#layerstable tbody tr') rows = self.find_all('#layerstable tbody tr') layer_to_remove = rows[0] remove_btn = layer_to_remove.find_element(
@@ -552,11 +568,16 @@ class TestProjectPage(TestProjectPageBase): '//td[@class="add-del-layers"]' ) remove_btn.click() - self.wait_until_visible('#change-notification', poll=2) + self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification') self.assertIn( f'You have removed 1 layer from your project: {input_text}', str(change_notification.text) ) + + hide_button = self.find('#hide-alert') + hide_button.click() + self.wait_until_not_visible('#change-notification') + # check layers table feature(show/hide column, pagination) self._navigate_to_config_nav('layerstable', 6) column_list = [
@@ -604,7 +625,7 @@ class TestProjectPage(TestProjectPageBase): '//td[@class="add-del-layers"]//a[1]' ) add_btn.click() - self.wait_until_visible('#change-notification', poll=2) + self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification') self.assertIn( f'You have changed the distro to: {input_text}', str(change_notification.text)
@@ -649,12 +670,15 @@ class TestProjectPage(TestProjectPageBase): # check remove layer button works remove_layer_btn = self.find('#add-remove-layer-btn') remove_layer_btn.click() - self.wait_until_visible('#change-notification', poll=2) + self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification') self.assertIn( f'You have removed 1 layer from your project', str(change_notification.text) ) + hide_button = self.find('#hide-alert') + hide_button.click() # check add layer button works + self.wait_until_not_visible('#change-notification') add_layer_btn = self.find('#add-remove-layer-btn') add_layer_btn.click() self.wait_until_visible('#change-notification')
@@ -662,6 +686,9 @@ class TestProjectPage(TestProjectPageBase): self.assertIn( f'You have added 1 layer to your project', str(change_notification.text) ) + hide_button = self.find('#hide-alert') + hide_button.click() + self.wait_until_not_visible('#change-notification') # check tabs(layers, recipes, machines) are displayed tabs = self.find_all('.nav-tabs li') self.assertEqual(len(tabs), 3)
PATCH 15/28 toaster/tests/browser/helpers: Add not visible wait function
In reply to Richard PurdieIn some cases we want to wait until some element is not visible. Add such a function helper.
--- lib/toaster/tests/browser/selenium_helpers_base.py | 7 +++++++ 1 file changed, 7 insertions(+)
lib/toaster/tests/browser/selenium_helpers_base.py +7 -0
@@ -227,6 +227,13 @@ class SeleniumTestCaseBase(unittest.TestCase): Wait(self.driver, poll=poll).until(is_visible, msg) return self.find(selector) + def wait_until_not_visible(self, selector, timeout=Wait._TIMEOUT): + """ Wait until element matching CSS selector is not visible on the page """ + is_visible = lambda driver: self.find(selector).is_displayed() + msg = 'An element matching "%s" should be visible' % selector + Wait(self.driver, timeout=timeout).until_not(is_visible, msg) + return self.find(selector) + def wait_until_clickable(self, selector, poll=1): """ Wait until element matching CSS selector is visible on the page """ sel = selector
PATCH 16/28 toaster/tests/functiona/project_page_tab_config: Switch to using library create_project function
In reply to Richard PurdieSwitch this test module to use the common project creation code which contains race fixes. That code requires the database access wrapper be dropped and we no longer have ordering constraints.
There is one test that does require database access. Move this to a separate class and allow database access there. Use ordering constraints to allow them to run after the main code. They depend on the project creation from the other class which isn't ideal but good enough for now.
--- .../test_project_page_tab_config.py | 213 ++++++++---------- 1 file changed, 90 insertions(+), 123 deletions(-)
lib/toaster/tests/functional/test_project_page_tab_config.py +90 -123
@@ -7,7 +7,6 @@ # import string -import random import pytest from django.urls import reverse from selenium.webdriver import Keys
@@ -19,60 +18,16 @@ from selenium.webdriver.common.by import By from .utils import get_projectId_from_url, wait_until_build, wait_until_build_cancelled - [email protected]_db [email protected]("last") -class TestProjectConfigTab(SeleniumFunctionalTestCase): +class TestProjectConfigTabBase(SeleniumFunctionalTestCase): PROJECT_NAME = 'TestProjectConfigTab' project_id = None - def _create_project(self, project_name, **kwargs): - """ Create/Test new project using: - - Project Name: Any string - - Release: Any string - - Merge Toaster settings: True or False - """ - release = kwargs.get('release', '3') - self.get(reverse('newproject')) - self.wait_until_visible('#new-project-name') - self.find("#new-project-name").send_keys(project_name) - select = Select(self.find("#projectversion")) - select.select_by_value(release) - - # check merge toaster settings - checkbox = self.find('.checkbox-mergeattr') - if not checkbox.is_selected(): - checkbox.click() - - if self.PROJECT_NAME != 'TestProjectConfigTab': - # Reset project name if it's not the default one - self.PROJECT_NAME = 'TestProjectConfigTab' - - self.find("#create-project-button").click() - - try: - self.wait_until_visible('#hint-error-project-name', poll=3) - url = reverse('project', args=(TestProjectConfigTab.project_id, )) - self.get(url) - self.wait_until_visible('#config-nav', poll=3) - except TimeoutException: - self.wait_until_visible('#config-nav', poll=3) - - def _random_string(self, length): - return ''.join( - random.choice(string.ascii_letters) for _ in range(length) - ) - def _navigate_to_project_page(self): # Navigate to project page - if TestProjectConfigTab.project_id is None: - self._create_project(project_name=self._random_string(10)) - current_url = self.driver.current_url - TestProjectConfigTab.project_id = get_projectId_from_url( - current_url) - else: - url = reverse('project', args=(TestProjectConfigTab.project_id,)) - self.get(url) + if TestProjectConfigTabBase.project_id is None: + TestProjectConfigTabBase.project_id = self.create_new_project(self.PROJECT_NAME, '3', None, True) + url = reverse('project', args=(TestProjectConfigTabBase.project_id,)) + self.get(url) self.wait_until_visible('#config-nav') def _create_builds(self):
@@ -114,6 +69,8 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): config_nav = self.find('#config-nav') return config_nav.find_elements(By.TAG_NAME, 'li')[index] +class TestProjectConfigTab(TestProjectConfigTabBase): + def test_project_config_nav(self): """ Test project config tab navigation: - Check if the menu is displayed and contains the right elements:
@@ -160,26 +117,26 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): conf_nav_list = [ # config [0, 'Configuration', - f"/toastergui/project/{TestProjectConfigTab.project_id}"], + f"/toastergui/project/{TestProjectConfigTabBase.project_id}"], # custom images [2, 'Custom images', - f"/toastergui/project/{TestProjectConfigTab.project_id}/customimages"], + f"/toastergui/project/{TestProjectConfigTabBase.project_id}/customimages"], # image recipes [3, 'Image recipes', - f"/toastergui/project/{TestProjectConfigTab.project_id}/images"], + f"/toastergui/project/{TestProjectConfigTabBase.project_id}/images"], # software recipes [4, 'Software recipes', - f"/toastergui/project/{TestProjectConfigTab.project_id}/softwarerecipes"], + f"/toastergui/project/{TestProjectConfigTabBase.project_id}/softwarerecipes"], # machines [5, 'Machines', - f"/toastergui/project/{TestProjectConfigTab.project_id}/machines"], + f"/toastergui/project/{TestProjectConfigTabBase.project_id}/machines"], # layers [6, 'Layers', - f"/toastergui/project/{TestProjectConfigTab.project_id}/layers"], + f"/toastergui/project/{TestProjectConfigTabBase.project_id}/layers"], # distro [7, 'Distros', - f"/toastergui/project/{TestProjectConfigTab.project_id}/distros"], - # [9, 'BitBake variables', f"/toastergui/project/{TestProjectConfigTab.project_id}/configuration"], # bitbake variables + f"/toastergui/project/{TestProjectConfigTabBase.project_id}/distros"], + # [9, 'BitBake variables', f"/toastergui/project/{TestProjectConfigTabBase.project_id}/configuration"], # bitbake variables ] for index, item_name, url in conf_nav_list: item = _get_config_nav_item(index)
@@ -299,9 +256,11 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): - meta-poky - meta-yocto-bsp """ - # Create a new project for this test - project_name = self._random_string(10) - self._create_project(project_name=project_name) + project_id = self.create_new_project(self.PROJECT_NAME + "-ST", '3', None, True) + url = reverse('project', args=(project_id,)) + self.get(url) + self.wait_until_visible('#config-nav') + # check if the menu is displayed self.wait_until_visible('#project-page') block_l = self.driver.find_element(
@@ -374,61 +333,6 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): layers_list_items = layers_list.find_elements(By.TAG_NAME, 'li') self.assertEqual(len(layers_list_items), 4) - def test_most_build_recipes(self): - """ Test most build recipes block contains""" - def rebuild_from_most_build_recipes(recipe_list_items): - checkbox = recipe_list_items[0].find_element(By.TAG_NAME, 'input') - checkbox.click() - build_btn = self.find('#freq-build-btn') - build_btn.click() - self.wait_until_visible('#latest-builds') - wait_until_build(self, 'queued cloning starting parsing failed') - lastest_builds = self.driver.find_elements( - By.XPATH, - '//div[@id="latest-builds"]/div' - ) - self.assertTrue(len(lastest_builds) >= 2) - last_build = lastest_builds[0] - try: - cancel_button = last_build.find_element( - By.XPATH, - '//span[@class="cancel-build-btn pull-right alert-link"]', - ) - cancel_button.click() - except NoSuchElementException: - # Skip if the build is already cancelled - pass - wait_until_build_cancelled(self) - # Create a new project for remaining asserts - project_name = self._random_string(10) - self._create_project(project_name=project_name, release='2') - current_url = self.driver.current_url - TestProjectConfigTab.project_id = get_projectId_from_url(current_url) - url = current_url.split('?')[0] - - # Create a new builds - self._create_builds() - - # back to project page - self.driver.get(url) - - self.wait_until_visible('#project-page', poll=3) - - # Most built recipes - most_built_recipes = self.driver.find_element( - By.XPATH, '//*[@id="project-page"]/div[1]/div[3]') - title = most_built_recipes.find_element(By.TAG_NAME, 'h3') - self.assertIn("Most built recipes", title.text) - # check can select a recipe and build it - self.wait_until_visible('#freq-build-list', poll=3) - recipe_list = self.find('#freq-build-list') - recipe_list_items = recipe_list.find_elements(By.TAG_NAME, 'li') - self.assertTrue( - len(recipe_list_items) > 0, - msg="No recipes found in the most built recipes list", - ) - rebuild_from_most_build_recipes(recipe_list_items) - TestProjectConfigTab.project_id = None # reset project id def test_project_page_tab_importlayer(self): """ Test project page tab import layer """
@@ -472,10 +376,11 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): def test_project_page_custom_image_no_image(self): """ Test project page tab "New custom image" when no custom image """ - project_name = self._random_string(10) - self._create_project(project_name=project_name) - current_url = self.driver.current_url - TestProjectConfigTab.project_id = get_projectId_from_url(current_url) + project_id = self.create_new_project(self.PROJECT_NAME + "-CustomImage", '3', None, True) + url = reverse('project', args=(project_id,)) + self.get(url) + self.wait_until_visible('#config-nav') + # navigate to "Custom image" tab custom_image_section = self._get_config_nav_item(2) custom_image_section.click()
@@ -490,9 +395,9 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): div_empty_msg = self.find('#empty-state-customimagestable') link_create_custom_image = div_empty_msg.find_element( By.TAG_NAME, 'a') - self.assertTrue(TestProjectConfigTab.project_id is not None) + self.assertTrue(TestProjectConfigTabBase.project_id is not None) self.assertIn( - f"/toastergui/project/{TestProjectConfigTab.project_id}/newcustomimage", str( + f"/toastergui/project/{project_id}/newcustomimage", str( link_create_custom_image.get_attribute('href') ) )
@@ -501,7 +406,6 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): link_create_custom_image.text ) ) - TestProjectConfigTab.project_id = None # reset project id def test_project_page_image_recipe(self): """ Test project page section images
@@ -526,3 +430,66 @@ class TestProjectConfigTab(SeleniumFunctionalTestCase): self.wait_until_visible('#imagerecipestable tbody tr') rows = self.find_all('#imagerecipestable tbody tr') self.assertTrue(len(rows) > 0) + [email protected]_db [email protected]("last") +class TestProjectConfigTabDB(TestProjectConfigTabBase): + + def test_most_build_recipes(self): + """ Test most build recipes block contains""" + def rebuild_from_most_build_recipes(recipe_list_items): + checkbox = recipe_list_items[0].find_element(By.TAG_NAME, 'input') + checkbox.click() + build_btn = self.find('#freq-build-btn') + build_btn.click() + self.wait_until_visible('#latest-builds') + wait_until_build(self, 'queued cloning starting parsing failed') + lastest_builds = self.driver.find_elements( + By.XPATH, + '//div[@id="latest-builds"]/div' + ) + self.assertTrue(len(lastest_builds) >= 2) + last_build = lastest_builds[0] + try: + cancel_button = last_build.find_element( + By.XPATH, + '//span[@class="cancel-build-btn pull-right alert-link"]', + ) + cancel_button.click() + except NoSuchElementException: + # Skip if the build is already cancelled + pass + wait_until_build_cancelled(self) + + # Create a new project for remaining asserts + project_id = self.create_new_project(self.PROJECT_NAME + "-MostBuilt", '2', None, True) + url = reverse('project', args=(project_id,)) + self.get(url) + self.wait_until_visible('#config-nav') + + current_url = self.driver.current_url + url = current_url.split('?')[0] + + # Create a new builds + self._create_builds() + + # back to project page + self.driver.get(url) + + self.wait_until_visible('#project-page', poll=3) + + # Most built recipes + most_built_recipes = self.driver.find_element( + By.XPATH, '//*[@id="project-page"]/div[1]/div[3]') + title = most_built_recipes.find_element(By.TAG_NAME, 'h3') + self.assertIn("Most built recipes", title.text) + # check can select a recipe and build it + self.wait_until_visible('#freq-build-list', poll=3) + recipe_list = self.find('#freq-build-list') + recipe_list_items = recipe_list.find_elements(By.TAG_NAME, 'li') + self.assertTrue( + len(recipe_list_items) > 0, + msg="No recipes found in the most built recipes list", + ) + rebuild_from_most_build_recipes(recipe_list_items) +
PATCH 17/28 toaster/tests/functiona/project_page_tab_config: Improve waits and drop polling
In reply to Richard PurdieDrop the poll parameters and make the waits much more specific for the requirements of the tests. This includes looping waiting for a list of layer elements as that code was previously particularly fragile.
--- .../test_project_page_tab_config.py | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-)
lib/toaster/tests/functional/test_project_page_tab_config.py +32 -20
@@ -7,12 +7,12 @@ # import string +import time import pytest from django.urls import reverse from selenium.webdriver import Keys from selenium.webdriver.support.select import Select from selenium.common.exceptions import ElementClickInterceptedException, NoSuchElementException, TimeoutException -from orm.models import Project from tests.functional.functional_helpers import SeleniumFunctionalTestCase from selenium.webdriver.common.by import By
@@ -210,7 +210,7 @@ class TestProjectConfigTab(TestProjectConfigTabBase): def test_show_rows(row_to_show, show_row_link): # Check that we can show rows == row_to_show show_row_link.select_by_value(str(row_to_show)) - self.wait_until_visible('#imagerecipestable tbody tr', poll=3) + self.wait_until_visible('#imagerecipestable tbody tr') # check at least some rows are visible self.assertTrue( len(self.find_all('#imagerecipestable tbody tr')) > 0
@@ -289,6 +289,9 @@ class TestProjectConfigTab(TestProjectConfigTabBase): self.assertIn( f'You have changed the {item_name} to: {new_item_name}', change_notification.text ) + hide_button = self.find('#hide-alert') + hide_button.click() + self.wait_until_not_visible('#change-notification') # Machine check_machine_distro(self, 'machine', 'qemux86-64', 'machine-section')
@@ -304,35 +307,44 @@ class TestProjectConfigTab(TestProjectConfigTabBase): # Layers title = layers.find_element(By.TAG_NAME, 'h3') self.assertIn("Layers", title.text) + self.wait_until_clickable('#layer-add-input') # check at least three layers are displayed # openembedded-core # meta-poky # meta-yocto-bsp - layers_list = layers.find_element(By.ID, 'layers-in-project-list') - layers_list_items = layers_list.find_elements(By.TAG_NAME, 'li') + layer_list_items = [] + starttime = time.time() + while len(layer_list_items) < 3: + layers_list = self.driver.find_element(By.ID, 'layers-in-project-list') + layer_list_items = layers_list.find_elements(By.TAG_NAME, 'li') + if time.time() > (starttime + 30): + self.fail("Layer list didn't contain at least 3 items within 30s (contained %d)" % len(layer_list_items)) + # remove all layers except the first three layers - for i in range(3, len(layers_list_items)): - layers_list_items[i].find_element(By.TAG_NAME, 'span').click() + for i in range(3, len(layer_list_items)): + layer_list_items[i].find_element(By.TAG_NAME, 'span').click() + # check can add a layer if exists add_layer_input = layers.find_element(By.ID, 'layer-add-input') add_layer_input.send_keys('meta-oe') self.wait_until_visible('#layer-container > form > div > span > div') - dropdown_item = self.driver.find_element( - By.XPATH, - '//*[@id="layer-container"]/form/div/span/div' - ) - try: - dropdown_item.click() - except ElementClickInterceptedException: - self.skipTest( - "layer-container dropdown item click intercepted. Element not properly visible.") + 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.click() + self.wait_until_clickable('#add-layer-btn') add_layer_btn = layers.find_element(By.ID, 'add-layer-btn') add_layer_btn.click() self.wait_until_visible('#layers-in-project-list') - # check layer is added - layers_list_items = layers_list.find_elements(By.TAG_NAME, 'li') - self.assertEqual(len(layers_list_items), 4) + # check layer is added + layer_list_items = [] + starttime = time.time() + while len(layer_list_items) < 4: + layers_list = self.driver.find_element(By.ID, 'layers-in-project-list') + layer_list_items = layers_list.find_elements(By.TAG_NAME, 'li') + if time.time() > (starttime + 30): + self.fail("Layer list didn't contain at least 4 items within 30s (contained %d)" % len(layer_list_items)) def test_project_page_tab_importlayer(self): """ Test project page tab import layer """
@@ -476,7 +488,7 @@ class TestProjectConfigTabDB(TestProjectConfigTabBase): # back to project page self.driver.get(url) - self.wait_until_visible('#project-page', poll=3) + self.wait_until_visible('#project-page') # Most built recipes most_built_recipes = self.driver.find_element(
@@ -484,7 +496,7 @@ class TestProjectConfigTabDB(TestProjectConfigTabBase): title = most_built_recipes.find_element(By.TAG_NAME, 'h3') self.assertIn("Most built recipes", title.text) # check can select a recipe and build it - self.wait_until_visible('#freq-build-list', poll=3) + self.wait_until_visible('#freq-build-list') recipe_list = self.find('#freq-build-list') recipe_list_items = recipe_list.find_elements(By.TAG_NAME, 'li') self.assertTrue(
PATCH 18/28 toaster/tests/browser/helpers: Drop remains of polling/sleep calls
In reply to Richard PurdieDrop the remaining poll parameters from the helpers code along with the remaining sleep call since the tests no longer depend on this.
This has the nice benefit of significantly speeding up the toaster test runs (45 minutes down to 12 minutes overall).
If a parameter is needed, it should be the timeout, not the polling frequency.
--- .../tests/browser/selenium_helpers_base.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
lib/toaster/tests/browser/selenium_helpers_base.py +7 -10
@@ -186,7 +186,7 @@ class SeleniumTestCaseBase(unittest.TestCase): self.driver.get(abs_url) try: # Ensure page is loaded before proceeding - self.wait_until_visible("#global-nav", poll=3) + self.wait_until_visible("#global-nav") except NoSuchElementException: self.driver.implicitly_wait(3) except TimeoutException:
@@ -211,20 +211,18 @@ class SeleniumTestCaseBase(unittest.TestCase): """ Return the element which currently has focus on the page """ return self.driver.switch_to.active_element - def wait_until_present(self, selector, poll=0.5): + def wait_until_present(self, selector, timeout=Wait._TIMEOUT): """ Wait until element matching CSS selector is on the page """ is_present = lambda driver: self.find(selector) msg = 'An element matching "%s" should be on the page' % selector - element = Wait(self.driver, poll=poll).until(is_present, msg) - if poll > 2: - time.sleep(poll) # element need more delay to be present + element = Wait(self.driver, timeout=timeout).until(is_present, msg) return element - def wait_until_visible(self, selector, poll=1): + def wait_until_visible(self, selector, timeout=Wait._TIMEOUT): """ Wait until element matching CSS selector is visible on the page """ is_visible = lambda driver: self.find(selector).is_displayed() msg = 'An element matching "%s" should be visible' % selector - Wait(self.driver, poll=poll).until(is_visible, msg) + Wait(self.driver, timeout=timeout).until(is_visible, msg) return self.find(selector) def wait_until_not_visible(self, selector, timeout=Wait._TIMEOUT):
@@ -234,15 +232,14 @@ class SeleniumTestCaseBase(unittest.TestCase): Wait(self.driver, timeout=timeout).until_not(is_visible, msg) return self.find(selector) - def wait_until_clickable(self, selector, poll=1): + def wait_until_clickable(self, selector, timeout=Wait._TIMEOUT): """ Wait until element matching CSS selector is visible on the page """ sel = selector if sel.startswith('#'): sel = selector[1:] WebDriverWait( self.driver, - Wait._TIMEOUT, - poll_frequency=poll + timeout=timeout, ).until( EC.element_to_be_clickable((By.ID, sel )
PATCH 19/28 functional/utils: Drop unused code from wait_until_build_cancelled
In reply to Richard PurdieThe code modifying the build object requires direct database access which is potentially problematic. It was being run on a database which was being reset after changes anyway so the code effectively did nothing. Remove it as it is unneeded.
--- lib/toaster/tests/functional/utils.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
lib/toaster/tests/functional/utils.py +1 -6
@@ -48,7 +48,6 @@ def wait_until_build_cancelled(test_instance): """ timeout = 30 start_time = 0 - build = None while True: try: if start_time > timeout:
@@ -64,11 +63,7 @@ def wait_until_build_cancelled(test_instance): if 'failed' in str(build_state).lower(): break if 'cancelling' in str(build_state).lower(): - # Change build state to cancelled - if not build: # get build object only once - build = Build.objects.last() - build.outcome = Build.CANCELLED - build.save() + pass if 'cancelled' in str(build_state).lower(): break except NoSuchElementException:
PATCH 20/28 toaster/tests/browser/helper: Improve wait_until_clickable exception handling
In reply to Richard PurdieOur own Wait() class allows exception handling which this form of wrapper does not. Switch the code to use our Wait() class to allow retrying upon encountering those exceptions (such as an element not being present yet).
The displayed and visible test is what Selenium would be doing internally, there is no JS reprensetation of clickable directly.
--- lib/toaster/tests/browser/selenium_helpers_base.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
lib/toaster/tests/browser/selenium_helpers_base.py +3 -11
@@ -234,17 +234,9 @@ class SeleniumTestCaseBase(unittest.TestCase): def wait_until_clickable(self, selector, timeout=Wait._TIMEOUT): """ Wait until element matching CSS selector is visible on the page """ - sel = selector - if sel.startswith('#'): - sel = selector[1:] - WebDriverWait( - self.driver, - timeout=timeout, - ).until( - EC.element_to_be_clickable((By.ID, sel - ) - ) - ) + is_clickable = lambda driver: (self.find(selector).is_displayed() and self.find(selector).is_enabled()) + msg = 'An element matching "%s" should be clickable' % selector + Wait(self.driver, timeout=timeout).until(is_clickable, msg) return self.find(selector) def wait_until_focused(self, selector):
PATCH 21/28 toaster/tests/browser/helper: Add wait_until_element_clickable funciton
In reply to Richard PurdieAdd a variant of the clickable function that accepts an element parameter.
--- lib/toaster/tests/browser/selenium_helpers_base.py | 7 +++++++ 1 file changed, 7 insertions(+)
lib/toaster/tests/browser/selenium_helpers_base.py +7 -0
@@ -239,6 +239,13 @@ 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): + """ Wait until element is clickable """ + is_clickable = lambda driver: (finder(driver).is_displayed() and finder(driver).is_enabled()) + msg = 'A matching element never became be clickable' + Wait(self.driver, timeout=timeout).until(is_clickable, msg) + return finder(self.driver) + def wait_until_focused(self, selector): """ Wait until element matching CSS selector has focus """ is_focused = \
PATCH 22/28 toaster/tests/browser: Add various fixes for test failures encountered
In reply to Richard PurdieFixes for the browser tests which:
* Add/improve waiting for specific elements
* Waiting for elements to be interactable, not just visible
* Hiding notification windows
* Using more specific asserts to obtain improved error messages
--- lib/toaster/tests/browser/test_all_builds_page.py | 1 + lib/toaster/tests/browser/test_landing_page.py | 1 + lib/toaster/tests/browser/test_layerdetails_page.py | 12 +++++++++--- lib/toaster/tests/browser/test_new_project_page.py | 6 ++---- 4 files changed, 13 insertions(+), 7 deletions(-)
lib/toaster/tests/browser/test_all_builds_page.py +1 -0
@@ -200,6 +200,7 @@ class TestAllBuildsPage(SeleniumTestCase): # should see a rebuild button for non-command-line builds self.wait_until_visible('#allbuildstable tbody tr') + self.wait_until_visible('.rebuild-btn') selector = 'div[data-latest-build-result="%s"] .rebuild-btn' % build1.id run_again_button = self.find_all(selector) self.assertEqual(len(run_again_button), 1,
lib/toaster/tests/browser/test_landing_page.py +1 -0
@@ -44,6 +44,7 @@ class TestLandingPage(SeleniumTestCase): # and info modal is appearing when clicking on the info sign info_sign.click() # click on the info sign make attribute 'aria-describedby' visible info_model_id = info_sign.get_attribute('aria-describedby') + self.wait_until_visible(f'#{info_model_id}') info_modal = self.find(f'#{info_model_id}') self.assertTrue(info_modal.is_displayed()) self.assertTrue("Toaster version information" in info_modal.text)
lib/toaster/tests/browser/test_layerdetails_page.py +9 -3
@@ -100,7 +100,7 @@ class TestLayerDetailsPage(SeleniumTestCase): (self.initial_values, value)) # Make sure the input visible beofre sending keys - self.wait_until_visible("#layer-git input[type=text]") + self.wait_until_clickable("#layer-git input[type=text]") inputs.send_keys("-edited") # Save the new values
@@ -211,6 +211,7 @@ class TestLayerDetailsPage(SeleniumTestCase): self.get(self.url) # Add the layer + self.wait_until_clickable("#add-remove-layer-btn") self.click("#add-remove-layer-btn") notification = self.wait_until_visible("#change-notification-msg")
@@ -218,12 +219,17 @@ class TestLayerDetailsPage(SeleniumTestCase): expected_text = "You have added 1 layer to your project: %s" % \ self.imported_layer_version.layer.name - self.assertTrue(expected_text in notification.text, + self.assertIn(expected_text, notification.text, "Expected notification text %s not found was " " \"%s\" instead" % (expected_text, notification.text)) + hide_button = self.find('#hide-alert') + hide_button.click() + self.wait_until_not_visible('#change-notification') + # Remove the layer + self.wait_until_clickable("#add-remove-layer-btn") self.click("#add-remove-layer-btn") notification = self.wait_until_visible("#change-notification-msg")
@@ -231,7 +237,7 @@ class TestLayerDetailsPage(SeleniumTestCase): expected_text = "You have removed 1 layer from your project: %s" % \ self.imported_layer_version.layer.name - self.assertTrue(expected_text in notification.text, + self.assertIn(expected_text, notification.text, "Expected notification text %s not found was " " \"%s\" instead" % (expected_text, notification.text))
lib/toaster/tests/browser/test_new_project_page.py +2 -4
@@ -89,12 +89,10 @@ class TestNewProjectPage(SeleniumTestCase): radio = self.driver.find_element(By.ID, 'type-new') radio.click() - self.click("#create-project-button") - - self.wait_until_present('#hint-error-project-name') + self.wait_until_visible('#hint-error-project-name') element = self.find('#hint-error-project-name') - self.assertTrue(("Project names must be unique" in element.text), + self.assertIn("Project names must be unique", element.text, "Did not find unique project name error message") # Try and click it anyway, if it submits we'll have a new project in
PATCH 23/28 toaster/tests/functional/util: Avoid test hangs
In reply to Richard PurdieIf the element never exists, the timeout is never incremented and the test hangs indefinitely. Fix the exception handling to avoid that and allow the timeout to happen.
--- lib/toaster/tests/functional/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/toaster/tests/functional/utils.py +1 -1
@@ -36,7 +36,7 @@ def wait_until_build(test_instance, state): if 'failed' in str(build_state).lower(): break except NoSuchElementException: - continue + pass except TimeoutException: break start_time += 1
PATCH 24/28 toaster/tests/functional/project_page: Use wait_until_element_clickable before click calls
In reply to Richard PurdieSwitch the clickable() calls to use the new element_clickable() function which accepts a finder labmda function. This means if the element doesn't yet exist, the code can rebuild the query and try again once a small amount of time has elapsed.
There were a ton of timing related races around these element interactions and this seemed to be the most robust way to address the issues.
The change also makes some of the elements slightly more specific so the code can work effectively.
--- .../tests/functional/test_project_page.py | 93 ++++++++----------- 1 file changed, 40 insertions(+), 53 deletions(-)
lib/toaster/tests/functional/test_project_page.py +40 -53
@@ -92,7 +92,8 @@ class TestProjectPageBase(SeleniumFunctionalTestCase): list_check_box_id: list ): # Check edit column - edit_column = self.find(f'#{edit_btn_id}') + finder = lambda driver: self.find(f'#{edit_btn_id}') + edit_column = self.wait_until_element_clickable(finder) self.assertTrue(edit_column.is_displayed()) edit_column.click() # Check dropdown is visible
@@ -280,7 +281,8 @@ class TestProjectPage(TestProjectPageBase): # click on "Edit" icon button self.wait_until_visible('#project-name-container') - edit_button = self.find('#project-change-form-toggle') + finder = lambda driver: self.find('#project-change-form-toggle') + edit_button = self.wait_until_element_clickable(finder) edit_button.click() project_name_input = self.find('#project-name-change-input') self.assertTrue(project_name_input.is_displayed())
@@ -391,12 +393,8 @@ class TestProjectPage(TestProjectPageBase): table_selector='softwarerecipestable' ) # check "build recipe" button works - rows = self.find_all('#softwarerecipestable tbody tr') - image_to_build = rows[0] - build_btn = image_to_build.find_element( - By.XPATH, - '//td[@class="add-del-layers"]//a[1]' - ) + 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.click() build_state = wait_until_build(self, 'queued cloning starting parsing failed') lastest_builds = self.driver.find_elements(
@@ -404,11 +402,10 @@ class TestProjectPage(TestProjectPageBase): '//div[@id="latest-builds"]/div' ) self.assertTrue(len(lastest_builds) > 0) - last_build = lastest_builds[0] - cancel_button = last_build.find_element( - By.XPATH, - '//span[@class="cancel-build-btn pull-right alert-link"]', - ) + # 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.click() if 'starting' not in build_state: # change build state when cancelled in starting state wait_until_build_cancelled(self)
@@ -455,14 +452,10 @@ class TestProjectPage(TestProjectPageBase): table_selector='machinestable' ) # check "Select machine" button works - rows = self.find_all('#machinestable tbody tr') - machine_to_select = rows[0] - select_btn = machine_to_select.find_element( - By.XPATH, - '//td[@class="add-del-layers"]//a[1]' - ) - select_btn.send_keys(Keys.RETURN) - self.wait_until_visible('#config-nav') + 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.click() + self.wait_until_visible('#project-machine-name') project_machine_name = self.find('#project-machine-name') self.assertIn( 'qemux86-64', project_machine_name.text
@@ -478,9 +471,9 @@ class TestProjectPage(TestProjectPageBase): ) self.wait_until_visible('#machinestable tbody tr') - rows = self.find_all('#machinestable tbody tr') - machine_to_add = rows[0] - add_btn = machine_to_add.find_element(By.XPATH, '//td[@class="add-del-layers"]') + # 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.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -488,7 +481,8 @@ class TestProjectPage(TestProjectPageBase): f'You have added 1 layer to your project', str(change_notification.text) ) - hide_button = self.find('#hide-alert') + finder = lambda driver: self.find('#hide-alert') + hide_button = self.wait_until_element_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification')
@@ -533,21 +527,15 @@ class TestProjectPage(TestProjectPageBase): ) # check "Add layer" button works self.wait_until_visible('#layerstable tbody tr') - rows = self.find_all('#layerstable tbody tr') - layer_to_add = rows[0] - add_btn = layer_to_add.find_element( - By.XPATH, - '//td[@class="add-del-layers"]' - ) + 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.click() # check modal is displayed self.wait_until_visible('#dependencies-modal') list_dependencies = self.find_all('#dependencies-list li') # click on add-layers button - add_layers_btn = self.driver.find_element( - By.XPATH, - '//form[@id="dependencies-modal-form"]//button[@class="btn btn-primary"]' - ) + 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.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -555,18 +543,15 @@ class TestProjectPage(TestProjectPageBase): f'You have added {len(list_dependencies)+1} layers to your project: {input_text} and its dependencies', str(change_notification.text) ) - hide_button = self.find('#hide-alert') + finder = lambda driver: self.find('#hide-alert') + hide_button = self.wait_until_element_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification') # check "Remove layer" button works self.wait_until_visible('#layerstable tbody tr') - rows = self.find_all('#layerstable tbody tr') - layer_to_remove = rows[0] - remove_btn = layer_to_remove.find_element( - By.XPATH, - '//td[@class="add-del-layers"]' - ) + 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.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -574,7 +559,8 @@ class TestProjectPage(TestProjectPageBase): f'You have removed 1 layer from your project: {input_text}', str(change_notification.text) ) - hide_button = self.find('#hide-alert') + finder = lambda driver: self.find('#hide-alert') + hide_button = self.wait_until_element_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification')
@@ -618,12 +604,9 @@ class TestProjectPage(TestProjectPageBase): table_selector='distrostable' ) # check "Add distro" button works - rows = self.find_all('#distrostable tbody tr') - distro_to_add = rows[0] - add_btn = distro_to_add.find_element( - By.XPATH, - '//td[@class="add-del-layers"]//a[1]' - ) + 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.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification')
@@ -668,25 +651,29 @@ class TestProjectPage(TestProjectPageBase): self.assertTrue(self.find('.page-header h1').is_displayed()) # check remove layer button works - remove_layer_btn = self.find('#add-remove-layer-btn') + finder = lambda driver: self.find('#add-remove-layer-btn') + remove_layer_btn = self.wait_until_element_clickable(finder) remove_layer_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification') self.assertIn( f'You have removed 1 layer from your project', str(change_notification.text) ) - hide_button = self.find('#hide-alert') + finder = lambda driver: self.find('#hide-alert') + hide_button = self.wait_until_element_clickable(finder) hide_button.click() # check add layer button works self.wait_until_not_visible('#change-notification') - add_layer_btn = self.find('#add-remove-layer-btn') + finder = lambda driver: self.find('#add-remove-layer-btn') + add_layer_btn = self.wait_until_element_clickable(finder) add_layer_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification') self.assertIn( f'You have added 1 layer to your project', str(change_notification.text) ) - hide_button = self.find('#hide-alert') + finder = lambda driver: self.find('#hide-alert') + hide_button = self.wait_until_element_clickable(finder) hide_button.click() self.wait_until_not_visible('#change-notification') # check tabs(layers, recipes, machines) are displayed
PATCH 25/28 toaster/tests/browser/helper: Add wait for jquery to complete
In reply to Richard PurdieMost of the tests that click on buttons need the DOM to stablise, including any running JQuery code before the test can proceed. Add calls to do this whenever we're about to click on an element.
--- lib/toaster/tests/browser/selenium_helpers_base.py | 2 ++ 1 file changed, 2 insertions(+)
lib/toaster/tests/browser/selenium_helpers_base.py +2 -0
@@ -234,6 +234,7 @@ class SeleniumTestCaseBase(unittest.TestCase): def wait_until_clickable(self, selector, timeout=Wait._TIMEOUT): """ Wait until element matching CSS selector is visible on the page """ + WebDriverWait(self.driver, timeout=timeout).until(lambda driver: self.driver.execute_script("return jQuery.active == 0")) is_clickable = lambda driver: (self.find(selector).is_displayed() and self.find(selector).is_enabled()) msg = 'An element matching "%s" should be clickable' % selector Wait(self.driver, timeout=timeout).until(is_clickable, msg)
@@ -241,6 +242,7 @@ class SeleniumTestCaseBase(unittest.TestCase): def wait_until_element_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()) msg = 'A matching element never became be clickable' Wait(self.driver, timeout=timeout).until(is_clickable, msg)
PATCH 26/28 tests/toaster/functional/utils: Handle WebDriverException
In reply to Richard PurdieFix the exception handling in the cancel builds function.
This involved adding WebDriverException which sometimes occurs but also correcting the other exception handlers to continue to increment the timeout to avoid test hangs.
--- lib/toaster/tests/functional/utils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
lib/toaster/tests/functional/utils.py +7 -5
@@ -8,7 +8,7 @@ from time import sleep -from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException, TimeoutException +from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException, TimeoutException, WebDriverException from selenium.webdriver.common.by import By from orm.models import Build
@@ -66,12 +66,14 @@ def wait_until_build_cancelled(test_instance): pass if 'cancelled' in str(build_state).lower(): break - except NoSuchElementException: - continue - except StaleElementReferenceException: - continue except TimeoutException: break + except NoSuchElementException: + pass + except StaleElementReferenceException: + pass + except WebDriverException: + pass start_time += 1 sleep(1) # take a breath and try again
PATCH 27/28 toaster/tests/browser/layerdetails: Drop unwanted test skipping/exception handling
In reply to Richard PurdieWe really don't want to be skipping a test like this, drop the exception handling code as in my testing we thankfully no longer seem to be seeing it. If we do again we need to fix the underlying issue.
--- .../tests/browser/test_layerdetails_page.py | 38 +++++-------------- 1 file changed, 9 insertions(+), 29 deletions(-)
lib/toaster/tests/browser/test_layerdetails_page.py +9 -29
@@ -64,7 +64,7 @@ class TestLayerDetailsPage(SeleniumTestCase): args=(self.project.pk, self.imported_layer_version.pk)) - def _edit_layerdetails(self): + def test_edit_layerdetails_page(self): """ Edit all the editable fields for the layer refresh the page and check that the new values exist"""
@@ -107,17 +107,10 @@ class TestLayerDetailsPage(SeleniumTestCase): for save_btn in self.find_all(".change-btn"): save_btn.click() - try: - self.wait_until_visible("#save-changes-for-switch") - btn_save_chg_for_switch = self.wait_until_clickable( - "#save-changes-for-switch") - btn_save_chg_for_switch.click() - except ElementClickInterceptedException: - self.skipTest( - "save-changes-for-switch click intercepted. Element not visible or maybe covered by another element.") - except TimeoutException: - self.skipTest( - "save-changes-for-switch is not clickable within the specified timeout.") + self.wait_until_visible("#save-changes-for-switch") + btn_save_chg_for_switch = self.wait_until_clickable( + "#save-changes-for-switch") + btn_save_chg_for_switch.click() self.wait_until_visible("#edit-layer-source")
@@ -147,17 +140,10 @@ class TestLayerDetailsPage(SeleniumTestCase): new_dir = "/home/test/my-meta-dir" dir_input.send_keys(new_dir) - try: - self.wait_until_visible("#save-changes-for-switch") - btn_save_chg_for_switch = self.wait_until_clickable( - "#save-changes-for-switch") - btn_save_chg_for_switch.click() - except ElementClickInterceptedException: - self.skipTest( - "save-changes-for-switch click intercepted. Element not properly visible or maybe behind another element.") - except TimeoutException: - self.skipTest( - "save-changes-for-switch is not clickable within the specified timeout.") + self.wait_until_visible("#save-changes-for-switch") + btn_save_chg_for_switch = self.wait_until_clickable( + "#save-changes-for-switch") + btn_save_chg_for_switch.click() self.wait_until_visible("#edit-layer-source")
@@ -168,12 +154,6 @@ class TestLayerDetailsPage(SeleniumTestCase): "Expected %s in the dir value for layer directory" % new_dir) - def test_edit_layerdetails_page(self): - try: - self._edit_layerdetails() - except ElementClickInterceptedException: - self.skipTest( - "ElementClickInterceptedException occured. Element not visible or maybe covered by another element.") def test_delete_layer(self): """ Delete the layer """
PATCH 28/28 toaster/tests/selenium_helper_base: Dump a screenshot into tmp upon failure
In reply to Richard PurdieIf we fail to have an element display, dump a screenshot into /tmp since debugging these issues is painful and a screenshot can help a lot.
--- lib/toaster/tests/browser/selenium_helpers_base.py | 1 + 1 file changed, 1 insertion(+)
lib/toaster/tests/browser/selenium_helpers_base.py +1 -0
@@ -122,6 +122,7 @@ class Wait(WebDriverWait): if time.time() > end_time: break + self._driver.get_screenshot_as_file("/tmp/toaster-failing-screenshot-%s.png" % int(time.time())) raise TimeoutException(message) def until_not(self, method, message=''):