Professional Documents
Culture Documents
Operatingsystem: Library Version: 3.2.2 Library Scope: Named Arguments: Supported
Operatingsystem: Library Version: 3.2.2 Library Scope: Named Arguments: Supported
Operatingsystem: Library Version: 3.2.2 Library Scope: Named Arguments: Supported
Introduction
A test library providing keywords for OS related tasks.
Table of contents
• Path separators
• Pattern matching
• Tilde expansion
• Boolean arguments
• Example
• Shortcuts
• Keywords
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:
Starting from Robot Framework 2.9.1, globbing is not done if the given path matches
an existing file even if it would contain a glob pattern.
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.
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:
False examples:
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
Shortcuts
List style: Compact Expanded
Append To Environment Variable
Append To File
Copy Directory
Copy File
Copy Files
Count Directories In Directory
Count Files In Directory
Count Items In Directory
Create Binary File
Create Directory
Create File
Directory Should Be Empty
Directory Should Exist
Directory Should Not Be Empty
Directory Should Not Exist
Empty Directory
Environment Variable Should Be Set
Environment Variable Should Not Be Set
File Should Be Empty
File Should Exist
File Should Not Be Empty
File Should Not Exist
Get Binary File
Get Environment Variable
Get Environment Variables
Get File
Get File Size
Get Modified Time
Grep File
Join Path
Join Paths
List Directories In Directory
List Directory
List Files In Directory
Log Environment Variables
Log File
Move Directory
Move File
Move Files
Normalize Path
Remove Directory
Remove Environment Variable
Remove File
Remove Files
Run
Run And Return Rc
Run And Return Rc And Output
Set Environment Variable
Set Modified Time
Should Exist
Should Not Exist
Split Extension
Split Path
Touch
Wait Until Created
Wait Until Removed
Keywords
Keywo
Arguments Documentation
rd
Appends given values to environment variable name.
If the file exists, the given text is written to its end. If the
file does not exist, it is created.
path,
Append content, Other than not overwriting possible existing files, this
To File encoding=UTF- keyword works exactly like Create File. See its
8 documentation for more details about the usage.
4) If the destination does not exist and it does not end with
a path separator, it is considered a file. If the path to the
file does not exist, it is created.
Create If the directory for the file does not exist, it is created,
path,
Binary along with missing intermediate directories.
content
File
Examples:
Examples:
Create
${dir}/example.txt Hello, world!
File
Create Hyv\xe4
${path} Latin-1
File esimerkki
Create
/tmp/foo.txt 3\nlines\nhere\n SYSTEM
File
Get
${time Modifi ${CURD
}= ed IR}
Time
Get
${secs Modifi ${CURD
epoch
}= ed IR}
Time
Get
${year Modifi ${CURD
return year
}= ed IR}
Time
Get
year,d
${y} ${d} = Modified ${CURDIR}
ay
Time
Get
@{tim Modifi ${CURD year,month,day,hour,
e} = ed IR} min,sec
Time
=>
Examples:
${errors} Grep
/var/log/myapp.log ERROR
= File
Grep [Ww]ildc??d
${ret} = ${CURDIR}/file.txt
File ex*ple
Examples:
=>
• ${path} = 'my/path'
• ${p2} = 'my/path'
• ${p3} = 'my/path/my/file.txt'
• ${p4} = '/path'
• ${p5} = '/my/path2'
=>
List
Directo path,
ries In pattern=None, Wrapper for List Directory that returns only directories.
Directo absolute=False
ry
Returns and logs items in a directory, optionally filtered
with pattern.
@{items}
List Directory ${TEMPDIR}
=
@{files} List Files In
/tmp *.txt absolute
= Directory
${count} Count Files In
${CURDIR} ???
= Directory
List
path,
Files In
pattern=None, Wrapper for List Directory that returns only files.
Directo
absolute=False
ry
Log
Logs all environment variables using the given log level.
Environ
ment level=INFO
Environment variables are also returned the same way as
Variabl
with Get Environment Variables keyword.
es
Wrapper for Get File that also logs the returned file.
path,
The file is logged with the INFO level. If you want
encoding=UTF-
Log something else, just use Get File and the built-in keyword
8,
File Log with the desired level.
encoding_errors
=strict
See Get File for more information about encoding and
encoding_errors arguments.
Moves the source directory into a destination.
Move
source,
Directo Uses Copy Directory keyword internally, and source and
destination
ry destination arguments have exactly same semantics as
with that keyword.
Moves the source file into the destination.
Examples:
=>
• ${path1} = 'abc'
• ${path2} = 'def'
• ${path3} = 'abc/def/ghi'
• ${path4} = '/home/robot/stuff'
Passes if the file does not exist, but fails if the path does
not point to a regular file (e.g. it points to a directory).
Remov
path
e File
The path can be given as an exact path or as a glob
pattern. The pattern matching syntax is explained in
introduction. If the path is a pattern, all files matching it
are removed.
Uses Remove File to remove multiple files one-by-one.
Example:
Remov
*paths
e Files
Rem
${TEMPDIR}$ ${TEMPDIR}$ ${TEMPDIR}$
ove
{/}foo.txt {/}bar.txt {/}zap.txt
Files
Runs the given command in the system and returns the
output.
Examples:
Examples:
See Run and Run And Return RC And Output if you need
to get the output of the executed command.
Examples:
Set
# Time given as
Modified /path/file 1177654467
epoch seconds
Time
Set
2007-04-27 # Time given as a
Modified /path/file
9:14:27 timestamp
Time
Set
# The local time
Modified /path/file NOW
of execution
Time
Set # 1 day subtracted
Modified /path/file NOW - 1 day from the local
Time time
Set # 1h 2min 3s
UTC + 1h
Modified /path/file added to the UTC
2min 3s
Time time
Fails unless the given path (file or directory) exists.
Examples:
=>
Splits the given path from the last path separator (/ or \).