4.2. List test cases
Goal
- Write a new Python script which lists the test cases in a given suite.
- Create a new folder named
tools
in thetests
folder and save your script into that folder astest_case_list.py
. - The script should accept the path to the suite as a command line argument (the path can point to a folder or to a
.robot
file). - The script should iterate through every suite in the given path.
- Create a new folder named
Solution
Hints
It is recommended to use argparse
module from the Python standard library to process command line arguments.
Click here to learn more about argparse
module.
You can use TestSuiteBuilder
class from robot.running
package to parse the test data in the given path.
Click here to learn more about how to use the TestSuiteBuilder
class.
Solution: tests/tools/test_case_list.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
|
Results
Inside the tests
folder, execute the following command.
1 |
|
The output should be something like this:
Root Suite: Tests
-
Test Case: Tests.01-Greetings.01-Greetings.Original Greetings
Tags: [ubuntu]
Documentation: This test case checks that the Print Your Name keyword works as expected.
-
Test Case: Tests.01-Greetings.01-Greetings.Greetings Again
Tags: [centos]
Documentation: This test case proves that we can import variables from resource files.
-
...
You can also list the test cases of a single .robot
file.
1 |
|
The output should be something like this:
Root Suite: 01-Lists
-
Test Case: 01-Lists.Greetings Everyone
Tags: [loop]
Documentation: This test case verifies the functionality of 'Print Multiple Names' keyword.
-
Test Case: 01-Lists.Students
Tags: []
Documentation: This test case logs the names from students.txt to console.
-
Last update: August 30, 2020