python - Robot Framework location and name of keyword -
i want create python library 0 argument function custom robot framework keywords can call. needs know absolute path of file keyword defined, , name of keyword. know how similar test cases using robot.libraries.builtin
library , ${suite_source}
, ${test name}
variables, can't find similar custom keywords. don't care how complicated answer is, maybe have dig guts of robot framework's internal classes , access data somehow. there way this?
thanks janne able find solution.
from robot.running.context import execution_contexts def resource_locator(): name = execution_contexts.current.keywords[-1].name libname = execution_contexts.current.get_handler(name).libname resources = execution_contexts.current.namespace._kw_store.resources path = "" key in resources._keys: if resources[key].name == libname: path = key break return {'name': name, 'path': path}
execution_contexts.current.keywords
stack of keywords called, earliest first , recent last, execution_contexts.current.keywords[-1]
gets last keyword, keyword called function.
execution_contexts.current.get_handler(name).libname
gets name of library in keyword name
defined. in case of user defined keywords, filename (not full path) minus extension.
execution_contexts.current.namespace._kw_store.resources
dictionary of included resources, key absolute path. because file path key, have search key such value's name name of resource in keyword defined (libname
)
Comments
Post a Comment