Skip to contentSkip to conversation

toaster/tests/functional: Fix later details page test issues

PATCH New Richard Purdie 1 participant 3 messages Oct 9, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 toaster/tests/functional: Fix later details page test issues

Consistently use meta-poky as the test target, instead of a magic number ID which can vary.

Fix incorrect comments.

Also ensure the viewport is scrolled to the top when changing tabs. This breaks if other layers are selected like openembedded-core due to the number of recipes.

---
 .../tests/functional/test_project_page.py     | 21 ++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
lib/toaster/tests/functional/test_project_page.py +14 -7
index deb26812ea..6b6d45eaba 100644
@@ -699,7 +699,7 @@ class TestProjectPage(SeleniumFunctionalTestCase):
         )
 
     def test_single_layer_page(self):
-        """ Test layer page
+        """ Test layer details page using meta-poky as an example (assumes is added to start with)
             - Check if title is displayed
             - Check add/remove layer button works
             - Check tabs(layers, recipes, machines) are displayed
@@ -708,13 +708,14 @@ class TestProjectPage(SeleniumFunctionalTestCase):
                 - Check layer summary
                 - Check layer description
         """
-        url = reverse("layerdetails", args=(TestProjectPage.project_id, 7))
-        self.get(url)
+        self._navigate_to_config_nav('layerstable', 6)
+        layer_link = self.driver.find_element(By.XPATH, '//tr/td[@class="layer__name"]/a[contains(text(),"meta-poky")]')
+        layer_link.click()
         self.wait_until_visible('.page-header')
         # check title is displayed
         self.assertTrue(self.find('.page-header h1').is_displayed())
 
-        # check add layer button works
+        # 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)
@@ -722,7 +723,7 @@ class TestProjectPage(SeleniumFunctionalTestCase):
         self.assertIn(
             f'You have removed 1 layer from your project', str(change_notification.text)
         )
-        # check add layer button works, 18 is the random layer id
+        # check add layer button works
         add_layer_btn = self.find('#add-remove-layer-btn')
         add_layer_btn.click()
         self.wait_until_visible('#change-notification')
@@ -738,12 +739,18 @@ class TestProjectPage(SeleniumFunctionalTestCase):
         self.assertTrue(
             'active' in str(self.find('#information').get_attribute('class'))
         )
-        # Check second tab
+        # Check second tab (recipes)
+        # Ensure page is scrolled to the top
+        self.driver.find_element(By.XPATH, '//body').send_keys(Keys.CONTROL + Keys.HOME)
+        self.wait_until_visible('.nav-tabs')
         tabs[1].click()
         self.assertTrue(
             'active' in str(self.find('#recipes').get_attribute('class'))
         )
-        # Check third tab
+        # Check third tab (machines)
+        # Ensure page is scrolled to the top
+        self.driver.find_element(By.XPATH, '//body').send_keys(Keys.CONTROL + Keys.HOME)
+        self.wait_until_visible('.nav-tabs')
         tabs[2].click()
         self.assertTrue(
             'active' in str(self.find('#machines').get_attribute('class'))
#1 lore raw

PATCH 2/3 toaster/tests/functional: Fix hardcoded database ID

Using a hardcoded database ID for a recipe is a bad idea and causes tests to fail when we change data/versions.

Remove magic numbers.

---
 lib/toaster/tests/functional/test_project_page.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
lib/toaster/tests/functional/test_project_page.py +6 -1
index 6b6d45eaba..8b34658418 100644
@@ -774,7 +774,12 @@ class TestProjectPage(SeleniumFunctionalTestCase):
                 - Check recipe: name, summary, description, Version, Section,
                 License, Approx. packages included, Approx. size, Recipe file
         """
-        url = reverse("recipedetails", args=(TestProjectPage.project_id, 53428))
+        # 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)
+        recipe_id = prj.get_all_compatible_recipes().get(name="xen-image-minimal").pk
+        url = reverse("recipedetails", args=(TestProjectPage.project_id, recipe_id))
         self.get(url)
         self.wait_until_visible('.page-header')
         # check title is displayed
#2 lore raw

PATCH 3/3 toaster/tests/functional: Fix test race on alert

In reply to Richard Purdie

THe test fails on faster systems as we need to wait. Fix that and a typo.

---
 lib/toaster/tests/functional/test_create_new_project.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
lib/toaster/tests/functional/test_create_new_project.py +3 -1
index c3b5679514..f7d17847ae 100644
@@ -172,8 +172,10 @@ class TestCreateNewProject(SeleniumFunctionalTestCase):
                                  "import-project-dir").send_keys(wrong_path)
         self.driver.find_element(By.ID, "create-project-button").click()
 
+        self.wait_until_visible('.alert-danger')
+
         # check error message
         self.assertTrue(self.element_exists('.alert-danger'),
-                        'Allert message not shown')
+                        'Alert message not shown')
         self.assertTrue(wrong_path in self.find('.alert-danger').text,
                         "Wrong path not in alert message")