RobotFramework之OperatingSystem
时间: 2018-08-15来源:OSCHINA
前景提要
「深度学习福利」大神带你进阶工程师,立即查看>>>
OperatingSystem
Library version: 3.0.4
Library scope: global
Named arguments: supported

Introduction
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 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:
* matches anything, even an empty string
? matches any single character
[chars] [!chars]
matches any character inside square brackets (e.g. [abc] matches either a , b or c ) matches any character not inside square brackets

Unless otherwise noted, matching is case-insensitive on case-insensitive operating systems such as Windows. Pattern matching is implemented using fnmatch module .
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: