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..681bf3c59 --- /dev/null +++ b/test/resources/testlibs/ExtSL.py @@ -0,0 +1,13 @@ +from SeleniumLibrary import SeleniumLibrary +from SeleniumLibrary.base import keyword + + +class ExtSL(SeleniumLibrary): + + @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'])