A test library providing keywords for OS related tasks.

OperatingSystem is Robot Framework's standard library that enables various operating system related tasks to be performed in the system where Robot Framework is running. It can, among other things, execute commands (e.g. Run), create and remove files and directories (e.g. Create File, Remove Directory), check whether files or directories exists or contain something (e.g. File Should Exist, Directory Should Be Empty) and manipulate environment variables (e.g. Set Environment Variable).

Table of contents

Path separators

Because Robot Framework uses the backslash (\) as an escape character in the test data, using a literal backslash requires duplicating it like in c:\\path\\file.txt. That can be inconvenient especially with longer Windows paths, and thus all keywords expecting paths as arguments convert forward slashes to backslashes automatically on Windows. This also means that paths like ${CURDIR}/path/file.txt are operating system independent.

Notice that the automatic path separator conversion does not work if the path is only a part of an argument like with Run and Start Process keywords. In these cases the built-in variable ${/} that contains \ or /, depending on the operating system, can be used instead.

Pattern matching

Some keywords allow their arguments to be specified as glob patterns where:

* matches any string, even an empty string
? matches any single character
[chars] matches one character in the bracket
[!chars] matches one character not in the bracket
[a-z] matches one character from the range in the bracket
[!a-z] matches one character not from the range in the bracket

Unless otherwise noted, matching is case-insensitive on case-insensitive operating systems such as Windows.

Tilde expansion

Paths beginning with ~ or ~username are expanded to the current or specified user's home directory, respectively. The resulting path is operating system dependent, but typically e.g. ~/robot is expanded to C:\Users\<user>\robot on Windows and /home/<user>/robot on Unixes.

The ~username form does not work on Jython.

Boolean arguments

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 an empty string or equal to FALSE, NONE, NO, OFF or 0, case-insensitively. Other strings are considered true regardless their value, and other argument types are tested using the same rules as in Python.

True examples:

Remove Directory ${path} recursive=True # Strings are generally true.
Remove Directory ${path} recursive=yes # Same as the above.
Remove Directory ${path} recursive=${TRUE} # Python True is true.
Remove Directory ${path} recursive=${42} # Numbers other than 0 are true.

False examples:

Remove Directory ${path} recursive=False # String false is false.
Remove Directory ${path} recursive=no # Also string no is false.
Remove Directory ${path} recursive=${EMPTY} # Empty string is false.
Remove Directory ${path} recursive=${FALSE} # Python False is false.

Considering OFF` and 0 false is new in Robot Framework 3.1.

Example

Setting Value
Library OperatingSystem
Variable Value
${PATH} ${CURDIR}/example.txt
Test Case Action Argument Argument
Example Create File ${PATH} Some text
File Should Exist ${PATH}
Copy File ${PATH} ~/file.txt
${output} = Run ${TEMPDIR}${/}script.py arg