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. 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')