def _parse_plugins(self, plugins): libraries = [] importer = Importer('test library') for parsed_plugin in self._string_to_modules(plugins): plugin = importer.import_class_or_module(parsed_plugin.module) if not isclass(plugin): message = "Importing test library: '%s' failed." % parsed_plugin.module raise DataError(message) plugin = plugin(self, *parsed_plugin.args, **parsed_plugin.kw_args) if not isinstance(plugin, LibraryComponent): message = 'Plugin does not inherit SeleniumLibrary.base.LibraryComponent' raise PluginError(message) self._store_plugin_keywords(plugin) libraries.append(plugin) return libraries
def __init__(self, timeout=5.0, implicit_wait=0.0, run_on_failure='Capture Page Screenshot', screenshot_root_directory=None, plugins=None): """SeleniumLibrary can be imported with several optional arguments. - ``timeout``: Default value for `timeouts` used with ``Wait ...`` keywords. - ``implicit_wait``: Default value for `implicit wait` used when locating elements. - ``run_on_failure``: Default action for the `run-on-failure functionality`. - ``screenshot_root_directory``: Location where possible screenshots are created. If not given, the directory where the log file is written is used. - ``plugins``: Allows extending the SeleniumLibrary with external Python classes. """ self.timeout = timestr_to_secs(timeout) self.implicit_wait = timestr_to_secs(implicit_wait) self.speed = 0.0 self.run_on_failure_keyword \ = RunOnFailureKeywords.resolve_keyword(run_on_failure) self._running_on_failure_keyword = False self.screenshot_root_directory = screenshot_root_directory self._element_finder = ElementFinder(self) self._plugin_keywords = [] libraries = [ AlertKeywords(self), BrowserManagementKeywords(self), CookieKeywords(self), ElementKeywords(self), FormElementKeywords(self), FrameKeywords(self), JavaScriptKeywords(self), RunOnFailureKeywords(self), ScreenshotKeywords(self), SelectElementKeywords(self), TableElementKeywords(self), WaitingKeywords(self), WindowKeywords(self) ] if is_truthy(plugins): parsed_plugins = self._string_to_modules(plugins) for index, plugin in enumerate( self._import_modules(parsed_plugins)): if not isclass(plugin): message = "Importing test library: '%s' failed." % parsed_plugins[ index].plugin raise DataError(message) plugin = plugin(self, *parsed_plugins[index].args, **parsed_plugins[index].kw_args) if not isinstance(plugin, LibraryComponent): message = 'Plugin does not inherit SeleniumLibrary.base.LibraryComponent' raise PluginError(message) self._store_plugin_keywords(plugin) libraries.append(plugin) self._drivers = WebDriverCache() DynamicCore.__init__(self, libraries) self.ROBOT_LIBRARY_LISTENER = LibraryListener()