2.5. Module based libraries
Goal
- Create a new module based library named
HelperLibrary
with a keyword namedGenerate Random Number
. This keyword should return a random number between0
and100
. - Make sure that the
HelperLibrary
available to every test case. - Create a new suite variable named
@{STUDENTS}
in02-Exams
suite and store some names in it. - Create a new test case named
Generate Exam Results
in02-Exams
suite which will useGenerate Random Number
keyword for every student. Save the results in a file namedyet_another_results_file.txt
in the following format:Jane Doe: 80%
. - Make sure that the
yet_another_results_file.txt
is removed before the test case execution starts.
Solution
Hints
Test libraries can be implemented as Python modules and Python or Java classes.
Click here to learn more about creating test libraries.
You can define test setup with [Setup]
setting in the Test Case table. Click here to learn more about test setup and teardown functionality.
Solution: tests/libraries/HelperLibrary.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Solution: tests/02-classroom/02-exams.robot
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 |
|
Results
To be able to import HelperLibrary
without defining the whole path to the file, you need to set its location with --pythonpath
parameter.
Inside the tests
folder, execute the following command to execute 02-Exams
suite.
1 |
|
The content of the 02-classroom/test_data/yet_another_results_file.txt
should be something like this:
Jane Doe: 78%
John Doe: 61%
You can check the generated log.html
file to see how your test cases worked.
Last update: June 22, 2020