pybot Command
- Run all test cases
| |
- Run a certain test suite
| |
- Run a test case in a certain test suite
| |
- Output the test results to a fixed path
| |
- Run test cases that contain a certain tag
| |
About Logging
By default, log messages below the INFO level in Robot Framework are not written to the log. This threshold can be changed with the command-line option --loglevel.
There are five log levels in Robot Framework:
- FAIL
Used when a keyword fails, and only usable by Robot Framework itself
- WARN
Used to show warnings. Warning messages also appear on the console and in the test execution error section of the log file, but they do not affect the status of a test case
- INFO
The default message level. By default, messages below this level are not shown in the log file
- DEBUG
Used for debugging purposes. It is useful when you need to record the internal execution process of a test library. When a keyword fails, the place where the code failed automatically prints traceback information at this level
- TRACE
A more detailed debugging level. At this level, the arguments and return values of a keyword are automatically written to the log
In a test case, you can call the built-in keyword log to output the corresponding logs:
For example:
| |
Output:
| |
The first argument is the log content, the second argument is the log level, and the default is info.
Declaring Variables
- Variables
In a test suite:
| |
In a test case:
| |
- Lists
In a test suite:
| |
In a test case:
| |
There are two ways to access a list:
- @{variable_name}[index]
- ${variable_name[index]}
- Dictionaries
In a test suite:
| |
In a test case:
| |
You can also declare a dictionary variable with the scalar sign, ${user} .
Access methods:
| |
Conditional Expressions
Syntax structure:
| |
For example:
| |
Note that keywords are not case-sensitive, but the ELSE and ELSE IF here are strictly case-sensitive.
Loop Expressions
Syntax structure:
| |
For example:
| |
Arguments and Return Values
In Robot Framework, passing arguments to a keyword or getting a return value from a keyword is a very common operation.
In a keyword definition, arguments are defined with [Arguments], and a default value can also be set as ${version}=0. An argument with a default value does not have to be passed when used; otherwise it must be passed. When passing arguments, you can use the default positional form, or the key/value form.
In a keyword definition, a value is returned with [Return].
| |
Extending Python Variables with the Variables Approach
In Robot Framework, sometimes you need to use Python to handle some logic and obtain a computed value. In this case, you can use a Variable to extend Python variables.
test.py
| |
*** Settings ***
Variables test.py
*** Test Cases ***
testCase
log ${myrand.random()} warn
Extending Python Functions as Keywords with the Library Approach
In Robot Framework, sometimes you need to use Python to wrap some operations, such as sending email. In this case, you can use the Library approach to import Python functions as keywords in Robot Framework.
mylib.py
| |
| |
