Run Keyword If Test Failed BDD Robot Framework - robotframework

I have a .robot file with settings where I import keywords and Test Cases in Gherkin/BDD.
There is an issue if one test cases fails, due to the nature of the testing all the other test cases in the .robot file fail.
Before I run the test I initialize the test with a keyword.
I would like to run that keyword to re-initialize and run the next test case in the file.
*** Settings ***
Resource My_keywords.robot
*** Test Cases ***
000 Test Inicialization 000
Inicialize test
001 First test 001
Test something

Related

Start second test only if first test fails in RobotFramework

I got 2 testcases defined in RobotFramework
test1
test2
Is it possible to start test2 only when test1 fails?
One way of achieving this is by making use of robotframework-dependencylibrary.
excerpt from this library
Declare dependencies between tests. Make tests automatically fail
based on the results of other test cases or test suites.
In the below example, you can make use of "Depends on test" keyword as shown.
*** Settings ***
Library DependencyLibrary
*** Test cases ***
Passing Test
No operation
Failing Test
Fail This test is intentionally hardcoded to fail
This Test Depends on "Passing Test" Passing
Depends on test Passing Test
Log The rest of the keywords in this test will run as normal.
This Test Depends on "Failing Test" Failing
Depends on test failure Failing Test
Log The rest of the keywords in this test will run as normal.

How to create _init_.robot and use it for all robot files in the directory in robot framework?

I am trying to include_init_.robot file in the test suite. I have added a test implementation to check the method it would work, however I am unable to figure out it's execution. Code is as follows:
init.robot
*** Settings ***
Documentation Suite description
Suite Setup Initialization In Progress
*** Keywords ***
Initialization In Progress
log many THE CODE WORKS NOW
test#1.robot
*** Settings ***
Documentation Suite description
*** Test Cases ***
Test Case Execution
log many TC EXECUTED
Code used to run the test: pybot folder_name
The name of the first file is incorrect. You have
_init_.robot
while it should be
__init__.robot
When you do that the log will show this:

Can't specify include tags when using set Tag in Robot Framework

I am using data driven tests and setting the tags as part of the data. Below is the simplified code:
*** Settings ***
Test Template TN Lookup
*** Testcases ***
Testa Hi TC-1
Bye TC-2
*** Keywords ***
TN Lookup
[Arguments] ${text} #{tags}
Set tags #{tags}
Log to console ${text}
Yet when I run the command:
robot -i TC-1 filename.robot
Both test cases run. How can I specify which tags to run when using set Tags keyword or does this not work?
The -i flag is only processed at the start of the test run and is only influenced by tags present before the tests run. Once the tests start running, you can't change what will or won't be run.

Run keyword at suite level only if the test cases in that suite pass when executed

I need to run the keyword only if the test case passes.How can i setup it up at Test suit level?
In your Suite Teardown, you can use the (automatic) variable ${SUITE_STATUS}. This variable is document in here and contains "The status of the current test suite, either PASS or FAIL". So it will contain PASS when all the test cases of the suite are passing.
Here is how it can be used:
my_suite_teardown
Run Keyword If '${SUITE_STATUS}' == 'PASS' your_keyword
The built-in library has keywords specifically for this purpose.
You can call these keywords in a suite setup:
Run keyword if any test failed
Run keyword if any critical tests failed
You can call these keywords in a test case teardown:
Run keyword if test failed
Run keyword if test passed
For example:
*** Settings ***
Test Teardown Perform test teardown
Suite Teardown Perform suite teardown
*** Keywords ***
Perform suite teardown
run keyword if any test failed
... log "Hey, this suite failed!" WARN
Perform test teardown
run keyword if test failed
... log "Hey, this test failed!" WARN
Suite and test case teardowns are described in the robot framework user guide in a section titled Setups and teardowns.

Robotframework: how to show passed test as "PASS" even if suite teardown were "Fail"

I use robot framework at following environment.
Python 2.7.6
robotframework 2.8.7
Ubuntu 14.04.3 LTS
I use robotframwork like this.
*** settings ***
Suite Setup setupkeyword # Provisioning for test
Suite Teardown teardownkeyword # Delete all resources
*** testcases ***
TestCase1
TestCase2
TestCase3...
In this case,
if Teardown fails, test case is shown Failed in report like followings.
Suite Setup:PASS
Suite Teardown:FAIL
TestCase1:FAIL
TestCase2:FAIL
TestCase3:FAIL
But Teardown is not the purpose of this test,
So I want report shows like followings.
Suite Setup:PASS
Suite Teardown:FAIL
TestCase1:PASS
TestCase2:PASS
TestCase3:PASS
I test like followings.
Suite Teardown Run Keyword And Ignore Error teardownkeyword # Delete all resources
But in this case, report shows
Suite Teardown:PASS
but I want to know whether Teardown was passed or not.
Is there any good method for this case?
I think the best method would be to redesign teardown keyword to give a warn when it is about to fail (but avoid failure). It can be accomplished with log keyword:
Log This keyword would fail due a some reason level=WARN
you could try with level=ERROR (maybe it won't fail whole test suite then?)

Resources