*** Settings ***
Test Teardown My Teardown Keyword
*** Keywords ***
My Teardown Keyword
Function 1
Set test message ${my message here}
Function 2
Set test message prints whatever you want on message column in report.html. The thing is, if my Test Teardown fails, the error message overwrites the ${TEST MESSAGE} global variable being used by Set test message so whatever its previous contents are, it won't be displayed on the report.html message column, only the error message.
Is there a workaround I can do here to still print the original contents of the ${TEST MESSAGE} variable even if Test Teardown fails?
Related
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.
I have used TestNG SoftAssert feature in Java where we do multiple verifications and store result of each verification in SoftAssert and at the end of test case assert test case with all verification results.
I could not found a similar feature in Robot Framework. Does anyone know how to implement this feature or use it if exists in RobotFramework?
You can use Run keyword and continue on failure. If the keyword you run fails, the test will continue to run and report the failure at the end.
Example:
Here is a test that uses this keyword:
*** Test cases ***
Example
run keyword and continue on failure log this passes
run keyword and continue on failure fail this is a failure
run keyword and continue on failure log this also passes
run keyword and continue on failure fail this is also a failure
When run, you will see this on the console:
==============================================================================
Example
==============================================================================
Example | FAIL |
Several failures occurred:
1) this is a failure
2) this is also a failure
------------------------------------------------------------------------------
Junk | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
You could also use that keyword as the value for a test template, though I don't think I would recommend it as a standard practice:
*** Test cases ***
Example
[template] run keyword and continue on failure
log this passes
fail this is a failure
log this also passes
fail this is also a failure
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.
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.
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?)