Skip to content

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

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
saifjarboui opened this issue Aug 28, 2023 · 8 comments
Closed

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

saifjarboui opened this issue Aug 28, 2023 · 8 comments

Comments

@saifjarboui
Copy link

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

@JFoederer
Copy link
Contributor

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.

@saifjarboui
Copy link
Author

saifjarboui commented Sep 1, 2023 via email

@JFoederer
Copy link
Contributor

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.

@saifjarboui
Copy link
Author

saifjarboui commented Sep 4, 2023 via email

@JFoederer
Copy link
Contributor

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
Copy link
Contributor

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

@pekkaklarck
Copy link
Member

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
Copy link
Member

No updates, closing.

@pekkaklarck pekkaklarck closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2025
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

3 participants