From patchwork Wed Nov 29 22:53:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alassane Yattara X-Patchwork-Id: 35383 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E876C46CA0 for ; Wed, 29 Nov 2023 22:54:08 +0000 (UTC) Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by mx.groups.io with SMTP id smtpd.web11.57327.1701298439369636924 for ; Wed, 29 Nov 2023 14:53:59 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@savoirfairelinux.com header.s=DFC430D2-D198-11EC-948E-34200CB392D2 header.b=iHlmARx9; spf=pass (domain: savoirfairelinux.com, ip: 208.88.110.44, mailfrom: alassane.yattara@savoirfairelinux.com) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id BB5E29C3533 for ; Wed, 29 Nov 2023 17:53:58 -0500 (EST) Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavis, port 10032) with ESMTP id LeVdj5AYnJAf; Wed, 29 Nov 2023 17:53:58 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id E38E19C3372; Wed, 29 Nov 2023 17:53:57 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.savoirfairelinux.com E38E19C3372 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=savoirfairelinux.com; s=DFC430D2-D198-11EC-948E-34200CB392D2; t=1701298437; bh=zT4lYxeiyQEUxoz7l3mIDhzcMMpqS0no0csLVWkMKzo=; h=From:To:Date:Message-Id:MIME-Version; b=iHlmARx9mrswZtRznBCDZTLL+tC2xWuQH7XlTwpVojFyt0hl75DP/G+o5SBU8bf8x bIemQhF8p8urFLroVeMiavl+Bib+cgyHwC28riAfWQanxvPB8PFku8dS0XSjXwfajF /R4pbvPQYwD241dQ84JyVOeBJH9AHEgGzZcWguPwd1lcpHqogEkCF8p5Z3TgUorYX7 NpMv9x2MEMqFjqbu4JKe0/V8+XlcoQHMIw5JwEXHEjf8jC0DqtbC5oETSlH32xWhhw OCIVBuUqseu+ARHxOTcKdiIutAnDnvHLQf/kbD0EcfOmYd2qdlOcnoaelSbWHHfVh+ lJTJrI3M8b3Gg== X-Virus-Scanned: amavis at mail.savoirfairelinux.com Received: from mail.savoirfairelinux.com ([127.0.0.1]) by localhost (mail.savoirfairelinux.com [127.0.0.1]) (amavis, port 10026) with ESMTP id kBtK1fThS9Ki; Wed, 29 Nov 2023 17:53:57 -0500 (EST) Received: from jedi.. (unknown [196.127.183.75]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 511579C2797; Wed, 29 Nov 2023 17:53:57 -0500 (EST) From: Alassane Yattara To: toaster@lists.yoctoproject.org Cc: Alassane Yattara Subject: [PATCH 7/9] toaster/test: Bug-fix on tests/functional/test_project_page Date: Wed, 29 Nov 2023 23:53:38 +0100 Message-Id: <20231129225340.477401-7-alassane.yattara@savoirfairelinux.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231129225340.477401-1-alassane.yattara@savoirfairelinux.com> References: <20231129225340.477401-1-alassane.yattara@savoirfairelinux.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from li982-79.members.linode.com [45.33.32.79] by aws-us-west-2-korg-lkml-1.web.codeaurora.org with HTTPS for ; Wed, 29 Nov 2023 22:54:08 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/toaster/message/6031 - Generate a random name for create project while test - Set timeout on method _wait_until_build - update test_machines_page, test_softwareRecipe_page and test_single_layer_page to fix exception "element not interactable" Signed-off-by: Alassane Yattara --- .../tests/functional/test_project_page.py | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/lib/toaster/tests/functional/test_project_page.py b/lib/toaster/tests/functional/test_project_page.py index dd33e802..70829509 100644 --- a/lib/toaster/tests/functional/test_project_page.py +++ b/lib/toaster/tests/functional/test_project_page.py @@ -6,12 +6,15 @@ # SPDX-License-Identifier: GPL-2.0-only # +import random +import string import pytest from time import sleep from django.urls import reverse from django.utils import timezone +from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.select import Select -from selenium.common.exceptions import NoSuchElementException +from selenium.common.exceptions import NoSuchElementException, TimeoutException from tests.functional.functional_helpers import SeleniumFunctionalTestCase from orm.models import Build, Project, Target from selenium.webdriver.common.by import By @@ -23,13 +26,18 @@ class TestProjectPage(SeleniumFunctionalTestCase): def setUp(self): super().setUp() release = '3' - project_name = 'projectmaster' + project_name = 'project_' + self.generate_random_string() self._create_test_new_project( project_name, release, False, ) + def generate_random_string(self, length=10): + characters = string.ascii_letters + string.digits # alphabetic and numerical characters + random_string = ''.join(random.choice(characters) for _ in range(length)) + return random_string + def _create_test_new_project( self, project_name, @@ -204,7 +212,13 @@ class TestProjectPage(SeleniumFunctionalTestCase): test_show_rows(row_to_show, show_row_link) def _wait_until_build(self, state): + timeout = 10 + start_time = 0 while True: + if start_time > timeout: + raise TimeoutException( + f'Build did not reach {state} state within {timeout} seconds' + ) try: last_build_state = self.driver.find_element( By.XPATH, @@ -217,7 +231,8 @@ class TestProjectPage(SeleniumFunctionalTestCase): break except NoSuchElementException: continue - sleep(1) + start_time += 1 + sleep(1) # take a breath and try again def _mixin_test_table_search_input(self, **kwargs): input_selector, input_text, searchBtn_selector, table_selector, *_ = kwargs.values() @@ -380,11 +395,9 @@ class TestProjectPage(SeleniumFunctionalTestCase): self.wait_until_visible('#topbar-configuration-tab') config_tab = self.find('#topbar-configuration-tab') self.assertTrue(config_tab.get_attribute('class') == 'active') - self.assertTrue('Configuration' in config_tab.text) - config_tab_link = config_tab.find_element(By.TAG_NAME, 'a') + self.assertTrue('Configuration' in str(config_tab.text)) self.assertTrue( - f"/toastergui/project/1" in str(config_tab_link.get_attribute( - 'href')) + f"/toastergui/project/1" in str(self.driver.current_url) ) def get_tabs(): @@ -464,10 +477,10 @@ class TestProjectPage(SeleniumFunctionalTestCase): image_to_build = rows[0] build_btn = image_to_build.find_element( By.XPATH, - '//td[@class="add-del-layers"]' + '//td[@class="add-del-layers"]//a[1]' ) build_btn.click() - self._wait_until_build('parsing starting cloning') + self._wait_until_build('parsing starting cloning queued') lastest_builds = self.driver.find_elements( By.XPATH, '//div[@id="latest-builds"]/div' @@ -517,9 +530,9 @@ class TestProjectPage(SeleniumFunctionalTestCase): machine_to_select = rows[0] select_btn = machine_to_select.find_element( By.XPATH, - '//td[@class="add-del-layers"]' + '//td[@class="add-del-layers"]//a[1]' ) - select_btn.click() + select_btn.send_keys(Keys.RETURN) self.wait_until_visible('#config-nav') project_machine_name = self.find('#project-machine-name') self.assertTrue( @@ -530,32 +543,19 @@ class TestProjectPage(SeleniumFunctionalTestCase): # Search for a machine whit layer not in project self._mixin_test_table_search_input( input_selector='search-input-machinestable', - input_text='qemux86-64-screen', + input_text='qemux86-64-tpm2', searchBtn_selector='search-submit-machinestable', table_selector='machinestable' ) 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"]' - ) + add_btn = machine_to_add.find_element(By.XPATH, '//td[@class="add-del-layers"]') 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"]' - ) - add_layers_btn.click() self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification') self.assertTrue( - f'You have added {len(list_dependencies)+1} layers to your project: meta-tanowrt and its dependencies' in change_notification.text + f'You have added 1 layer to your project' in str(change_notification.text) ) - # check Machine table feature(show/hide column, pagination) self._navigate_to_config_nav('machinestable', 5) column_list = [ @@ -601,7 +601,7 @@ class TestProjectPage(SeleniumFunctionalTestCase): ) add_btn.click() # check modal is displayed - self.wait_until_visible('#dependencies-modal') + self.wait_until_visible('#dependencies-modal', poll=2) list_dependencies = self.find_all('#dependencies-list li') # click on add-layers button add_layers_btn = self.driver.find_element( @@ -612,7 +612,7 @@ class TestProjectPage(SeleniumFunctionalTestCase): self.wait_until_visible('#change-notification') change_notification = self.find('#change-notification') self.assertTrue( - f'You have added {len(list_dependencies)+1} layers to your project: {input_text} and its dependencies' in change_notification.text + f'You have added {len(list_dependencies)+1} layers to your project: {input_text} and its dependencies' in str(change_notification.text) ) # check "Remove layer" button works rows = self.find_all('#layerstable tbody tr') @@ -625,7 +625,7 @@ class TestProjectPage(SeleniumFunctionalTestCase): self.wait_until_visible('#change-notification', poll=2) change_notification = self.find('#change-notification') self.assertTrue( - f'You have removed 1 layer from your project: {input_text}' in change_notification.text + f'You have removed 1 layer from your project: {input_text}' in str(change_notification.text) ) # check layers table feature(show/hide column, pagination) self._navigate_to_config_nav('layerstable', 6) @@ -668,13 +668,13 @@ class TestProjectPage(SeleniumFunctionalTestCase): distro_to_add = rows[0] add_btn = distro_to_add.find_element( By.XPATH, - '//td[@class="add-del-layers"]' + '//td[@class="add-del-layers"]//a[1]' ) add_btn.click() self.wait_until_visible('#change-notification', poll=2) change_notification = self.find('#change-notification') self.assertTrue( - f'You have changed the distro to: {input_text}' in change_notification.text + f'You have changed the distro to: {input_text}' in str(change_notification.text) ) # check distro table feature(show/hide column, pagination) self._navigate_to_config_nav('distrostable', 7)