[Fuego] [PATCH 09/11] Add ClickLink selenium command
Guilherme Campos Camargo
guicc at profusion.mobi
Wed Mar 7 19:54:57 UTC 2018
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 <guicc at profusion.mobi>
---
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
More information about the Fuego
mailing list