From patchwork Fri Dec 8 01:53:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alassane Yattara X-Patchwork-Id: 35891 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 5F8D8C46CC5 for ; Fri, 8 Dec 2023 01:53:59 +0000 (UTC) Received: from mail.savoirfairelinux.com (mail.savoirfairelinux.com [208.88.110.44]) by mx.groups.io with SMTP id smtpd.web11.10347.1702000436547970455 for ; Thu, 07 Dec 2023 17:53:56 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@savoirfairelinux.com header.s=DFC430D2-D198-11EC-948E-34200CB392D2 header.b=U1X6Cg5u; 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 E51A99C33BA for ; Thu, 7 Dec 2023 20:53:55 -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 5I6Yapsmd0O3; Thu, 7 Dec 2023 20:53:55 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.savoirfairelinux.com (Postfix) with ESMTP id 72CDD9C3472; Thu, 7 Dec 2023 20:53:55 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.savoirfairelinux.com 72CDD9C3472 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=savoirfairelinux.com; s=DFC430D2-D198-11EC-948E-34200CB392D2; t=1702000435; bh=pp6zLWIo90Ps7WkBEqk9c38PxAJKi0ezvosNJG3A7dM=; h=From:To:Date:Message-Id:MIME-Version; b=U1X6Cg5u39wYllRssGZihZB8bnMpiINwRa9Bfr4H1s+uV5wX8atCWyZxrU0QYWM45 FGjhduw+XAM8XetQVBVPj/xM6DOpr3H7lQRbS2CSTWrICjUwtWAmowUUEyod9/yfrt MQpHwKl0DSyCEfEZSVue7M80PJ4B7vrbjoyHNZkgoXSXF0p7Q4qtIf+AKPpGgVdIQ5 nL+eY7UsIOzJTOE50EonXH7K2T2AuWfp02j4tGq28Z8FwO01QyCPeHK1i7gMd8iu03 avMwHrDtVrNdIaQ1utTecxb/95WVH5MARWGMkujguLxTQ9f7OWJSuapQB73dxztiWM xI89/kQB+Nsrw== 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 LbFdLBE7ZCJZ; Thu, 7 Dec 2023 20:53:55 -0500 (EST) Received: from jedi.. (unknown [196.127.183.75]) by mail.savoirfairelinux.com (Postfix) with ESMTPSA id 930359C33E2; Thu, 7 Dec 2023 20:53:54 -0500 (EST) From: Alassane Yattara To: toaster@lists.yoctoproject.org Cc: Alassane Yattara Subject: [PATCH 2/4] toaster/test: Added functional/utils, contains useful methods using by functional tests Date: Fri, 8 Dec 2023 02:53:47 +0100 Message-Id: <20231208015349.678997-2-alassane.yattara@savoirfairelinux.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231208015349.678997-1-alassane.yattara@savoirfairelinux.com> References: <20231208015349.678997-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 ; Fri, 08 Dec 2023 01:53:59 -0000 X-Groupsio-URL: https://lists.yoctoproject.org/g/toaster/message/6068 Signed-off-by: Alassane Yattara --- lib/toaster/tests/functional/utils.py | 89 +++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 lib/toaster/tests/functional/utils.py diff --git a/lib/toaster/tests/functional/utils.py b/lib/toaster/tests/functional/utils.py new file mode 100644 index 00000000..bde1146e --- /dev/null +++ b/lib/toaster/tests/functional/utils.py @@ -0,0 +1,89 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# BitBake Toaster UI tests implementation +# +# Copyright (C) 2023 Savoir-faire Linux Inc +# +# SPDX-License-Identifier: GPL-2.0-only + + +from time import sleep +from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException, TimeoutException +from selenium.webdriver.common.by import By + +from orm.models import Build + + +def wait_until_build(test_instance, state): + timeout = 60 + start_time = 0 + build_state = '' + while True: + try: + if start_time > timeout: + raise TimeoutException( + f'Build did not reach {state} state within {timeout} seconds' + ) + last_build_state = test_instance.driver.find_element( + By.XPATH, + '//*[@id="latest-builds"]/div[1]//div[@class="build-state"]', + ) + build_state = last_build_state.get_attribute( + 'data-build-state') + state_text = state.lower().split() + if any(x in str(build_state).lower() for x in state_text): + return str(build_state).lower() + if 'failed' in str(build_state).lower(): + break + except NoSuchElementException: + continue + except TimeoutException: + break + start_time += 1 + sleep(1) # take a breath and try again + +def wait_until_build_cancelled(test_instance): + """ Cancel build take a while sometime, the method is to wait driver action + until build being cancelled + """ + timeout = 30 + start_time = 0 + build = None + while True: + try: + if start_time > timeout: + raise TimeoutException( + f'Build did not reach cancelled state within {timeout} seconds' + ) + last_build_state = test_instance.driver.find_element( + By.XPATH, + '//*[@id="latest-builds"]/div[1]//div[@class="build-state"]', + ) + build_state = last_build_state.get_attribute( + 'data-build-state') + 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() + if 'cancelled' in str(build_state).lower(): + break + except NoSuchElementException: + continue + except StaleElementReferenceException: + continue + except TimeoutException: + break + start_time += 1 + sleep(1) # take a breath and try again + +def get_projectId_from_url(url): + # url = 'http://domainename.com/toastergui/project/1656/whatever + # or url = 'http://domainename.com/toastergui/project/1/ + # or url = 'http://domainename.com/toastergui/project/186 + assert '/toastergui/project/' in url, "URL is not valid" + url_to_list = url.split('/toastergui/project/') + return int(url_to_list[1].split('/')[0]) # project_id