简体   繁体   中英

How to run a specific test case along with failed test cases in Robot Framework

I have a test case in Robot Framework in the following format-

test_case 1: login
----
----
test_case 2: access name
----
----
test_case 3: access data
----
----
test_case 50: ...

Consider that test_case 3 or test_case 10 fails. When I use --rerunfailed to run the failed test cases, it fails again because test_case 1: Login generates the session cookies which is needed to run the following test cases successfully, as they are using the same session cookies .

So, my question is how to run test_case 1: Login along with failed test_cases?

First of all I want to point out that your test architecture is wrong and you create a test case dependencies. A good discussion how to create independent tests can be found here: https://sqa.stackexchange.com/questions/32193/automation-how-to-isolate-test-cases-when-they-really-depend-on-another-one

Now back to the question:

So, my question is how to run test_case 1: Login along with failed test_cases?

In general you can't do that.

What I would recommend is to create a setup keyword which generates the needed session cookies and then use this data in the tests. If the session cookies can be reused you can call the setup keyword in Suite Setup, so that it will be executed once and available let say as some suite variable for all the tests from the suite. If you have different suites you can increase the variable visibility to global, so that it can be accessed in all suites. Put a logic if the session cookies already exist in this variable to return from the setup keyword.

So, my question is how to run test_case 1: Login along with failed test_cases?

Short answer: you can't. Robot isn't really designed around the idea that tests have dependencies on other tests.

Long answer: The best solution is to use a keyword to login, and make that part of the test or suite setup. Since you only want to log in once for the whole suite, the keyword can set a flag so that it only actually logs in a single time.

The other option is to write your own script that can parse the robot output file, generate a list of failed test, and then use whatever algorithm you want to add additional tests. Then, the script can run robot and tell it to run your custom list of tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM