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

**URL:** <https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412>\
**Category:** Robot Framework\
**Created:** [8 March 2023 13:06 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412 "2023-03-08T13:06:05Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [8 March 2023 13:06 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/1 "2023-03-08T13:06:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [8 March 2023 13:53 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/2 "2023-03-08T13:53:37Z")

</div>

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:

```python
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](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Fail), [Pass Execution](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Pass%20Execution), or similar keywords inside your IF statement.

Dave.

---

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [8 March 2023 14:29 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/3 "2023-03-08T14:29:23Z")

</div>

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

I want to stop further execution.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [8 March 2023 14:51 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/4 "2023-03-08T14:51:14Z")

</div>

Ah I see

It’s in the documentation for [Using [Return] setting](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#toc-entry-349)

> 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.

```python
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](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Fail) and [Pass Execution](https://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Pass%20Execution) keywords, as they are the one’s that should prevent the execution of `SubmitTest`

Dave.

---

<div class="post-metadata">

**Author:** ![pekkaklarck](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/pekkaklarck/32/1019_2.png) [@pekkaklarck](https://forum.robotframework.org/u/pekkaklarck)\
**Post date:** [8 March 2023 15:33 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/5 "2023-03-08T15:33:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [9 March 2023 03:13 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/6 "2023-03-09T03:13:51Z")

</div>

@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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/3/373fc51281bca11bd5cfd9c926d9d021d7a43a16.png)

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

> [@Paramiko.transport: EOF in transport thread](https://forum.robotframework.org/t/paramiko-transport-eof-in-transport-thread/5403):
>
> I have below versions - paramiko==3.0.0 paramiko-ng==2.8.10 Python 3.8.3 I am trying to connect with SFTP server using keyfile and have to upload file. but I am getting below error in logs DEB [20230306-10:04:13.216] thr=2 paramiko.transport: Adding ssh-rsa host key for sbx.filla.in: b2dee68b81745535bb5bff4a22ca8cf0 DEB [20230306-10:04:13.266] thr=1 paramiko.transport: userauth is OK DEB [20230306-10:04:13.277] thr=1 paramiko.transport: Authentication type (none) not permitted. DE…

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [9 March 2023 09:24 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/7 "2023-03-09T09:24:43Z")

</div>

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_

```python
***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

```

---

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [10 March 2023 09:22 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/9 "2023-03-10T09:22:32Z")

</div>

@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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [10 March 2023 10:38 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/10 "2023-03-10T10:38:11Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [10 March 2023 13:29 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/11 "2023-03-10T13:29:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [10 March 2023 13:34 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/12 "2023-03-10T13:34:58Z")

</div>

Hi @bk-user

Refer to the [Contribution guidelines](https://github.com/robotframework/robotframework/blob/master/CONTRIBUTING.rst), particularly the sections [Submitting issues](https://github.com/robotframework/robotframework/blob/master/CONTRIBUTING.rst#submitting-issues) and [Enhancement requests](https://github.com/robotframework/robotframework/blob/master/CONTRIBUTING.rst#enhancement-requests)

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

Dave.

---

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [10 March 2023 13:36 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/13 "2023-03-10T13:36:04Z")

</div>

Ok Thanks @damies13

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [10 March 2023 14:13 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/14 "2023-03-10T14:13:45Z")

</div>

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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/8/86ef23d4204423dc1788d0860ad54152629d9c3b.png)

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

---

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [10 March 2023 14:28 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/15 "2023-03-10T14:28:39Z")

</div>

@_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.

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [10 March 2023 14:51 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/16 "2023-03-10T14:51:58Z")

</div>

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 😕 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.

---

<div class="post-metadata">

**Author:** ![bk-user](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/bk-user/32/1446_2.png) [@bk-user](https://forum.robotframework.org/u/bk-user)\
**Post date:** [10 March 2023 19:57 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/17 "2023-03-10T19:57:23Z")

</div>

@_daryl

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

\*\*\* Variables \*\*\*  
${HOST}= [ste.io](http://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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/robotframework1/original/2X/2/217267ce0425f09e78b9ae7c9352568ed8484b19.png)

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}

---

<div class="post-metadata">

**Author:** ![\_daryl](https://avatars.discourse-cdn.com/v4/letter/_/45deac/32.png) [@\_daryl](https://forum.robotframework.org/u/_daryl)\
**Post date:** [11 March 2023 18:00 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/18 "2023-03-11T18:00:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![damies13](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/damies13/32/623_2.png) [@damies13](https://forum.robotframework.org/u/damies13)\
**Post date:** [24 March 2023 04:54 UTC](https://forum.robotframework.org/t/i-want-to-stop-further-execution-of-script-if-my-if-condition-is-true-in-robot-script/5412/19 "2023-03-24T04:54:56Z")

</div>

Hi @bk-user,

Have a look at the answer by @MahmoudIMahmoud in this thread → [Test case prioritisation - #3 by MahmoudIMahmoud](https://forum.robotframework.org/t/test-case-prioritisation/5458/3)

That might help you with this issue.

Dave.
