# How to create condition for test result ==passed

**URL:** <https://forum.robotframework.org/t/how-to-create-condition-for-test-result-passed/7627>\
**Category:** Robot Framework\
**Created:** [25 July 2024 18:14 UTC](https://forum.robotframework.org/t/how-to-create-condition-for-test-result-passed/7627 "2024-07-25T18:14:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![samsanati2000](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/samsanati2000/32/4108_2.png) [@samsanati2000](https://forum.robotframework.org/u/samsanati2000)\
**Post date:** [25 July 2024 18:14 UTC](https://forum.robotframework.org/t/how-to-create-condition-for-test-result-passed/7627/1 "2024-07-25T18:14:20Z")

</div>

How do I do this?  
if test 1 passed run test 2  
or if keyword 1 passed run keyword 2

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [25 July 2024 18:59 UTC](https://forum.robotframework.org/t/how-to-create-condition-for-test-result-passed/7627/2 "2024-07-25T18:59:46Z")

</div>

Hi,

There are probably multiple solutions, but the keyword idea is a good one. Something like this.

```
***Tests Cases***
TEST1
    ${TEST1_STATUS} Run Keyword And Return Status TEST1 CASE

TEST2
    IF '${TEST1_STATUS}' == 'PASS'
        ${TEST2_STATUS} Run Keyword And Return Status TEST2 CASE
    END

***Keywords***
    TEST1 CASE
        _steps_

    TEST2 CASE
        _steps_

```

Important thing is to have ${TEST1\_STATUS} as a suite variable reachable from TEST2, but you could also use in TEST2 the built-in ${PREV\_TEST\_STATUS} if tests are sequential.  
Also you could use Skip If ${TEST1\_STATUS} != PASS directly, or FAIL in a if then else statement.

Regards.  
Charlie

---

<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:** [25 July 2024 23:45 UTC](https://forum.robotframework.org/t/how-to-create-condition-for-test-result-passed/7627/3 "2024-07-25T23:45:57Z")

</div>

Hi Charlie,

When doing things like it’s important to pay attention to [variable scopes](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#variable-scopes), pretty sure `${TEST1_STATUS}` is in Local scope, or maybe Test case scope as it was at the top level of the test case, so it won’t have a value in `TEST2`

Dave.

---

<div class="post-metadata">

**Author:** ![CharlieScene](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/charliescene/32/3484_2.png) [@CharlieScene](https://forum.robotframework.org/u/CharlieScene)\
**Post date:** [26 July 2024 06:19 UTC](https://forum.robotframework.org/t/how-to-create-condition-for-test-result-passed/7627/4 "2024-07-26T06:19:09Z")

</div>

Yes, I mentioned this below the code 😉

Btw I’m still wondering what’s the best way to redefine scope of a variable during a test or in a keyword, other that setting it this way:

```
 VAR ${MYVAR} ${MYVAR} scope=SUITE

```

---

<div class="post-metadata">

**Author:** ![FrancisG](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.robotframework.org/francisg/32/4247_2.png) [@FrancisG](https://forum.robotframework.org/u/FrancisG)\
**Post date:** [5 August 2024 08:21 UTC](https://forum.robotframework.org/t/how-to-create-condition-for-test-result-passed/7627/5 "2024-08-05T08:21:49Z")

</div>

For conditionally executing test cases you might be interested in [robotframework-dependencylibrary](https://forum.robotframework.org/t/unable-to-import-robotframework-appiumlibrary-even-after-successful-installation-in-pycharm/6990).

There are also some [automatic variables](https://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#automatic-variables) that could be useful, such as ${PREV TEST STATUS}
