Skip to content

Library internal argument conversion with Robot Framework API #4109

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

Closed
aaltat opened this issue Oct 4, 2021 · 6 comments
Closed

Library internal argument conversion with Robot Framework API #4109

aaltat opened this issue Oct 4, 2021 · 6 comments

Comments

@aaltat
Copy link
Contributor

aaltat commented Oct 4, 2021

Browser library has similar run on failure support as SeleniumLibrary has, but Browser library supports arguments with the Register Keyword To Run On Failure keyword. But because registered keyword arguments can be almost anything, Browser library can not define typing for the arguments and therefore Robot Framework can not perform automatic conversion to the arguments. There is an issue which demonstrates the problem when we do not perform the conversion.

Therefore I was thinking to do conversion inside of the library. I think it can be done if the run on failure keyword is one of the browser library keywords, because then library knows the argument specification. But the argument conversion is pretty complex problem to do, so I was thinking that I could use some Robot Framework code. Is there some entry point which would allow to do the conversion easily?

@pekkaklarck
Copy link
Member

Exposing argument conversion publicly would be a good idea. Not exactly sure what's the best API for that, though. Anyway, something that could be added in RF 5.0.

@pekkaklarck pekkaklarck added this to the v5.0 milestone Oct 5, 2021
@pekkaklarck pekkaklarck removed this from the v5.0 milestone Mar 4, 2022
@pekkaklarck
Copy link
Member

Could you @aaltat clarify this request a bit more? I checked the linked Browser library issue and notice it was fixed already. Was this issue not relevant or was there some existing way to handle conversion?

I removed this from RF 5.0 scope because we'd like to get that release out ASAP and because I'm not sure what we actually should even do to address this. If there's something concrete to do, this issue can be added to RF 5.1 scope.

@pekkaklarck
Copy link
Member

pekkaklarck commented Mar 4, 2022

I don't actually understand the whole need for argument conversion in Browser side. AFAIK it uses BuiltIn.run_keyword and it should handle conversion based on the type information of the called keyword automatically. For example, if I have a dummy library like

from robot.libraries.BuiltIn import BuiltIn


def kw1(arg: int):
    assert arg == 42


def kw2(arg):
    BuiltIn().run_keyword('kw1', arg)

I can use it as follows and 42 is converted to an integer correctly.

*** Test Cases ***
Example
  kw2    42

BuiltIn.run_keyword is a pretty bad API for running other keywords, though, as #4237 explains. If we add a new and better API, need to take conversion into account with it.

@aaltat
Copy link
Contributor Author

aaltat commented Mar 9, 2022

When keyword originates from the same library, arguments are not problem. But keyword is not from same library arguments are problematic because args can be almost anything and then it get pretty complicated how that works. Or is there some shortcut to happiness which I do not see?

@pekkaklarck
Copy link
Member

It seems that #4942 proposed the same thing and it was implemented in RF 7.0.

@pekkaklarck
Copy link
Member

@aaltat agreed. Closing.

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

No branches or pull requests

2 participants