Find All Tests Cases which reference a given Keyword (directly or via another keyword)

I am working with a Suite that is quite large and often find a need to change some behaviors within a Keyword that I want to then ensure doesn’t cause problems. Up until now, I just search for references and try to perform some due diligence examining and manually running some set of tests followed by just running the whole Suite overnight (as it runs for 16+ hours).

I am looking to do something where I can use prerunmodifier to tag Tests accordingly so that any Test using the desired keyword (directly or indirectly) is executed.

I have successfully managed to get it to run any Tests that directly call a given keyword as follows but cannot figure out how to extend it to look through all the Keywords recursively. Is this possible? Is it terrible idea?? I understand that if I wasn’t careful, it could end up running MANY (or even All Tests)

robot --prerunmodifier keyword_filter.KeywordFilter:"MyModifiedKeyword" --exclude skip .\Tests\UI\MyApplication

against a python file such as…

from robot.api import SuiteVisitor

class KeywordFilter(SuiteVisitor):
    def __init__(self, keyword):
        self.keyword = keyword

    def start_test(self, test):
        if not any(self.keyword in kw.name for kw in test.body):
            test.tags.add('skip')

Doing what you want isn’t unfortunately possible with a pre-run modifier. The reason is that in the execution model that you modify, keywords only represent a keyword call with a name and arguments, and the actual keyword that will be run is resolved only during execution. You thus cannot see what lower level keywords actually are run.

An alternative is using a listener. Then you see all executed keywords, but also then you don’t see them when the test starts. Good news is that if you use the listener v3 API and RF 7.1 or newer, you can skip a test by setting result.status to SKIP in end_keyword or end_user_keyword. In this usage doing that already in start_user_keyword would be especially useful, but I think that’s not supported (and don’t have time to check). If it isn’t, and it would be useful for you, please submit an issue and we can look at it in RF 7.3.

1 Like

Thank you Pekka and keep up the great work! I could see that being useful in different ways.

For my purposes, I hope to spend some time looking at what is available in VSCode / Robot Framework Language Server extension as perhaps some unique utilization of a “Find All References” might be achievable since I am really trying to figure out what Tests to run when I alter a Keyword. Side Note: I always run Lint after I do this kind of thing.

Hi Scott,

Perhaps combining the listener that @pekkaklarck mentioned with --dryrun might get you what you want?

Otherwise if you want to do it in code, you probably need a self recursive function that iterates in a for loop over the identified keywords and then resolves the keywords in them, then calls itself with each keyword, but that could potentially get quite slow for the user.

Dave.

I just want to suggest the RIDE feature, “Find where used” or “Find Usages”. I am actually working on improving its code. Maybe we can chat about it.