robotframework icon indicating copy to clipboard operation
robotframework copied to clipboard

possibility to get return value and fail keyword at the same time

Open saifjarboui opened this issue 2 years ago • 7 comments

I am running the robot test in the context of continue on failure. It seems that it doesn't go with the python implemented keywords where I use nested keywords as a workaround to achieve what I need (we have restrictions from using resource files, so we need pure python implementation).

Python Script: ` @keyword def raise_fail(self): raise ExecutionFailed("nooo")

@keyword(tags=["robot:continue-on-failure"])
def check_kahaw(self,value, expected_value):
    BuiltIn().run_keyword("Raise Fail")
    Print('yes')
    return True



@keyword
def check_value_and_fail_if_not_expected(self, value, expected_value):
    
    status = BuiltIn().run_keyword_and_continue_on_failure("Check Kahaw",value, expected_value)
    print("yes!!")
    if status!=True:
        return False
    return True
    `

testcase: `*** Variables *** ${var} ${1}

*** Test Cases ***

test [Tags] robot:recursive-continue-on-failure

log    start

${bool1}=    Check Value And Fail If Not Expected    ${1}    ${var}
log    ${bool1}
${bool2}=    Check Value And Fail If Not Expected    ${2}    ${var}
log    ${bool2}

`

output:

image

saifjarboui avatar Aug 28 '23 17:08 saifjarboui

Hi @saifjarboui, Would this library be helpful to you? robotframeworkNL

The Check that keyword has continue on failure by default and accepts other keywords as input for the checks.

JFoederer avatar Sep 01 '23 11:09 JFoederer

Thank i will try it. The problem here is that i use continue on failure explicitly from builtin yet it has no effect. I doubt that it will do something special. The bog issue here is that I am using RED editor. Which make me stuck in an old version of RF due to end of development of that project. I am looking for something that could help me in that version. Even changing or prompting the keyword to fail.

saifjarboui avatar Sep 01 '23 21:09 saifjarboui

Sorry, I misunderstood the issue. Although the real issue could be, as you mention, that RED editor isn't being maintained anymore. There have been so many improvements to Robot Framework since then, and also to alternatives for RED, that it is difficult to still defend RED for any project.

JFoederer avatar Sep 04 '23 06:09 JFoederer

Hi, yes you are correct although RED if it is still maintained would be on to of the Robot IDEs also can't do much thing about that since too much effort and money were invested on RED plugin and the eclipse editor in general to add specific features and waste of expertise of our java developers who no alternative other than that in this scope since pycharm is closed source and vs code is mainly cpp.

In any case one of robot maintainers or someone dug inside the source code could give a workaround or slight modification regarding this issue.

saifjarboui avatar Sep 04 '23 06:09 saifjarboui

Can you confirm if this behavior is still the same in Robot Framework 6.1?

Thinking about a workaround, there might be something you could already do yourself. Instead of using BuiltIn().run_keyword_and_continue_on_failure() you could use the regular BuiltIn().run_keyword() and put a try-except around it yourself.

JFoederer avatar Sep 04 '23 07:09 JFoederer

From static analysis I am quite sure the current behavior is the designed behavior, but I do see your point @saifjarboui

JFoederer avatar Sep 04 '23 12:09 JFoederer

The code in the issue description looks pretty complicated. Could you @saifjarboui explain why you are calling your own functions via BuiltIn.run_keyword and not directly as normal Python functions? Explaining what you actually are trying to accomplish in some more details would be good as well.

It seems that you expect BuiltIn.run_keyword_and_continue_on_failure to return the execution status, but that's not how error reporting with Robot works. Errors are always exceptions, so if there's an error, calling that method will fail. If you want to continue execution in your library, you need to use try/except. That keyword happens to raise robot.errors.ExecutionFailed, but you can also catch just Exception.

pekkaklarck avatar Dec 19 '23 23:12 pekkaklarck