From b9266efec60deea40771e63e6f51a32a1021dd1e Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Nov 2017 23:38:44 +0200 Subject: [PATCH 1/2] Tests for making sure that keywords can be used in programatic way Tests for #1001 --- test/acceptance/extending.robot | 18 +++++++++++ test/resources/testlibs/ExtSL.py | 16 ++++++++++ .../unit/api/test_accessing_keywod_methods.py | 32 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 test/acceptance/extending.robot create mode 100644 test/resources/testlibs/ExtSL.py create mode 100644 test/unit/api/test_accessing_keywod_methods.py diff --git a/test/acceptance/extending.robot b/test/acceptance/extending.robot new file mode 100644 index 000000000..a097c351a --- /dev/null +++ b/test/acceptance/extending.robot @@ -0,0 +1,18 @@ +*** Settings *** +Suite Setup Extending Suite Setup +Suite Teardown ExtSeLib.Close All Browsers +Resource resource.robot +Library ExtSL.ExtSL WITH NAME ExtSeLib + + +*** Test Cases *** +When Extending SeleniumLibrary Keywords With Decorated Name Can Be Used For Extending + ${elements} = ExtSeLib.Ext Web Element //tr + Should Not Be Empty ${elements} + +When Extending SeleniumLibrary Keywords With Method Name Can Be Used For Extending + ExtSeLib.Ext Page Should Contain Email: + +*** Keywords *** +Extending Suite Setup + ExtSeLib.Open Browser ${ROOT}/forms/prefilled_email_form.html ${BROWSER} diff --git a/test/resources/testlibs/ExtSL.py b/test/resources/testlibs/ExtSL.py new file mode 100644 index 000000000..a7fe800a6 --- /dev/null +++ b/test/resources/testlibs/ExtSL.py @@ -0,0 +1,16 @@ +from SeleniumLibrary import SeleniumLibrary +from SeleniumLibrary.base import keyword + + +class ExtSL(SeleniumLibrary): + + def add_keywords(self): + self.add_library_components([self]) + + @keyword + def ext_web_element(self, locator): + return self.get_webelements(locator) + + @keyword + def ext_page_should_contain(self, text): + self.page_should_contain(text) diff --git a/test/unit/api/test_accessing_keywod_methods.py b/test/unit/api/test_accessing_keywod_methods.py new file mode 100644 index 000000000..c13673dd1 --- /dev/null +++ b/test/unit/api/test_accessing_keywod_methods.py @@ -0,0 +1,32 @@ +import unittest + +from SeleniumLibrary import SeleniumLibrary + + +class KeywordsMethodsTests(unittest.TestCase): + + @classmethod + def setUpClass(cls): + cls.selib = SeleniumLibrary() + + def test_kw_with_method_name(self): + self.assertTrue(self.selib.keywords['add_cookie']) + self.assertTrue(self.selib.attributes['add_cookie']) + self.assertTrue(self.selib.keywords['page_should_contain_image']) + self.assertTrue(self.selib.attributes['page_should_contain_image']) + self.assertTrue(self.selib.keywords['xpath_should_match_x_times']) + self.assertTrue(self.selib.attributes['xpath_should_match_x_times']) + + def test_kw_with_methods_name_do_not_have_kw_name(self): + with self.assertRaises(KeyError): + self.selib.keywords['Add Cookie'] + with self.assertRaises(KeyError): + self.selib.keywords['Page Should Contain Image'] + with self.assertRaises(KeyError): + self.selib.keywords['Xpath Should Match X Times'] + + def test_kw_with_decorated_name(self): + self.assertTrue(self.selib.attributes['get_webelement']) + self.assertTrue(self.selib.keywords['Get WebElement']) + self.assertTrue(self.selib.attributes['get_webelements']) + self.assertTrue(self.selib.keywords['Get WebElements']) From 6d32b0e5e2673ce5de5b4583991568728b1c4d81 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Mon, 27 Nov 2017 23:42:11 +0200 Subject: [PATCH 2/2] Removes not needed method from ExtSL.py test library --- test/resources/testlibs/ExtSL.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/resources/testlibs/ExtSL.py b/test/resources/testlibs/ExtSL.py index a7fe800a6..681bf3c59 100644 --- a/test/resources/testlibs/ExtSL.py +++ b/test/resources/testlibs/ExtSL.py @@ -4,9 +4,6 @@ class ExtSL(SeleniumLibrary): - def add_keywords(self): - self.add_library_components([self]) - @keyword def ext_web_element(self, locator): return self.get_webelements(locator)