I want to stop further execution of script if My IF condition is true in robot script

I want to stop further execution of script if My IF condition is true in robot script
e.g.
*** Test Cases ***

MyFirestTC1
LoginTest
LogicTest
SubmitTest

*** Keywords ***
LoginTest
Log I am in login test

LogicTest
IF 1==1
[Return] or do not execute further keywords. stop execution and generate report
END

SubmitTest
Log I am in submit test

In above scenario it should not run submitTest Keyword if condition is True

Hi @bk-user,

[Return] does not stop the test, it simply exits the keyword in a PASS state, so naturally Robot Frameworks says, that keyword passed so continue to the next one.

If logic test looked like this:

LogicTest
    IF 1==1
        [Return] or do not execute further keywords. stop execution and generate report
    END
    Log    After If Log Me

Then the line Log After If Log Me would not get executed.

You probably want to look at using Fail, Pass Execution, or similar keywords inside your IF statement.

Dave.

@damies13
It is continuing and executing below keyword
Log After If Log Me

I want to stop further execution.

Ah I see

It’s in the documentation for Using [Return] setting

The [Return] setting defines what the keyword should return after it has been executed

I guess meaning it doesn’t actually return from the keyword at that point (I’ve never actually used it this way). You should probably use this (post RF v5.0) syntax instead.

LogicTest
    IF 1==1
        RETURN    or do not execute further keywords. stop execution and generate report
    END
    Log    After If Log Me

But for your original issue you really need to look into using the Fail and Pass Execution keywords, as they are the one’s that should prevent the execution of SubmitTest

Dave.

The Fatal Error keyword can be used to stop the whole execution.

1 Like

@pekkaklarck
Thanks for quick response.

It is actually failing the report as below. I don’t want to fail the test case. I just want to stop execution and generate report

Also could you please help me for this. Since this is blocker for me.
Whether SFTP file upload is supported or not in robot framework

You could do something like this, the only problem is all your skipped tests will be marked as PASS not SKIP, but if that’s ok this might be a solution for you?

skippy.robot

*** Settings ***
Documentation    An example of skipping the rest of the tests without failing when one meets a certain criteria

*** Variables ***
${Skip}			False

*** Test Cases ***
Always Run
	Log 	This test always runs
	Log 	All the way to the end

Do Logic Test
	LogicTest

Skip Me
	Pass Execution If		${Skip}		Test Case Skipped
	Log		Never actually gets here
	Log		or here here

Skip Me As Well
	Pass Execution If		${Skip}		Test Case Skipped
	Log		Never actually gets here
	Log		or here here

Skip Me Too
	Pass Execution If		${Skip}		Test Case Skipped
	Log		Never actually gets here
	Log		or here here

*** Keywords ***
LogicTest
	IF 	1==1
			Set Suite Variable		${Skip}			True
      RETURN    or do not execute further keywords. stop execution and generate report
  END
  Log    After IF Log Me
1 Like

@damies13
Logic looks good but We will have to add this line -Pass Execution If ${Skip} Test Case Skipped in all the subsequest keyword and test cases to check whether ${Skip} is set to true or not. I was thinking little out of box but that’s ok

Any other way do we have?
Instead of impacting test status and we should not need to add check for ${Skip} ==True

I am looking for such solution

Hi @bk-user

I don’t know of any other way to do what you were asking for, Pekka would know better than me, and the solution I offered is, I agree, a bit of a hack, but it seems as best I can tell the Fatal Error keyword is the only alternative, but that had the test Fail which you didn’t want.

Is it possible to create a python library with a keyword that passes the current test and stops further execution? Maybe. I don’t know enough about robot framework (especially the internals) to say.

What your wanting to do seems to be a bit of an unusual scenario, but I guess if it’s important enough to you raise a feature request, the worst that could happen is it gets rejected and your in the same place as now.

Dave.

@damies13
Can you please help me for the process to create feature request.
Thanks for your suggestion

Hi @bk-user

Refer to the Contribution guidelines, particularly the sections Submitting issues and Enhancement requests

Like you, I am just someone who uses Robot framework, so I can’t guarantee any outcome.

Dave.

Ok Thanks @damies13

1 Like

Could you not incorporate the Skip If KW that BuiltIn offers?

You could probably also play around with tags, not had much time to have a play, so just passing and wanted to throw that Skip If KW out there.

Thanks

1 Like

@_daryl
I tried with -
Pass Execution
Fail
SKIP

But is is overriding original status of test. As I have to perform some activity based on ${TEST_STATUS } in Test Cleanup, If I marked that as SKIP and if all of the keyword already passed/failed then it is marking overall status as SKIP.

I don’t want to impact current Test Status.

No worries, your statement here:

“As I have to perform some activity based on ${TEST_STATUS } in Test Cleanup, If I marked that as SKIP and if all of the keywords already passed/failed then it is marking overall status as SKIP.”

The Skip and Skip If doesn’t override the original status :confused: only that one test or many for which you choose to skip would show as SKIP as they are being skipped from running if you choose to skip it due to the outcome of another test, while all other tests would show PASS or FAIL? so in your post example: “SubmitTest” would hold a status of SKIP while all others would be PASS or FAIL.

Unless you’re speaking about the individual keywords in an individual test case then they would show their outcome in the generated report anyways.

I’d assume in your clean up as you speak about doing action on ${TEST_STATUS } you’d be able to handle/ignore skipped tests as you can access the test status from there if you were not to use the keyword Pass Execution and were to actually show the SKIP status for what it is actually doing.

@_daryl

*** Settings ***
Library String
Library SSHLibrary
Test Teardown Test Cleanup

*** Variables ***
${HOST}= ste.io

*** Test Cases ***
Stop Task
Keyword1
Keyword2
StopMe stop
Keyword3

*** Keywords ***
Keyword1
Log I am in keyword1

Keyword2
Log I am in keyword2
${status}= Run Keyword And Return Status Login With Public Key test key allow_agent=True look_for_keys=True

Keyword3
Log I am in keyword3

StopMe
[Arguments] ${param}
IF “${param}” == “stop”
Log call stop me
Pass Execution message

Run Keyword And Return Status Fatal Error End Of Review Mode

Run Keyword And Ignore Error Skip

END
[Return]

Test Cleanup
Log In Test Teardown
Log ${TEST_STATUS}

Result

If any of the keyword status is failed then it should not mark overall ${TEST_STATUS} to pass. Since I have used pass execution it is marking overall status to PASS. Because in Test TearDown based on status , I have to perform some other task

Hence I want to stop execution without impacting original ${TEST_STATUS}

Hi

I wasn’t suggesting you use Pass Execution If, but more having it return as SKIP for what it is doing, to that end using Skip If or Skip.

But was more so was throwing out there that there was that keyword as well that you could play around with.

1 Like

Hi @bk-user,

Have a look at the answer by @MahmoudIMahmoud in this thread → Test case prioritisation - #3 by MahmoudIMahmoud

That might help you with this issue.

Dave.