Skip to content

Question: how to get keyword results in listener #5400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
slavaGanzin opened this issue Apr 14, 2025 · 2 comments
Open

Question: how to get keyword results in listener #5400

slavaGanzin opened this issue Apr 14, 2025 · 2 comments

Comments

@slavaGanzin
Copy link

slavaGanzin commented Apr 14, 2025

Hello there, awesome work on Robot, thanks everyone

I have stupid question:
How to get keyword value in listener?

So for example I do have a testing library:

@library(scope="TEST", version="0.0.1", doc_format="ROBOT")
class Test:
    @keyword
    def test(self):
      return 'result'

And I have listener(v3) with defined method end_keyword:

    def end_keyword(
        self, data: robot.running.model.Keyword, result: robot.result.Keyword
    ):
        result.what? == 'result'

robot.result.Keyword looks like is not holding result, despite its name. And result is accessible to robot, because you can assign it to variable. But how to get it from listener?

Use case would be to collect artifacts in some other way.

@pekkaklarck
Copy link
Member

Return values aren't exposed via the result model directly. One reason is that return values can be huge and storing them could waste a lot of memory and disk space. Return values are logged, though, and that automatic message can be inspected in the log_message method. Due to the values potentially being huge, that message only contains the beginning of the result, though. It's also possible to log the whole value explicitly, but then you need to make changes to the data. Logged messages are also always strings, which is likely a problem if the return value is something else.

I can see that it would be convenient to have a direct access to return values somehow, and being able to change the return value could be useful too. In addition to that, it could be nice to a direct access to used arguments and to be able to modify them. The main question is, how should these APIs work?

@slavaGanzin
Copy link
Author

Hi Pekka @pekkaklarck

You do have a keyword.Result class, and right now it holds everything except an actual result. "They could be huge" is a weak argument against it; if it's huge, so what? The Puppeteer process consumes a lot more memory than 99.99% of keyword results would. I only have access to them when the keyword is returning their value inside the listener, so I can collect, modify, and probably assign them to a variable. Garbage collect them right away if you're so concerned about memory.

For my use case, I would be fine if the variable ${previous_keyword_result} were created after each keyword run; it will simplify a lot of code. So this:

${title} = Get Title
Should Match  'ok' ${title}

Will became:

Get Title
Should Match  'even better' ${previous_keyword_result}

A little like bash is doing with $?, hacky, less descriptive but works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants