def __init__(self, *args, **kwargs) -> None: locators_path = kwargs.pop("locators_path", locators.default_locators_path()) # Parse user-given plugins plugins = kwargs.get("plugins", "") plugins = set(p for p in plugins.split(",") if p) # Add testability if requested if "use_testability" in args: args = [arg for arg in args if arg != "use_testability"] plugins.add("SeleniumTestability") # Refresh plugins list kwargs["plugins"] = ",".join(plugins) SeleniumLibrary.__init__(self, *args, **kwargs) self.logger = logging.getLogger(__name__) self.using_testability = bool("SeleniumTestability" in plugins) # Add support for locator aliases self.locators = locators.LocatorsDatabase(locators_path) self._element_finder.register("alias", self._find_by_alias, persist=True) self._embedding_screenshots = False self._previous_screenshot_directory = None # Embed screenshots in logs by default if not notebook.IPYTHON_AVAILABLE: self._embedding_screenshots = True self._previous_screenshot_directory = self.set_screenshot_directory( EMBED)
def __init__(self, *args, **kwargs) -> None: self.logger = logging.getLogger(__name__) self.using_testability = False if "use_testability" in args: self.using_testability = True args = filter(lambda x: x != "use_testability", args) if "plugins" in kwargs.keys( ) and "SeleniumTestability" in kwargs["plugins"]: # SeleniumTestability already included as plugin self.using_testability = True elif self.using_testability and "plugins" in kwargs.keys(): # Adding SeleniumTestability as SeleniumLibrary plugin kwargs["plugins"] += ",SeleniumTestability" elif self.using_testability: # Setting SeleniumTestability as SeleniumLibrary plugin kwargs["plugins"] = "SeleniumTestability" locators_path = kwargs.pop("locators_path", locators.DEFAULT_DATABASE) SeleniumLibrary.__init__(self, *args, **kwargs) self.drivers = [] self.locators = locators.LocatorsDatabase(locators_path) self._element_finder.register("alias", self._find_by_alias, persist=True)
def test_duplicate_name(): content = copy.deepcopy(CONTENT) content[0]["name"] = content[2]["name"] database = locators.LocatorsDatabase(to_stream(content)) database.load() assert database.error is not None assert len(database.locators) == 0
def test_load_malformed(): stream = io.StringIO("not-a-json{]}\\''") database = locators.LocatorsDatabase(stream) database.load() assert database.error is not None assert len(database.error) == 2 assert len(database.locators) == 0
def test_missing_name(): content = copy.deepcopy(CONTENT) del content[1]["name"] database = locators.LocatorsDatabase(to_stream(content)) database.load() assert database.error is not None assert len(database.locators) == 0
def test_reset_error(): database = locators.LocatorsDatabase() database.path = io.StringIO("some-error") database.load() assert database.error is not None assert len(database.locators) == 0 database.path = to_stream(CONTENT) database.load() assert database.error is None assert len(database.locators) == 3
def test_load_missing(): database = locators.LocatorsDatabase("not/a/valid/path") database.load() assert database.error is None assert len(database.locators) == 0
def test_load_empty(): database = locators.LocatorsDatabase(to_stream({})) database.load() assert database.error is None assert len(database.locators) == 0
def test_load_ok(): database = locators.LocatorsDatabase(to_stream(CONTENT)) database.load() assert database.error is None assert len(database.locators) == 3
def valid_database(): database = locators.LocatorsDatabase(to_stream(CONTENT)) database.load() return database