Skip to content

Commit c085848

Browse files
authored
Fixed initialisation order (robotframework#1428)
Fixes robotframework#1424
1 parent 3d049d5 commit c085848

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

docs/extending/extending.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ of the attributes are explained in the library `keyword documentation`_. please
8989
plugins may alter the functionality of the method or attributes and documentation applies
9090
only for the core SeleniumLibrary.
9191

92+
Initialisation order
93+
====================
94+
When instance is created from the SeleniumLibrary, example when library is imported in the
95+
test data, there is an order in the initialisation. At first all classes defining SeleniumLibrary
96+
keywords are discovered. As a second event, discovery for the EventFiringWebDriver is done.
97+
At third event, plugins are discovered. As a last event, keywords are found from SeleniumLibrary
98+
classes and plugins. Because plugins are discovered last, they may example alter the
99+
EventFiringWebDriver. Consult the plugin's documentation for more details.
100+
92101
Plugins
93102
=======
94103
SeleniumLibrary offers plugins as a way to modify, add library keywords and modify some of the internal

src/SeleniumLibrary/__init__.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,17 +460,16 @@ def __init__(self, timeout=5.0, implicit_wait=0.0,
460460
WaitingKeywords(self),
461461
WindowKeywords(self)
462462
]
463+
self.ROBOT_LIBRARY_LISTENER = LibraryListener()
464+
self._running_keyword = None
465+
self.event_firing_webdriver = None
466+
if is_truthy(event_firing_webdriver):
467+
self.event_firing_webdriver = self._parse_listener(event_firing_webdriver)
463468
if is_truthy(plugins):
464469
plugin_libs = self._parse_plugins(plugins)
465470
libraries = libraries + plugin_libs
466471
self._drivers = WebDriverCache()
467472
DynamicCore.__init__(self, libraries)
468-
self.ROBOT_LIBRARY_LISTENER = LibraryListener()
469-
if is_truthy(event_firing_webdriver):
470-
self.event_firing_webdriver = self._parse_listener(event_firing_webdriver)
471-
else:
472-
self.event_firing_webdriver = None
473-
self._running_keyword = None
474473

475474
def run_keyword(self, name, args, kwargs):
476475
self._running_keyword = name

utest/test/api/plugin_tester.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from SeleniumLibrary.base import LibraryComponent, keyword
2+
3+
4+
class plugin_tester(LibraryComponent):
5+
6+
def __init__(self, ctx):
7+
LibraryComponent.__init__(self, ctx)
8+
ctx.event_firing_webdriver = 'should be last'
9+
10+
@keyword
11+
def foo(self):
12+
self.info('foo')
13+
14+
@keyword
15+
def bar(self, arg):
16+
self.info(arg)

utest/test/api/test_plugins.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,9 @@ def test_no_library_component_inherit(self):
103103
no_inherit = os.path.join(self.root_dir, 'my_lib_not_inherit.py')
104104
with self.assertRaises(PluginError):
105105
SeleniumLibrary(plugins=no_inherit)
106+
107+
def test_plugin_as_last_in_init(self):
108+
plugin_file = os.path.join(self.root_dir, 'plugin_tester.py')
109+
event_firing_wd = os.path.join(self.root_dir, 'MyListener.py')
110+
sl = SeleniumLibrary(plugins=plugin_file, event_firing_webdriver=event_firing_wd)
111+
self.assertEqual(sl.event_firing_webdriver, 'should be last')

0 commit comments

Comments
 (0)