Skip to content

Commit 165fe69

Browse files
authored
Easier event firing webdriver from plugin (robotframework#1431)
* Easier event firing webdriver from plugins. Fixes robotframework#1425
1 parent 405786b commit 165fe69

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

docs/extending/extending.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,16 @@ log Wrapper to ``robot.api.logger.write`` method.
217217

218218
Also following attributes are available from the ``LibraryComponent`` class:
219219

220-
============== =====================================================================
221-
Attribute Description
222-
============== =====================================================================
223-
driver Currently active browser/WebDriver instance in the SeleniumLibrary.
224-
drivers `Cache`_ for the opened browsers/WebDriver instances.
225-
element_finder Read/write attribute for the `ElementFinder`_ instance.
226-
ctx Instance of the SeleniumLibrary.
227-
log_dir Folder where output files are written.
228-
============== =====================================================================
220+
====================== ==============================================================================
221+
Attribute Description
222+
====================== ==============================================================================
223+
driver Currently active browser/WebDriver instance in the SeleniumLibrary.
224+
drivers `Cache`_ for the opened browsers/WebDriver instances.
225+
element_finder Read/write attribute for the `ElementFinder`_ instance.
226+
ctx Instance of the SeleniumLibrary.
227+
log_dir Folder where output files are written.
228+
event_firing_webdriver Read/write attribute for the SeleniumLibrary `EventFiringWebDriver`_ instance.
229+
====================== ==============================================================================
229230

230231
See the `SeleniumLibrary init`_, the `LibraryComponent`_ and the `ContextAware`_ classes for further
231232
implementation details.

src/SeleniumLibrary/base/context.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ def element_finder(self):
4343
def element_finder(self, value):
4444
self.ctx._element_finder = value
4545

46+
@property
47+
def event_firing_webdriver(self):
48+
return self.ctx.event_firing_webdriver
49+
50+
@event_firing_webdriver.setter
51+
def event_firing_webdriver(self, event_firing_webdriver):
52+
self.ctx.event_firing_webdriver = event_firing_webdriver
53+
4654
def find_element(self, locator, tag=None, required=True, parent=None):
4755
"""Find element matching `locator`.
4856
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from SeleniumLibrary.base import LibraryComponent, keyword
2+
3+
4+
class plugin_with_event_firing_webdriver(LibraryComponent):
5+
6+
def __init__(self, ctx):
7+
LibraryComponent.__init__(self, ctx)
8+
self.event_firing_webdriver = 'event_firing_webdriver'
9+
10+
@keyword
11+
def tidii(self):
12+
self.info('foo')

utest/test/api/test_plugins.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ def test_plugin_as_last_in_init(self):
109109
event_firing_wd = os.path.join(self.root_dir, 'MyListener.py')
110110
sl = SeleniumLibrary(plugins=plugin_file, event_firing_webdriver=event_firing_wd)
111111
self.assertEqual(sl.event_firing_webdriver, 'should be last')
112+
113+
def test_easier_event_firing_webdriver_from_plugin(self):
114+
plugin_file = os.path.join(self.root_dir, 'plugin_with_event_firing_webdriver.py')
115+
sl = SeleniumLibrary(plugins=plugin_file)
116+
self.assertEqual(sl._plugin_keywords, ['tidii'])
117+
self.assertEqual(sl.event_firing_webdriver, 'event_firing_webdriver')

0 commit comments

Comments
 (0)