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=otfic745nzvDdeB7swEudwACRDcLpdVvj6h/qxdbCXqza1GpoxMyDtADT+hY7z7AZx gxwQHa2PljaRaucKBllDuBgnDJfDgZqmdoydb3O7S7J7soGgRahFgHGPQlL6Uz1NKNYQ 1RpYRrcfTbelR+p7Jl+IE781NhWFF6R8eB/lBxbO64OUf+zEMDI9HCC3AxbsmKHQtRhw rkLoQtO2oUmhseDUbM0PYoiQzy+u9wiBfiPVlnGW60WcmGZdFTwPDoYUw8H9QVsGD4Nv ipEU17nc1KL0b3VovBPXYa6AwSCf6fQ5IO+RBxxJfS+vgSfU1NClNiOQJwuX/z9XoV5Y BJAg== From: Guilherme Campos Camargo Date: Wed, 7 Mar 2018 16:54:57 -0300 Message-Id: <20180307195459.16757-10-guicc@profusion.mobi> In-Reply-To: <20180307195459.16757-1-guicc@profusion.mobi> References: <20180307195459.16757-1-guicc@profusion.mobi> Subject: [Fuego] [PATCH 09/11] 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