From 6b9139ab72e6f1d2d6f3f6153bb087720052ee92 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 20 Aug 2019 22:37:13 +0300 Subject: [PATCH 1/2] Easier event firing webdriver from plugins. Fixes #1425 --- src/SeleniumLibrary/base/context.py | 8 ++++++++ utest/test/api/plugin_with_event_firing_webdriver.py | 12 ++++++++++++ utest/test/api/test_plugins.py | 6 ++++++ 3 files changed, 26 insertions(+) create mode 100644 utest/test/api/plugin_with_event_firing_webdriver.py diff --git a/src/SeleniumLibrary/base/context.py b/src/SeleniumLibrary/base/context.py index d215441d8..47f9ab6db 100644 --- a/src/SeleniumLibrary/base/context.py +++ b/src/SeleniumLibrary/base/context.py @@ -43,6 +43,14 @@ def element_finder(self): def element_finder(self, value): self.ctx._element_finder = value + @property + def event_firing_webdriver(self): + return self.ctx.event_firing_webdriver + + @event_firing_webdriver.setter + def event_firing_webdriver(self, event_firing_webdriver): + self.ctx.event_firing_webdriver = event_firing_webdriver + def find_element(self, locator, tag=None, required=True, parent=None): """Find element matching `locator`. diff --git a/utest/test/api/plugin_with_event_firing_webdriver.py b/utest/test/api/plugin_with_event_firing_webdriver.py new file mode 100644 index 000000000..8dbf13c7b --- /dev/null +++ b/utest/test/api/plugin_with_event_firing_webdriver.py @@ -0,0 +1,12 @@ +from SeleniumLibrary.base import LibraryComponent, keyword + + +class plugin_with_event_firing_webdriver(LibraryComponent): + + def __init__(self, ctx): + LibraryComponent.__init__(self, ctx) + self.event_firing_webdriver = 'event_firing_webdriver' + + @keyword + def tidii(self): + self.info('foo') diff --git a/utest/test/api/test_plugins.py b/utest/test/api/test_plugins.py index d84a8d16f..b9aa4cb43 100644 --- a/utest/test/api/test_plugins.py +++ b/utest/test/api/test_plugins.py @@ -109,3 +109,9 @@ def test_plugin_as_last_in_init(self): event_firing_wd = os.path.join(self.root_dir, 'MyListener.py') sl = SeleniumLibrary(plugins=plugin_file, event_firing_webdriver=event_firing_wd) self.assertEqual(sl.event_firing_webdriver, 'should be last') + + def test_easier_event_firing_webdriver_from_plugin(self): + plugin_file = os.path.join(self.root_dir, 'plugin_with_event_firing_webdriver.py') + sl = SeleniumLibrary(plugins=plugin_file) + self.assertEqual(sl._plugin_keywords, ['tidii']) + self.assertEqual(sl.event_firing_webdriver, 'event_firing_webdriver') From 5353ba1857b351af36f17c25fa0a92a8734c6fa8 Mon Sep 17 00:00:00 2001 From: Tatu Aalto Date: Tue, 20 Aug 2019 22:45:02 +0300 Subject: [PATCH 2/2] Added documentation --- docs/extending/extending.rst | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/docs/extending/extending.rst b/docs/extending/extending.rst index d143e8840..9b5212299 100644 --- a/docs/extending/extending.rst +++ b/docs/extending/extending.rst @@ -217,15 +217,16 @@ log Wrapper to ``robot.api.logger.write`` method. Also following attributes are available from the ``LibraryComponent`` class: -============== ===================================================================== - Attribute Description -============== ===================================================================== -driver Currently active browser/WebDriver instance in the SeleniumLibrary. -drivers `Cache`_ for the opened browsers/WebDriver instances. -element_finder Read/write attribute for the `ElementFinder`_ instance. -ctx Instance of the SeleniumLibrary. -log_dir Folder where output files are written. -============== ===================================================================== +====================== ============================================================================== + Attribute Description +====================== ============================================================================== +driver Currently active browser/WebDriver instance in the SeleniumLibrary. +drivers `Cache`_ for the opened browsers/WebDriver instances. +element_finder Read/write attribute for the `ElementFinder`_ instance. +ctx Instance of the SeleniumLibrary. +log_dir Folder where output files are written. +event_firing_webdriver Read/write attribute for the SeleniumLibrary `EventFiringWebDriver`_ instance. +====================== ============================================================================== See the `SeleniumLibrary init`_, the `LibraryComponent`_ and the `ContextAware`_ classes for further implementation details.