Library version: | 2.9b2 |
---|---|
Library scope: | global |
Named arguments: | supported |
An always available standard library with often needed keywords.
BuiltIn
is Robot Framework's standard library that provides a set of generic keywords needed often. It is imported automatically and thus always available. The provided keywords can be used, for example, for verifications (e.g. Should Be Equal, Should Contain), conversions (e.g. Convert To Integer) and for various other purposes (e.g. Log, Sleep, Run Keyword If, Set Global Variable).
Many of the keywords accept an optional error message to use if the keyword fails. Starting from Robot Framework 2.8, it is possible to use HTML in these messages by prefixing them with *HTML*
. See Fail keyword for a usage example. Notice that using HTML in messages is not limited to BuiltIn library but works with any error message.
Many keywords, such as Evaluate, Run Keyword If and Should Be True, accept an expression that is evaluated in Python. These expressions are evaluated using Python's eval function so that all Python built-ins like len()
and int()
are available. Evaluate allows configuring the execution namespace with custom modules, and other keywords have os and sys modules available automatically.
Examples:
Run Keyword If | os.sep == '/' | Log | Not on Windows |
${random int} = | Evaluate | random.randint(0, 5) | modules=random |
When a variable is used in the expressing using the normal ${variable}
syntax, its value is replaces before the expression is evaluated. This means that the value used in the expression will be the string representation of the variable value, not the variable value itself. This is not a problem with numbers and other objects that have a string representation that can be evaluated directly, but with other objects the behavior depends on the string representation. Most importantly, strings must always be quoted, and if they can contain newlines, they must be triple quoted.
Examples:
Should Be True | ${rc} < 10 | Return code greater than 10 | |
Run Keyword If | '${status}' == 'PASS' | Log | Passed |
Run Keyword If | 'FAIL' in '''${output}''' | Log | Output contains FAIL |
Starting from Robot Framework 2.9, variables themselves are automatically available in the evaluation namespace. They can be accessed using special variable syntax without the curly braces like $variable
. These variables should never be quoted, and in fact they are not even replaced inside strings.
Examples:
Should Be True | $rc < 10 | Return code greater than 10 | |
Run Keyword If | $status == 'PASS' | Log | Passed |
Run Keyword If | 'FAIL' in $output | Log | Output contains FAIL |
Should Be True | len($result) > 1 and $result[1] == 'OK' |
Notice that instead of creating complicated expressions, it is often better to move the logic into a test library.
Some keywords accept arguments that are handled as Boolean values true or false. If such an argument is given as a string, it is considered false if it is either empty or case-insensitively equal to false
or no
. Keywords verifying something that allow dropping actual and expected values from the possible error message also consider string no values
as false. Other strings are considered true regardless their value, and other argument types are tested using same rules as in Python.
True examples:
Should Be Equal | ${x} | ${y} | Custom error | values=True | # Strings are generally true. |
Should Be Equal | ${x} | ${y} | Custom error | values=yes | # Same as the above. |
Should Be Equal | ${x} | ${y} | Custom error | values=${TRUE} | # Python True is true. |
Should Be Equal | ${x} | ${y} | Custom error | values=${42} | # Numbers other than 0 are true. |
False examples:
Should Be Equal | ${x} | ${y} | Custom error | values=False | # String false is false. |
Should Be Equal | ${x} | ${y} | Custom error | values=no | # Also string no is false. |
Should Be Equal | ${x} | ${y} | Custom error | values=${EMPTY} | # Empty string is false. |
Should Be Equal | ${x} | ${y} | Custom error | values=${FALSE} | # Python False is false. |
Should Be Equal | ${x} | ${y} | Custom error | values=no values | # no values works with values argument |
Note that prior to Robot Framework 2.9 some keywords considered all non-empty strings, including false
and no
, to be true.
Keyword | Arguments | Documentation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Call Method | object, method_name, *args, **kwargs | Calls the named method of the given object with the provided arguments. The possible return value from the method is returned and can be assigned to a variable. Keyword fails both if the object does not have a method with the given name or if executing the method raises an exception. Support for Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Catenate | *items | Catenates the given items together and returns the resulted string. By default, items are catenated with spaces, but if the first item contains the string Examples:
=> ${str1} = 'Hello world' ${str2} = 'Hello---world' ${str3} = 'Helloworld' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment | *messages | Displays the given messages in the log file as keyword arguments. This keyword does nothing with the arguments it receives, but as they are visible in the log, this keyword can be used to display simple messages. Given arguments are ignored so thoroughly that they can even contain non-existing variables. If you are interested about variable values, you can use the Log or Log Many keywords. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Continue For Loop | Skips the current for loop iteration and continues from the next. Skips the remaining keywords in the current for loop iteration and continues from the next one. Can be used directly in a for loop or in a keyword that the loop uses. Example:
See Continue For Loop If to conditionally continue a for loop without using Run Keyword If or other wrapper keywords. New in Robot Framework 2.8. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Continue For Loop If | condition | Skips the current for loop iteration if the A wrapper for Continue For Loop to continue a for loop based on the given condition. The condition is evaluated using the same semantics as with Should Be True keyword. Example:
New in Robot Framework 2.8. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To Binary | item, base=None, prefix=None, length=None | Converts the given item to a binary string. The The returned value can contain an optional Examples:
See also Convert To Integer, Convert To Octal and Convert To Hex. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To Boolean | item | Converts the given item to Boolean true or false. Handles strings | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To Bytes | input, input_type=text | Converts the given Valid input types are listed below:
In addition to giving the input as a string, it is possible to use lists or other iterables containing individual characters or numbers. In that case numbers do not need to be padded to certain length and they cannot contain extra spaces. Examples (last column shows returned bytes):
Use Encode String To Bytes in New in Robot Framework 2.8.2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To Hex | item, base=None, prefix=None, length=None, lowercase=False | Converts the given item to a hexadecimal string. The The returned value can contain an optional By default the value is returned as an upper case string, but the Examples:
See also Convert To Integer, Convert To Binary and Convert To Octal. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To Integer | item, base=None | Converts the given item to an integer number. If the given item is a string, it is by default expected to be an integer in base 10. There are two ways to convert from other bases:
The syntax is case-insensitive and possible spaces are ignored. Examples:
See also Convert To Number, Convert To Binary, Convert To Octal, Convert To Hex, and Convert To Bytes. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To Number | item, precision=None | Converts the given item to a floating point number. If the optional Examples:
Notice that machines generally cannot store floating point numbers accurately. This may cause surprises with these numbers in general and also when they are rounded. For more information see, for example, these resources:
If you need an integer number, use Convert To Integer instead. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To Octal | item, base=None, prefix=None, length=None | Converts the given item to an octal string. The The returned value can contain an optional Examples:
See also Convert To Integer, Convert To Binary and Convert To Hex. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Convert To String | item | Converts the given item to a Unicode string. Uses Use Encode String To Bytes and Decode Bytes To String keywords in | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Create Dictionary | *items | Creates and returns a dictionary based on given items. Items are given using If same key is used multiple times, the last value has precedence. The returned dictionary is ordered, and values with strings as keys can also be accessed using convenient dot-access syntax like Examples:
This keyword was changed in Robot Framework 2.9 in many ways:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Create List | *items | Returns a list containing given items. The returned list can be assigned both to Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Evaluate | expression, modules=None, namespace=None | Evaluates the given expression in Python and returns the results.
Variables used like Examples (expecting
=> ${status} = True ${random} = <random integer> ${result} = 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Exit For Loop | Stops executing the enclosing for loop. Exits the enclosing for loop and continues execution after it. Can be used directly in a for loop or in a keyword that the loop uses. Example:
See Exit For Loop If to conditionally exit a for loop without using Run Keyword If or other wrapper keywords. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Exit For Loop If | condition | Stops executing the enclosing for loop if the A wrapper for Exit For Loop to exit a for loop based on the given condition. The condition is evaluated using the same semantics as with Should Be True keyword. Example:
New in Robot Framework 2.8. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fail | msg=None, *tags | Fails the test with the given message and optionally alters its tags. The error message is specified using the It is possible to modify tags of the current test case by passing tags after the message. Tags starting with a hyphen (e.g. Examples:
See Fatal Error if you need to stop the whole test execution. Support for modifying tags was added in Robot Framework 2.7.4 and HTML message support in 2.8. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Fatal Error | msg=None | Stops the whole test execution. The test or suite where this keyword is used fails with the provided message, and subsequent tests fail with a canned message. Possible teardowns will nevertheless be executed. See Fail if you only want to stop one test case unconditionally. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Count | item1, item2 | Returns and logs how many times This keyword works with Python strings and lists and all objects that either have Example:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Length | item | Returns and logs the length of the given item as an integer. The item can be anything that has a length, for example, a string, a list, or a mapping. The keyword first tries to get the length with the Python function Examples:
See also Length Should Be, Should Be Empty and Should Not Be Empty. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Library Instance | name | Returns the currently active instance of the specified test library. This keyword makes it easy for test libraries to interact with other test libraries that have state. This is illustrated by the Python example below: from robot.libraries.BuiltIn import BuiltIn def title_should_start_with(expected): seleniumlib = BuiltIn().get_library_instance('SeleniumLibrary') title = seleniumlib.get_title() if not title.startswith(expected): raise AssertionError("Title '%s' did not start with '%s'" % (title, expected)) It is also possible to use this keyword in the test data and pass the returned library instance to another keyword. If a library is imported with a custom name, the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Time | format=timestamp, time_=NOW | Returns the given time in the requested format. NOTE: DateTime library added in Robot Framework 2.8.5 contains much more flexible keywords for getting the current date and time and for date and time handling in general. How time is returned is determined based on the given 1) If 2) If 3) Otherwise (and by default) the time is returned as a timestamp string in the format By default this keyword returns the current local time, but that can be altered using 1) If 2) If 3) If 4) If 5) If Examples (expecting the current local time is 2006-03-29 15:06:21):
=> ${time} = '2006-03-29 15:06:21' ${secs} = 1143637581 ${year} = '2006' ${yyyy} = '2006', ${mm} = '03', ${dd} = '29' @{time} = ['2006', '03', '29', '15', '06', '21'] ${y} = '2006' ${s} = '21' Examples (expecting the current local time is 2006-03-29 15:06:21 and UTC time is 2006-03-29 12:06:21):
=> ${time} = '2007-04-27 09:14:27' ${secs} = 27 ${year} = '2006' @{time} = ['16', '08', '24'] @{utc} = ['12', '06', '21'] ${hour} = '11' Support for UTC time was added in Robot Framework 2.7.5 but it did not work correctly until 2.7.7. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Variable Value | name, default=None | Returns variable value or The name of the variable can be given either as a normal variable name (e.g. Examples:
=> ${x} gets value of ${a} if ${a} exists and string 'default' otherwise ${y} gets value of ${a} if ${a} exists and value of ${b} otherwise ${z} is set to Python None if it does not exist previously See Set Variable If for another keyword to set variables dynamically. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Get Variables | no_decoration=False | Returns a dictionary containing all variables in the current scope. Variables are returned as a special dictionary that allows accessing variables in space, case, and underscore insensitive manner similarly as accessing variables in the test data. This dictionary supports all same operations as normal Python dictionaries and, for example, Collections library can be used to access or modify it. Modifying the returned dictionary has no effect on the variables available in the current scope. By default variables are returned with Example:
Note: Prior to Robot Framework 2.7.4 variables were returned as a custom object that did not support all dictionary methods. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Import Library | name, *args | Imports a library with the given name and optional arguments. This functionality allows dynamic importing of libraries while tests are running. That may be necessary, if the library itself is dynamic and not yet available when test data is processed. In a normal case, libraries should be imported using the Library setting in the Setting table. This keyword supports importing libraries both using library names and physical paths. When paths are used, they must be given in absolute format. Forward slashes can be used as path separators in all operating systems. It is possible to pass arguments to the imported library and also named argument syntax works if the library supports it. Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Import Resource | path | Imports a resource file with the given path. Resources imported with this keyword are set into the test suite scope similarly when importing them in the Setting table using the Resource setting. The given path must be absolute. Forward slashes can be used as path separator regardless the operating system. Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Import Variables | path, *args | Imports a variable file with the given path and optional arguments. Variables imported with this keyword are set into the test suite scope similarly when importing them in the Setting table using the Variables setting. These variables override possible existing variables with the same names. This functionality can thus be used to import new variables, for example, for each test in a test suite. The given path must be absolute. Forward slashes can be used as path separator regardless the operating system. Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Keyword Should Exist | name, msg=None | Fails unless the given keyword exists in the current scope. Fails also if there are more than one keywords with the same name. Works both with the short name (e.g. The default error message can be overridden with the See also Variable Should Exist. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Length Should Be | item, length, msg=None | Verifies that the length of the given item is correct. The length of the item is got using the Get Length keyword. The default error message can be overridden with the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Log | message, level=INFO, html=False, console=False, repr=False | Logs the given message with the given level. Valid levels are TRACE, DEBUG, INFO (default), HTML, WARN, and ERROR. Messages below the current active log level are ignored. See Set Log Level keyword and Messages logged with the WARN or ERROR levels will be automatically visible also in the console and in the Test Execution Errors section in the log file. Logging can be configured using optional If the If the If the Examples:
See Log Many if you want to log multiple messages in one go, and Log To Console if you only want to write to the console. Arguments Pprint support when | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Log Many | *messages | Logs the given messages as separate entries using the INFO level. Supports also logging list and dictionary variable items individually. Examples:
See Log and Log To Console keywords if you want to use alternative log levels, use HTML, or log to the console. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Log To Console | message, stream=STDOUT, no_newline=False | Logs the given message to the console. By default uses the standard output stream. Using the standard error stream is possibly by giving the By default appends a newline to the logged message. This can be disabled by giving the Examples:
This keyword does not log the message to the normal log file. Use Log keyword, possibly with argument New in Robot Framework 2.8.2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Log Variables | level=INFO | Logs all variables in the current scope with given log level. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
No Operation | Does absolutely nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Pass Execution | message, *tags | Skips rest of the current test, setup, or teardown with PASS status. This keyword can be used anywhere in the test data, but the place where used affects the behavior:
Possible continuable failures before this keyword is used, as well as failures in executed teardowns, will fail the execution. It is mandatory to give a message explaining why execution was passed. By default the message is considered plain text, but starting it with It is also possible to modify test tags passing tags after the message similarly as with Fail keyword. Tags starting with a hyphen (e.g. Examples:
This keyword is typically wrapped to some other keyword, such as Run Keyword If, to pass based on a condition. The most common case can be handled also with Pass Execution If:
Passing execution in the middle of a test, setup or teardown should be used with care. In the worst case it leads to tests that skip all the parts that could actually uncover problems in the tested application. In cases where execution cannot continue do to external factors, it is often safer to fail the test case and make it non-critical. New in Robot Framework 2.8. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Pass Execution If | condition, message, *tags | Conditionally skips rest of the current test, setup, or teardown with PASS status. A wrapper for Pass Execution to skip rest of the current test, setup or teardown based the given Example:
New in Robot Framework 2.8. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Regexp Escape | *patterns | Returns each argument string escaped for use as a regular expression. This keyword can be used to escape strings to be used with Should Match Regexp and Should Not Match Regexp keywords. Escaping is done with Python's Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Reload Library | name_or_instance | Rechecks what keywords the specified library provides. Can be called explicitly in the test data or by a library itself when keywords it provides have changed. The library can be specified by its name or as the active instance of the library. The latter is especially useful if the library itself calls this keyword as a method. New in Robot Framework 2.9. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Remove Tags | *tags | Removes given Tags can be given exactly or using a pattern where This keyword can affect either one test case or all test cases in a test suite similarly as Set Tags keyword. The current tags are available as a built-in variable Example:
See Set Tags if you want to add certain tags and Fail if you want to fail the test case after setting and/or removing tags. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Repeat Keyword | times, name, *args | Executes the specified keyword multiple times.
If Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Replace Variables | text | Replaces variables in the given text with their current values. If the text contains undefined variables, this keyword fails. If the given Example: The file
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Return From Keyword | *return_values | Returns from the enclosing user keyword. This keyword can be used to return from a user keyword with PASS status without executing it fully. It is also possible to return values similarly as with the This keyword is typically wrapped to some other keyword, such as Run Keyword If or Run Keyword If Test Passed, to return based on a condition:
It is possible to use this keyword to return from a keyword also inside a for loop. That, as well as returning values, is demonstrated by the Find Index keyword in the following somewhat advanced example. Notice that it is often a good idea to move this kind of complicated logic into a test library. *** Variables *** @{LIST} = foo baz *** Test Cases *** Example ${index} = Find Index baz @{LIST} Should Be Equal ${index} ${1} ${index} = Find Index non existing @{LIST} Should Be Equal ${index} ${-1} *** Keywords *** Find Index [Arguments] ${element} @{items} ${index} = Set Variable ${0} :FOR ${item} IN @{items} \ Run Keyword If '${item}' == '${element}' Return From Keyword ${index} \ ${index} = Set Variable ${index + 1} Return From Keyword ${-1} # Also [Return] would work here. The most common use case, returning based on an expression, can be accomplished directly with Return From Keyword If. Both of these keywords are new in Robot Framework 2.8. See also Run Keyword And Return and Run Keyword And Return If. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Return From Keyword If | condition, *return_values | Returns from the enclosing user keyword if A wrapper for Return From Keyword to return based on the given condition. The condition is evaluated using the same semantics as with Should Be True keyword. Given the same example as in Return From Keyword, we can rewrite the Find Index keyword as follows: *** Keywords *** Find Index [Arguments] ${element} @{items} ${index} = Set Variable ${0} :FOR ${item} IN @{items} \ Return From Keyword If '${item}' == '${element}' ${index} \ ${index} = Set Variable ${index + 1} Return From Keyword ${-1} # Also [Return] would work here. See also Run Keyword And Return and Run Keyword And Return If. New in Robot Framework 2.8. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword | name, *args | Executes the given keyword with the given arguments. Because the name of the keyword to execute is given as an argument, it can be a variable and thus set dynamically, e.g. from a return value of another keyword or from the command line. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword And Continue On Failure | name, *args | Runs the keyword and continues execution even if a failure occurs. The keyword name and arguments work as with Run Keyword. Example:
The execution is not continued if the failure is caused by invalid syntax, timeout, or fatal exception. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword And Expect Error | expected_error, name, *args | Runs the keyword and checks that the expected error occurred. The expected error must be given in the same format as in Robot Framework reports. It can be a pattern containing characters If the expected error occurs, the error message is returned and it can be further processed/tested, if needed. If there is no error, or the error does not match the expected error, this keyword fails. Examples:
Errors caused by invalid syntax, timeouts, or fatal exceptions are not caught by this keyword. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword And Ignore Error | name, *args | Runs the given keyword with the given arguments and ignores possible error. This keyword returns two values, so that the first is either string The keyword name and arguments work as in Run Keyword. See Run Keyword If for a usage example. Errors caused by invalid syntax, timeouts, or fatal exceptions are not caught by this keyword. Otherwise this keyword itself never fails. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword And Return | name, *args | Runs the specified keyword and returns from the enclosing user keyword. The keyword to execute is defined with Example:
Use Run Keyword And Return If if you want to run keyword and return based on a condition. New in Robot Framework 2.8.2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword And Return If | condition, name, *args | Runs the specified keyword and returns from the enclosing user keyword. A wrapper for Run Keyword And Return to run and return based on the given Example:
Use Return From Keyword If if you want to return a certain value based on a condition. New in Robot Framework 2.8.2. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword And Return Status | name, *args | Runs the given keyword with given arguments and returns the status as a Boolean value. This keyword returns Boolean The keyword name and arguments work as in Run Keyword. Example:
Errors caused by invalid syntax, timeouts, or fatal exceptions are not caught by this keyword. Otherwise this keyword itself never fails. New in Robot Framework 2.7.6. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If | condition, name, *args | Runs the given keyword with the given arguments, if The given Example, a simple if/else construct:
In this example, only either Some Action or Another Action is executed, based on the status of My Keyword. Instead of Run Keyword And Ignore Error you can also use Run Keyword And Return Status. Variables used like Example:
Starting from Robot version 2.7.4, this keyword supports also optional ELSE and ELSE IF branches. Both of these are defined in Given previous example, if/else construct can also be created like this:
The return value is the one of the keyword that was executed or None if no keyword was executed (i.e. if
In this example, ${var2} will be set to None if ${condition} is false. Notice that Starting from Robot Framework 2.8, Python's os and sys modules are automatically imported when evaluating the
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If All Critical Tests Passed | name, *args | Runs the given keyword with the given arguments, if all critical tests passed. This keyword can only be used in suite teardown. Trying to use it in any other place will result in an error. Otherwise, this keyword works exactly like Run Keyword, see its documentation for more details. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If All Tests Passed | name, *args | Runs the given keyword with the given arguments, if all tests passed. This keyword can only be used in a suite teardown. Trying to use it anywhere else results in an error. Otherwise, this keyword works exactly like Run Keyword, see its documentation for more details. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If Any Critical Tests Failed | name, *args | Runs the given keyword with the given arguments, if any critical tests failed. This keyword can only be used in a suite teardown. Trying to use it anywhere else results in an error. Otherwise, this keyword works exactly like Run Keyword, see its documentation for more details. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If Any Tests Failed | name, *args | Runs the given keyword with the given arguments, if one or more tests failed. This keyword can only be used in a suite teardown. Trying to use it anywhere else results in an error. Otherwise, this keyword works exactly like Run Keyword, see its documentation for more details. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If Test Failed | name, *args | Runs the given keyword with the given arguments, if the test failed. This keyword can only be used in a test teardown. Trying to use it anywhere else results in an error. Otherwise, this keyword works exactly like Run Keyword, see its documentation for more details. Prior to Robot Framework 2.9 failures in test teardown itself were not detected by this keyword. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If Test Passed | name, *args | Runs the given keyword with the given arguments, if the test passed. This keyword can only be used in a test teardown. Trying to use it anywhere else results in an error. Otherwise, this keyword works exactly like Run Keyword, see its documentation for more details. Prior to Robot Framework 2.9 failures in test teardown itself were not detected by this keyword. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword If Timeout Occurred | name, *args | Runs the given keyword if either a test or a keyword timeout has occurred. This keyword can only be used in a test teardown. Trying to use it anywhere else results in an error. Otherwise, this keyword works exactly like Run Keyword, see its documentation for more details. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keyword Unless | condition, name, *args | Runs the given keyword with the given arguments, if See Run Keyword If for more information and an example. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Run Keywords | *keywords | Executes all the given keywords in a sequence. This keyword is mainly useful in setups and teardowns when they need to take care of multiple actions and creating a new higher level user keyword would be an overkill. Examples:
In this example, we call Run Keywords with three different combination of arguments. Keyword names and arguments can come from variables, as demonstrated in the second and third row. Starting from Robot Framework 2.7.6, keywords can also be run with arguments using upper case Examples:
Notice that the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Global Variable | name, *values | Makes a variable available globally in all tests and suites. Variables set with this keyword are globally available in all test cases and suites executed after setting them. Setting variables with this keyword thus has the same effect as creating from the command line using the options See Set Suite Variable for more information and examples. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Library Search Order | *search_order | Sets the resolution order to use when a name matches multiple keywords. The library search order is used to resolve conflicts when a keyword name in the test data matches multiple keywords. The first library (or resource, see below) containing the keyword is selected and that keyword implementation used. If the keyword is not found from any library (or resource), test executing fails the same way as when the search order is not set. When this keyword is used, there is no need to use the long
you can have
This keyword can be used also to set the order of keywords in different resource files. In this case resource names must be given without paths or extensions like:
NOTE:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Log Level | level | Sets the log threshold to the specified level and returns the old level. Messages below the level will not logged. The default logging level is INFO, but it can be overridden with the command line option The available levels: TRACE, DEBUG, INFO (default), WARN, ERROR and NONE (no logging). | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Suite Documentation | doc, append=False, top=False | Sets documentation for the current test suite. By default the possible existing documentation is overwritten, but this can be changed using the optional This keyword sets the documentation of the current suite by default. If the optional The documentation of the current suite is available as a built-in variable New in Robot Framework 2.7. Support for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Suite Metadata | name, value, append=False, top=False | Sets metadata for the current test suite. By default possible existing metadata values are overwritten, but this can be changed using the optional This keyword sets the metadata of the current suite by default. If the optional The metadata of the current suite is available as a built-in variable New in Robot Framework 2.7.4. Support for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Suite Variable | name, *values | Makes a variable available everywhere within the scope of the current suite. Variables set with this keyword are available everywhere within the scope of the currently executed test suite. Setting variables with this keyword thus has the same effect as creating them using the Variable table in the test data file or importing them from variable files. Possible child test suites do not see variables set with this keyword by default. Starting from Robot Framework 2.9, that can be controlled by using The name of the variable can be given either as a normal variable name (e.g. If a variable already exists within the new scope, its value will be overwritten. Otherwise a new variable is created. If a variable already exists within the current scope, the value can be left empty and the variable within the new scope gets the value within the current scope. Examples:
To override an existing value with an empty value, use built-in variables
NOTE: If the variable has value which itself is a variable (escaped or not), you must always use the escaped format to set the variable: Example:
This limitation applies also to Set Test Variable, Set Global Variable, Variable Should Exist, Variable Should Not Exist and Get Variable Value keywords. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Tags | *tags | Adds given When this keyword is used inside a test case, that test gets the specified tags and other tests are not affected. If this keyword is used in a suite setup, all test cases in that suite, recursively, gets the given tags. It is a failure to use this keyword in a suite teardown. The current tags are available as a built-in variable See Remove Tags if you want to remove certain tags and Fail if you want to fail the test case after setting and/or removing tags. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Test Documentation | doc, append=False | Sets documentation for the current test case. By default the possible existing documentation is overwritten, but this can be changed using the optional The current test documentation is available as a built-in variable New in Robot Framework 2.7. Support for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Test Message | message, append=False | Sets message for the current test case. If the optional In test teardown this keyword can alter the possible failure message, but otherwise failures override messages set by this keyword. Notice that in teardown the initial message is available as a built-in variable It is possible to use HTML format in the message by starting the message with Examples:
This keyword can not be used in suite setup or suite teardown. Support for | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Test Variable | name, *values | Makes a variable available everywhere within the scope of the current test. Variables set with this keyword are available everywhere within the scope of the currently executed test case. For example, if you set a variable in a user keyword, it is available both in the test case level and also in all other user keywords used in the current test. Other test cases will not see variables set with this keyword. See Set Suite Variable for more information and examples. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Variable | *values | Returns the given values which can then be assigned to a variables. This keyword is mainly used for setting scalar variables. Additionally it can be used for converting a scalar variable containing a list to a list variable or to multiple scalar variables. It is recommended to use Create List when creating new lists. Examples:
Variables created with this keyword are available only in the scope where they are created. See Set Global Variable, Set Test Variable and Set Suite Variable for information on how to set variables so that they are available also in a larger scope. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Set Variable If | condition, *values | Sets variable based on the given condition. The basic usage is giving a condition and two values. The given condition is first evaluated the same way as with the Should Be True keyword. If the condition is true, then the first value is returned, and otherwise the second value is returned. The second value can also be omitted, in which case it has a default value None. This usage is illustrated in the examples below, where
=> ${var1} = 'zero' ${var2} = 'value2' ${var3} = None It is also possible to have 'else if' support by replacing the second value with another condition, and having two new values after it. If the first condition is not true, the second is evaluated and one of the values after it is returned based on its truth value. This can be continued by adding more conditions without a limit.
Use Get Variable Value if you need to set variables dynamically based on whether a variable exist or not. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Be Empty | item, msg=None | Verifies that the given item is empty. The length of the item is got using the Get Length keyword. The default error message can be overridden with the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Be Equal | first, second, msg=None, values=True | Fails if the given objects are unequal. Optional
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Be Equal As Integers | first, second, msg=None, values=True, base=None | Fails if objects are unequal after converting them to integers. See Convert To Integer for information how to convert integers from other bases than 10 using See Should Be Equal for an explanation on how to override the default error message with Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Be Equal As Numbers | first, second, msg=None, values=True, precision=6 | Fails if objects are unequal after converting them to real numbers. The conversion is done with Convert To Number keyword using the given Examples:
As discussed in the documentation of Convert To Number, machines generally cannot store floating point numbers accurately. Because of this limitation, comparing floats for equality is problematic and a correct approach to use depends on the context. This keyword uses a very naive approach of rounding the numbers before comparing them, which is both prone to rounding errors and does not work very well if numbers are really big or small. For more information about comparing floats, and ideas on how to implement your own context specific comparison algorithm, see http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/. See Should Not Be Equal As Numbers for a negative version of this keyword and Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Be Equal As Strings | first, second, msg=None, values=True | Fails if objects are unequal after converting them to strings. See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Be True | condition, msg=None | Fails if the given condition is not true. If The default error message ( Examples:
Variables used like Examples:
Starting from Robot Framework 2.8, Should Be True automatically imports Python's os and sys modules that contain several useful attributes:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Contain | item1, item2, msg=None, values=True | Fails if Works with strings, lists, and anything that supports Python's Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Contain X Times | item1, item2, count, msg=None | Fails if Works with strings, lists and all objects that Get Count works with. The default error message can be overridden with Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should End With | str1, str2, msg=None, values=True | Fails if the string See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Match | string, pattern, msg=None, values=True | Fails unless the given Pattern matching is similar as matching files in a shell, and it is always case-sensitive. In the pattern, See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Match Regexp | string, pattern, msg=None, values=True | Fails if Regular expression check is implemented using the Python re module. Python's regular expression syntax is derived from Perl, and it is thus also very similar to the syntax used, for example, in Java, Ruby and .NET. Things to note about the regexp syntax in Robot Framework test data: 1) Backslash is an escape character in the test data, and possible backslashes in the pattern must thus be escaped with another backslash (e.g. 2) Strings that may contain special characters, but should be handled as literal strings, can be escaped with the Regexp Escape keyword. 3) The given pattern does not need to match the whole string. For example, the pattern 4) Possible flags altering how the expression is parsed (e.g. If this keyword passes, it returns the portion of the string that matched the pattern. Additionally, the possible captured groups are returned. See the Should Be Equal keyword for an explanation on how to override the default error message with the Examples:
=> ${ret} = 'Foo: 42' ${match} = 'Bar: 43' ${group1} = 'Bar' ${group2} = '43' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Be Empty | item, msg=None | Verifies that the given item is not empty. The length of the item is got using the Get Length keyword. The default error message can be overridden with the | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Be Equal | first, second, msg=None, values=True | Fails if the given objects are equal. See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Be Equal As Integers | first, second, msg=None, values=True, base=None | Fails if objects are equal after converting them to integers. See Convert To Integer for information how to convert integers from other bases than 10 using See Should Be Equal for an explanation on how to override the default error message with See Should Be Equal As Integers for some usage examples. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Be Equal As Numbers | first, second, msg=None, values=True, precision=6 | Fails if objects are equal after converting them to real numbers. The conversion is done with Convert To Number keyword using the given See Should Be Equal As Numbers for examples on how to use | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Be Equal As Strings | first, second, msg=None, values=True | Fails if objects are equal after converting them to strings. See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Be True | condition, msg=None | Fails if the given condition is true. See Should Be True for details about how | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Contain | item1, item2, msg=None, values=True | Fails if Works with strings, lists, and anything that supports Python's Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not End With | str1, str2, msg=None, values=True | Fails if the string See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Match | string, pattern, msg=None, values=True | Fails if the given Pattern matching is similar as matching files in a shell, and it is always case-sensitive. In the pattern See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Match Regexp | string, pattern, msg=None, values=True | Fails if See Should Match Regexp for more information about arguments. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Not Start With | str1, str2, msg=None, values=True | Fails if the string See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Should Start With | str1, str2, msg=None, values=True | Fails if the string See Should Be Equal for an explanation on how to override the default error message with | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Sleep | time_, reason=None | Pauses the test executed for the given time.
Examples:
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variable Should Exist | name, msg=None | Fails unless the given variable exists within the current scope. The name of the variable can be given either as a normal variable name (e.g. The default error message can be overridden with the See also Variable Should Not Exist and Keyword Should Exist. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Variable Should Not Exist | name, msg=None | Fails if the given variable exists within the current scope. The name of the variable can be given either as a normal variable name (e.g. The default error message can be overridden with the See also Variable Should Exist and Keyword Should Exist. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Wait Until Keyword Succeeds | retry, retry_interval, name, *args | Runs the specified keyword and retries if it fails.
If If the keyword does not succeed regardless of retries, this keyword fails. If the executed keyword passes, its return value is returned. Examples:
All normal failures are caught by this keyword. Errors caused by invalid syntax, test or keyword timeouts, or fatal exceptions (caused e.g. by Fatal Error) are not caught. Running the same keyword multiple times inside this keyword can create lots of output and considerably increase the size of the generated output files. Starting from Robot Framework 2.7, it is possible to remove unnecessary keywords from the outputs using Support for specifying |