Skip to content

robot.running.keywordfinder

KeywordFinder

KeywordFinder(owner: TestLibrary | ResourceFile)

Bases: Generic[K]

Source code in src/robot/running/keywordfinder.py
def __init__(self, owner: 'TestLibrary|ResourceFile'):
    self.owner = owner
    self.cache: KeywordCache|None = None

find

find(name: str, count: Literal[1]) -> K
find(name: str, count: int | None = None) -> list[K]
find(name: str, count: int | None = None) -> list[K] | K

Find keywords based on the given name.

With normal keywords matching is a case, space and underscore insensitive string comparison and there cannot be more than one match. With keywords accepting embedded arguments, matching is done against the name and there can be multiple matches.

Returns matching keywords as a list, possibly as an empty list, without any validation by default. If the optional count is used, raises a ValueError if the number of found keywords does not match. If count is 1 and exactly one keyword is found, returns that keyword directly and not as a list.

Source code in src/robot/running/keywordfinder.py
def find(self, name: str, count: 'int|None' = None) -> 'list[K]|K':
    """Find keywords based on the given ``name``.

    With normal keywords matching is a case, space and underscore insensitive
    string comparison and there cannot be more than one match. With keywords
    accepting embedded arguments, matching is done against the name and
    there can be multiple matches.

    Returns matching keywords as a list, possibly as an empty list, without
    any validation by default. If the optional ``count`` is used, raises
    a ``ValueError`` if the number of found keywords does not match. If
    ``count`` is ``1`` and exactly one keyword is found, returns that keyword
    directly and not as a list.
    """
    if self.cache is None:
        self.cache = KeywordCache[K](self.owner.keywords)
    return self.cache.find(name, count)