diff --git a/src/robot/libraries/BuiltIn.py b/src/robot/libraries/BuiltIn.py index 50bd99f131e..e2286f92fa0 100644 --- a/src/robot/libraries/BuiltIn.py +++ b/src/robot/libraries/BuiltIn.py @@ -3781,6 +3781,39 @@ def evaluate(self, expression, modules=None, namespace=None): evaluation namespace. It needed to be taken into use explicitly like ``modules=rootmod, rootmod.submod``. """ + + """ + If Libraries are aliased when imported, substitute alias for actual library + This is so the correct library can be passed to the python execution + The first for loop is to ensure there are no ambiguous substitutions + The second executes the substitutions for any assumed object dereference + operations + Currently this will execute the substitution inside a string + Example: + Library foo AS BAR + Evaluate BAR.baz() --> Evaluate foo.baz() + + Library foo AS BAR + Evaluate BAR.BAR.baz() --> Evaluate foo.BAR.baz() + """ + libraries = self._namespace._kw_store.libraries + for library in libraries.values(): + for name, module_obj in libraries.items(): + if name != library.name and ( + module_obj.real_name == library.name or + module_obj.real_name == library.real_name): + raise DataError("Evaluate Expression failed: " + f"Ambiguous aliases with Library '{name}' " + f"As '{module_obj.real_name}' and Library " + f"'{library.name}' As '{library.real_name}'") + for library in libraries.values(): + if library.name != library.real_name: + escaped_name = re.escape(library.name) + search_regex = re.compile(r'(?