Return-Path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profusion-mobi.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=vG4gWzlOZBgi8qzDL5WKlFAudGEnXD/B7/Hbw1O6Tjc=; b=mjLymf98bQgjzK+DPAnMt/1aAoqQbOxQK5Vm29tTQ+Ql0yExsbOX7Ca5rp3RWyYmUg 6dh07OnwyBeLGFD5X22trkW7ZjWl8dUEmhFLn7lDbo7HM+KKdMNKx3oAeoF72der5fqe APfS9mVrQP/dydURK8k7357pd2GgoZ6Hks9HeMQL3uRagPNgGshu+kfJu8ecEWD86iZ/ kQrcpKSe1CKsqZyG3LzDkGwHb4CyJQyTgCDhRBAp5+SQl1c38X2Z+x6IyTznW9wWWkJ8 QbSskd6V0MfdyXdTIoAsk+G1E/RLdTR5Hih8+vzSJDL2cyI0+/3K1FJ+G5eh0++QXM5Z KE/g== From: Guilherme Campos Camargo Date: Wed, 28 Mar 2018 21:08:24 -0300 Message-Id: <20180329000832.12268-9-guicc@profusion.mobi> In-Reply-To: <20180329000832.12268-1-guicc@profusion.mobi> References: <20180329000832.12268-1-guicc@profusion.mobi> Subject: [Fuego] [PATCH 08/16] Add ClickLink selenium command List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org Clicks in the link that has the text passed in the argument `linktext`. Returns False if no link containing `linktext` is found. Signed-off-by: Guilherme Campos Camargo --- engine/tests/Functional.fuegotest/test_run.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/engine/tests/Functional.fuegotest/test_run.py b/engine/tests/Functional.fuegotest/test_run.py index 851074f..e03853b 100755 --- a/engine/tests/Functional.fuegotest/test_run.py +++ b/engine/tests/Functional.fuegotest/test_run.py @@ -13,6 +13,7 @@ import docker import pexpect import requests from selenium import webdriver +import selenium.common.exceptions as selenium_exceptions LOGGER = logging.getLogger('test_run') STREAM_HANDLER = logging.StreamHandler() @@ -97,6 +98,29 @@ class CheckText(SeleniumCommand): return result == self.expected_result +class ClickLink(SeleniumCommand): + def __init__(self, linktext, expected_result=True): + self.linktext = linktext + self.expected_result = expected_result + + def exec(self, selenium_ctx): + super().exec(selenium_ctx) + + LOGGER.debug( + ' Searching for a link with the text \'%s\'', self.linktext) + + try: + link = self.driver.find_element_by_partial_link_text(self.linktext) + link.click() + LOGGER.debug(' Link found and clicked') + result = True + except selenium_exceptions.NoSuchElementException: + LOGGER.error(' Link not found') + result = False + + return result == self.expected_result + + class Back(SeleniumCommand): def exec(self, selenium_ctx): super().exec(selenium_ctx) -- 2.16.2