2019独角兽企业重金招聘Python工程师标准>>>
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] |
matches any character inside square brackets (e.g. [abc] matches either a , b or c ) |
[!chars] |
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:\Users\
on Windows and /home/
on Unixes.
Tilde expansion is a new feature in Robot Framework 2.8. 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 either an empty string or case-insensitively equal to false
, none
or no
. 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. |
Prior to Robot Framework 2.9, all non-empty strings, including false
and no
, were considered true. Considering none
false is new in Robot Framework 3.0.3.
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
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
Keyword | Arguments | Documentation | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Append To Environment Variable | name, *values, **config | Appends given If the environment variable already exists, values are added after it, and otherwise a new environment variable is created. Values are, by default, joined together using the operating system path separator ( Examples (assuming
New in Robot Framework 2.8.4. |
||||||||||||||||||||||||||||||||
Append To File | path, content,encoding=UTF-8 | Appends the given content to the specified file. If the file does not exists, this keyword works exactly the same way as Create File. |
||||||||||||||||||||||||||||||||
Copy Directory | source, destination | Copies the source directory into the destination. If the destination exists, the source is copied under it. Otherwise the destination directory and the possible missing intermediate directories are created. |
||||||||||||||||||||||||||||||||
Copy File | source, destination | Copies the source file into the destination. Source must be an existing file. Starting from Robot Framework 2.8.4, it can be given as a glob pattern (see Pattern matching) that matches exactly one file. How the destination is interpreted is explained below. 1) If the destination is an existing file, the source file is copied over it. 2) If the destination is an existing directory, the source file is copied into it. A possible file with the same name as the source is overwritten. 3) If the destination does not exist and it ends with a path separator ( 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. The resulting destination path is returned since Robot Framework 2.9.2. See also Copy Files, Move File, and Move Files. |
||||||||||||||||||||||||||||||||
Copy Files | *sources_and_destination | Copies specified files to the target directory. Source files can be given as exact paths and as glob patterns (see Pattern matching). At least one source must be given, but it is not an error if it is a pattern that does not match anything. Last argument must be the destination directory. If the destination does not exist, it will be created. Examples:
See also Copy File, Move File, and Move Files. New in Robot Framework 2.8.4. |
||||||||||||||||||||||||||||||||
Count Directories In Directory | path, pattern=None | Wrapper for Count Items In Directory returning only directory count. |
||||||||||||||||||||||||||||||||
Count Files In Directory | path, pattern=None | Wrapper for Count Items In Directory returning only file count. |
||||||||||||||||||||||||||||||||
Count Items In Directory | path, pattern=None | Returns and logs the number of all items in the given directory. The argument |
||||||||||||||||||||||||||||||||
Create Binary File | path, content | Creates a binary file with the given content. If content is given as a Unicode string, it is first converted to bytes character by character. All characters with ordinal below 256 can be used and are converted to bytes with same values. Using characters with higher ordinal is an error. Byte strings, and possible other types, are written to the file as is. If the directory for the file does not exist, it is created, along with missing intermediate directories. Examples:
Use Create File if you want to create a text file using a certain encoding. File Should Not Exist can be used to avoid overwriting existing files. New in Robot Framework 2.8.5. |
||||||||||||||||||||||||||||||||
Create Directory | path | Creates the specified directory. Also possible intermediate directories are created. Passes if the directory already exists, but fails if the path exists and is not a directory. |
||||||||||||||||||||||||||||||||
Create File | path, content=,encoding=UTF-8 | Creates a file with the given content and encoding. If the directory for the file does not exist, it is created, along with missing intermediate directories. See Get File for more information about possible Examples:
Use Append To File if you want to append to an existing file and Create Binary File if you need to write bytes without encoding. File Should Not Exist can be used to avoid overwriting existing files. The support for |
||||||||||||||||||||||||||||||||
Directory Should Be Empty | path, msg=None | Fails unless the specified directory is empty. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Directory Should Exist | path, msg=None | Fails unless the given path points to an existing directory. The path can be given as an exact path or as a glob pattern. The pattern matching syntax is explained in introduction. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Directory Should Not Be Empty | path, msg=None | Fails if the specified directory is empty. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Directory Should Not Exist | path, msg=None | Fails if the given path points to an existing file. The path can be given as an exact path or as a glob pattern. The pattern matching syntax is explained in introduction. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Empty Directory | path | Deletes all the content from the given directory. Deletes both files and sub-directories, but the specified directory itself if not removed. Use Remove Directory if you want to remove the whole directory. |
||||||||||||||||||||||||||||||||
Environment Variable Should Be Set | name, msg=None | Fails if the specified environment variable is not set. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Environment Variable Should Not Be Set | name, msg=None | Fails if the specified environment variable is set. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
File Should Be Empty | path, msg=None | Fails unless the specified file is empty. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
File Should Exist | path, msg=None | Fails unless the given The path can be given as an exact path or as a glob pattern. The pattern matching syntax is explained in introduction. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
File Should Not Be Empty | path, msg=None | Fails if the specified directory is empty. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
File Should Not Exist | path, msg=None | Fails if the given path points to an existing file. The path can be given as an exact path or as a glob pattern. The pattern matching syntax is explained in introduction. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Get Binary File | path | Returns the contents of a specified file. This keyword reads the specified file and returns the contents as is. See also Get File. |
||||||||||||||||||||||||||||||||
Get Environment Variable | name, default=None | Returns the value of an environment variable with the given name. If no such environment variable is set, returns the default value, if given. Otherwise fails the test case. Starting from Robot Framework 2.7, returned variables are automatically decoded to Unicode using the system encoding. Note that you can also access environment variables directly using the variable syntax |
||||||||||||||||||||||||||||||||
Get Environment Variables | Returns currently available environment variables as a dictionary. Both keys and values are decoded to Unicode using the system encoding. Altering the returned dictionary has no effect on the actual environment variables. New in Robot Framework 2.7. |
|||||||||||||||||||||||||||||||||
Get File | path, encoding=UTF-8,encoding_errors=strict | Returns the contents of a specified file. This keyword reads the specified file and returns the contents. Line breaks in content are converted to platform independent form. See also Get Binary File.
|
||||||||||||||||||||||||||||||||
Get File Size | path | Returns and logs file size as an integer in bytes. |
||||||||||||||||||||||||||||||||
Get Modified Time | path, format=timestamp | Returns the last modification time of a file or directory. 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 Examples (when the modified time of
=>
|
||||||||||||||||||||||||||||||||
Grep File | path, pattern,encoding=UTF-8,encoding_errors=strict | Returns the lines of the specified file that match the This keyword reads a file from the file system using the defined A line matches if it contains the Examples:
If more complex pattern matching is needed, it is possible to use Get File in combination with String library keywords like Get Lines Matching Regexp.
|
||||||||||||||||||||||||||||||||
Join Path | base, *parts | Joins the given path part(s) to the given base path. The path separator ( Examples:
=>
|
||||||||||||||||||||||||||||||||
Join Paths | base, *paths | Joins given paths with base and returns resulted paths. See Join Path for more information. Examples:
=>
|
||||||||||||||||||||||||||||||||
List Directories In Directory | path, pattern=None,absolute=False | Wrapper for List Directory that returns only directories. |
||||||||||||||||||||||||||||||||
List Directory | path, pattern=None,absolute=False | Returns and logs items in a directory, optionally filtered with File and directory names are returned in case-sensitive alphabetical order, e.g. File and directory names are returned relative to the given path (e.g. If Examples (using also other List Directory variants):
|
||||||||||||||||||||||||||||||||
List Files In Directory | path, pattern=None,absolute=False | Wrapper for List Directory that returns only files. |
||||||||||||||||||||||||||||||||
Log Environment Variables | level=INFO | Logs all environment variables using the given log level. Environment variables are also returned the same way as with Get Environment Variables keyword. New in Robot Framework 2.7. |
||||||||||||||||||||||||||||||||
Log File | path, encoding=UTF-8,encoding_errors=strict | Wrapper for Get File that also logs the returned file. The file is logged with the INFO level. If you want something else, just use Get File and the built-in keyword Log with the desired level. See Get File for more information about
|
||||||||||||||||||||||||||||||||
Move Directory | source, destination | Moves the source directory into a destination. Uses Copy Directory keyword internally, and |
||||||||||||||||||||||||||||||||
Move File | source, destination | Moves the source file into the destination. Arguments have exactly same semantics as with Copy File keyword. Destination file path is returned since Robot Framework 2.9.2. If the source and destination are on the same filesystem, rename operation is used. Otherwise file is copied to the destination filesystem and then removed from the original filesystem. See also Move Files, Copy File, and Copy Files. |
||||||||||||||||||||||||||||||||
Move Files | *sources_and_destination | Moves specified files to the target directory. Arguments have exactly same semantics as with Copy Files keyword. See also Move File, Copy File, and Copy Files. New in Robot Framework 2.8.4. |
||||||||||||||||||||||||||||||||
Normalize Path | path | Normalizes the given path. Examples:
=>
|
||||||||||||||||||||||||||||||||
Remove Directory | path, recursive=False | Removes the directory pointed to by the given If the second argument If the directory pointed to by the |
||||||||||||||||||||||||||||||||
Remove Environment Variable | *names | Deletes the specified environment variable. Does nothing if the environment variable is not set. Starting from Robot Framework 2.7, it is possible to remove multiple variables by passing them to this keyword as separate arguments. |
||||||||||||||||||||||||||||||||
Remove File | path | Removes a file with the given path. 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). 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. |
||||||||||||||||||||||||||||||||
Remove Files | *paths | Uses Remove File to remove multiple files one-by-one. Example:
|
||||||||||||||||||||||||||||||||
Run | command | Runs the given command in the system and returns the output. The execution status of the command is not checked by this keyword, and it must be done separately based on the returned output. If the execution return code is needed, either Run And Return RC or Run And Return RC And Output can be used. The standard error stream is automatically redirected to the standard output stream by adding The returned output contains everything written into the standard output or error streams by the command (unless either of them is redirected explicitly). Many commands add an extra newline ( Examples:
TIP: Run Process keyword provided by the Process library supports better process configuration and is generally recommended as a replacement for this keyword. |
||||||||||||||||||||||||||||||||
Run And Return Rc | command | Runs the given command in the system and returns the return code. The return code (RC) is returned as a positive integer in range from 0 to 255 as returned by the executed command. On some operating systems (notable Windows) original return codes can be something else, but this keyword always maps them to the 0-255 range. Since the RC is an integer, it must be checked e.g. with the keyword Should Be Equal As Integers instead of Should Be Equal (both are built-in keywords). Examples:
See Run and Run And Return RC And Output if you need to get the output of the executed command. TIP: Run Process keyword provided by the Process library supports better process configuration and is generally recommended as a replacement for this keyword. |
||||||||||||||||||||||||||||||||
Run And Return Rc And Output | command | Runs the given command in the system and returns the RC and output. The return code (RC) is returned similarly as with Run And Return RC and the output similarly as with Run. Examples:
TIP: Run Process keyword provided by the Process library supports better process configuration and is generally recommended as a replacement for this keyword. |
||||||||||||||||||||||||||||||||
Set Environment Variable | name, value | Sets an environment variable to a specified value. Values are converted to strings automatically. Starting from Robot Framework 2.7, set variables are automatically encoded using the system encoding. |
||||||||||||||||||||||||||||||||
Set Modified Time | path, mtime | Sets the file modification and access times. Changes the modification and access times of the given file to the value determined by 1) If 2) If 3) If 4) If 5) If Examples:
Support for UTC time is a new feature in Robot Framework 2.7.5. |
||||||||||||||||||||||||||||||||
Should Exist | path, msg=None | Fails unless the given path (file or directory) exists. The path can be given as an exact path or as a glob pattern. The pattern matching syntax is explained in introduction. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Should Not Exist | path, msg=None | Fails if the given path (file or directory) exists. The path can be given as an exact path or as a glob pattern. The pattern matching syntax is explained in introduction. The default error message can be overridden with the |
||||||||||||||||||||||||||||||||
Split Extension | path | Splits the extension from the given path. The given path is first normalized (e.g. possible trailing path separators removed, special directories Examples:
=>
|
||||||||||||||||||||||||||||||||
Split Path | path | Splits the given path from the last path separator ( The given path is first normalized (e.g. a possible trailing path separator is removed, special directories Examples:
=>
|
||||||||||||||||||||||||||||||||
Touch | path | Emulates the UNIX touch command. Creates a file, if it does not exist. Otherwise changes its access and modification times to the current time. Fails if used with the directories or the parent directory of the given file does not exist. |
||||||||||||||||||||||||||||||||
Wait Until Created | path, timeout=1 minute | Waits until the given file or directory is created. 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, the keyword returns when an item matching it is created. The optional If the timeout is negative, the keyword is never timed-out. The keyword returns immediately, if the path already exists. |
||||||||||||||||||||||||||||||||
Wait Until Removed | path, timeout=1 minute | Waits until the given file or directory is removed. 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, the keyword waits until all matching items are removed. The optional If the timeout is negative, the keyword is never timed-out. The keyword returns immediately, if the path does not exist in the first place. |
Altogether 56 keywords.
Generated by Libdoc on 2018-04-25 23:41:28.
操作系统
图书馆版本: | 3.0.4 |
---|---|
图书馆范围: | 全球 |
命名参数: | 支持的 |
介绍
为OS相关任务提供关键字的测试库。
OperatingSystem
是Robot Framework的标准库,可以在运行Robot Framework的系统中执行各种与操作系统相关的任务。除其他外,它可以执行命令(例如运行),创建和删除文件和目录(例如创建文件,删除目录),检查文件或目录是否存在或包含某些内容(例如文件应该存在,目录应该为空)和操纵环境变量(例如设置环境变量)。
目录
- 路径分隔符
- 模式匹配
- Tilde扩张
- 布尔参数
- 例
- 快捷键
- 关键词
路径分隔符
因为Robot Framework \
在测试数据中使用反斜杠()作为转义字符,所以使用文字反斜杠需要像在中一样复制它c:\\path\\file.txt
。这可能不方便,特别是对于较长的Windows路径,因此所有希望路径作为参数的关键字会在Windows上自动将正斜杠转换为反斜杠。这也意味着路径就像${CURDIR}/path/file.txt
操作系统无关。
请注意,如果路径只是参数的一部分(如Run和Start Process关键字),则自动路径分隔符转换不起作用。在这些情况下,可以使用${/}
包含\
或/
取决于操作系统的内置变量。
模式匹配
有些关键字允许将其参数指定为glob模式,其中:
* |
匹配任何东西,甚至是空字符串 |
? |
匹配任何单个字符 |
[chars] |
匹配方括号内的任何字符(例如[abc] 匹配a ,b 或c ) |
[!chars] |
匹配不在方括号内的任何字符 |
除非另有说明,否则匹配在不区分大小写的操作系统(如Windows)上不区分大小写。使用fnmatch模块实现模式匹配。
从Robot Framework 2.9.1开始,如果给定路径与现有文件匹配,即使它包含glob模式,也不会进行globbing。
Tilde扩张
分别以当前或指定用户的主目录开头~
或~username
扩展的路径。生成的路径取决于操作系统,但通常例如在Windows和Unix 上~/robot
扩展。C:\Users\
/home/
Tilde扩展是Robot Framework 2.8中的一项新功能。该~username
表单不适用于Jython
布尔参数
某些关键字接受以布尔值true或false处理的参数。如果这样的参数以字符串形式给出,则如果它是空字符串或不区分大小写,则被视为false false
,none
或no
。无论其值如何,其他字符串都被视为true,其他参数类型使用与Python相同的规则进行测试。
真实的例子:
删除目录 | $ {PATH} | 递归=真 | #字符串通常是正确的。 |
删除目录 | $ {PATH} | 递归= YES | #与上述相同。 |
删除目录 | $ {PATH} | 递归= $ {TRUE} | #Pcthon True 是真的。 |
删除目录 | $ {PATH} | 递归= $ {42} | #0以外的数字为真。 |
错误的例子:
删除目录 | $ {PATH} | 递归=假 | #String false 为false。 |
删除目录 | $ {PATH} | 递归=无 | #字符串no 也是false。 |
删除目录 | $ {PATH} | 递归= $ {EMPTY} | #Empty字符串为false。 |
删除目录 | $ {PATH} | 递归= $ {FALSE} | #Python False 是假的。 |
在Robot Framework 2.9之前,所有非空字符串(包括false
和no
)都被认为是真的。none
在Robot Framework 3.0.3中考虑false是新的。
例
设置 | 值 |
---|---|
图书馆 | 操作系统 |
变量 | 值 |
---|---|
$ {PATH} | $ {} CURDIR /example.txt |
测试用例 | 行动 | 论据 | 论据 |
---|---|---|---|
例 | 创建文件 | $ {PATH} | 一些文字 |
文件应该存在 | $ {PATH} | ||
复制文件 | $ {PATH} | 〜/ file.txt的 | |
$ {output} = | 跑 | $ {TEMPDIR} $ {/} script.py arg |
快捷键
追加到环境变量 · 附加到文件 · 复制目录 · 复制文件 · 复制文件 · 伯爵目录,在目录 · 计数目录中的文件 · 清点货物目录 · 创建二进制文件 · 创建目录 · 创建文件 · 目录应该是空的 · 目录应该存在 · 目录不应该是空的 · 目录不应该存在 · 空目录 · 应该设置环境变量 · 不应该设置环境变量 · 文件应该是空的 · 文件应该存在 · 文件不应该是空的 · 文件不应该存在 · 获取二进制文件 · 获取环境变量 · 获取环境变量 · 获取文件 · 获取文件大小 · 获取修改时间 · Grep文件 · 加入路径 · 加入路径 · 列出目录中的目录 ·列表目录 · 列出目录中的文件 · 日志环境变量 · 日志文件 · 移动目录 · 移动文件 · 移动文件 · 规范化路径 · 删除目录 · 删除环境变量 · 删除文件 · 删除文件 · 运行 · 运行并返回Rc · 运行并返回Rc和输出 · 设置环境变量 · 设置修改时间 · 应该存在 · 不应存在 ·拆分扩展 · 拆分路径 · 触摸 · 等待直到创建 · 等待直到删除
关键词
关键词 | 参数 | 文档 | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
附加到环境变量 | name, * values, ** config | 附加 如果环境变量已存在,则在其后添加值,否则将创建新的环境变量。 默认情况下,值使用操作系统路径分隔符( 示例(假设
Robot Framework 2.8.4中的新功能。 |
||||||||||||||||||||||||||||||||
附加到文件 | 路径, 内容, 编码= UTF-8 | 将给定内容附加到指定文件。 如果该文件不存在,则此关键字的工作方式与“ 创建文件”完全相同。 |
||||||||||||||||||||||||||||||||
复制目录 | 来源, 目的地 | 将源目录复制到目标。 如果目标存在,则在其下复制源。否则,将创建目标目录和可能缺少的中间目录。 |
||||||||||||||||||||||||||||||||
复制文件 | 来源, 目的地 | 将源文件复制到目标。 源必须是现有文件。从Robot Framework 2.8.4开始,它可以作为一个完全匹配一个文件的glob模式(参见模式匹配)给出。下面解释如何解释目的地。 1)如果目标是现有文件,则将源文件复制到其上。 2)如果目标是现有目录,则将源文件复制到其中。将覆盖与源名称相同的可能文件。 3)如果目标不存在并且以路径分隔符( 4)如果目标不存在且它不以路径分隔符结束,则将其视为文件。如果文件的路径不存在,则创建该路径。 从Robot Framework 2.9.2开始返回结果目标路径。 另请参阅复制文件,移动文件和移动文件。 |
||||||||||||||||||||||||||||||||
复制文件 | * sources_and_destination | 将指定的文件复制到目标目录。 源文件可以作为精确路径和glob模式给出(请参阅模式匹配)。必须至少给出一个源,但如果它是一个与任何东西都不匹配的模式,则不是错误。 最后一个参数必须是目标目录。如果目标不存在,则将创建该目标。 例子:
另请参阅复制文件,移动文件和移动文件。 Robot Framework 2.8.4中的新功能。 |
||||||||||||||||||||||||||||||||
计算目录中的目录 | path, pattern = None | 计数项目的包装器在目录中仅返回目录计数。 |
||||||||||||||||||||||||||||||||
计算目录中的文件 | path, pattern = None | 计数项目的包装在目录中仅返回文件计数。 |
||||||||||||||||||||||||||||||||
计算目录中的项目 | path, pattern = None | 返回并记录给定目录中所有项的数量。 该参数 |
||||||||||||||||||||||||||||||||
创建二进制文件 | 路径, 内容 | 创建具有给定内容的二进制文件。 如果内容以Unicode字符串形式给出,则首先将其逐个字符转换为字节。可以使用序号低于256的所有字符,并将其转换为具有相同值的字节。使用序号较高的字符是错误的。 字节字符串和可能的其他类型将按原样写入文件。 如果该文件的目录不存在,则会创建该目录以及缺少的中间目录。 例子:
如果要使用特定编码创建文本文件,请使用“ 创建文件”。File Not Not Exist可用于避免覆盖现有文件。 机器人框架2.8.5中的新功能。 |
||||||||||||||||||||||||||||||||
创建目录 | 路径 | 创建指定的目录。 还可以创建可能的中间目录。如果目录已存在则通过,但如果路径存在且不是目录则失败。 |
||||||||||||||||||||||||||||||||
创建文件 | path, content =, encoding = UTF-8 | 创建具有给定内容和编码的文件。 如果该文件的目录不存在,则会创建该目录以及缺少的中间目录。 有关可能的值的更多信息,请参阅获取文件 例子:
如果要在不编码的情况下编写字节,则如果要附加到现有文件并创建二进制文件,请使用“ 附加到文件”。File Not Not Exist可用于避免覆盖现有文件。 对Robot Framework 3.0 的支持 |
||||||||||||||||||||||||||||||||
目录应该是空的 | path, msg =无 | 除非指定的目录为空,否则失败。 可以使用 |
||||||||||||||||||||||||||||||||
目录应该存在 | path, msg =无 | 除非给定路径指向现有目录,否则失败。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用 |
||||||||||||||||||||||||||||||||
目录不应该是空的 | path, msg =无 | 如果指定的目录为空,则失败。 可以使用 |
||||||||||||||||||||||||||||||||
目录不应该存在 | path, msg =无 | 如果给定路径指向现有文件,则会失败。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用 |
||||||||||||||||||||||||||||||||
空目录 | 路径 | 删除给定目录中的所有内容。 删除文件和子目录,但如果未删除则删除指定的目录。如果要删除整个目录,请使用“ 删除目录”。 |
||||||||||||||||||||||||||||||||
应该设置环境变量 | name, msg =无 | 如果未设置指定的环境变量,则会失败。 可以使用 |
||||||||||||||||||||||||||||||||
不应设置环境变量 | name, msg =无 | 如果设置了指定的环境变量,则会失败。 可以使用 |
||||||||||||||||||||||||||||||||
文件应该是空的 | path, msg =无 | 除非指定的文件为空,否则失败。 可以使用 |
||||||||||||||||||||||||||||||||
文件应该存在 | path, msg =无 | 除非给定 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用 |
||||||||||||||||||||||||||||||||
文件不应该是空的 | path, msg =无 | 如果指定的目录为空,则失败。 可以使用 |
||||||||||||||||||||||||||||||||
文件不应该存在 | path, msg =无 | 如果给定路径指向现有文件,则会失败。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用 |
||||||||||||||||||||||||||||||||
获取二进制文件 | 路径 | 返回指定文件的内容。 此关键字读取指定的文件并按原样返回内容。另请参阅获取文件。 |
||||||||||||||||||||||||||||||||
获取环境变量 | name, default = None | 返回具有给定名称的环境变量的值。 如果未设置此类环境变量,则返回默认值(如果给定)。否则测试用例失败。 从Robot Framework 2.7开始,返回的变量使用系统编码自动解码为Unicode。 请注意,您还可以使用变量语法直接访问环境变量 |
||||||||||||||||||||||||||||||||
获取环境变量 | 将当前可用的环境变量作为字典返回。 使用系统编码将键和值都解码为Unicode。更改返回的字典对实际环境变量没有影响。 Robot Framework 2.7中的新功能。 |
|||||||||||||||||||||||||||||||||
获取文件 | path, encoding = UTF-8,encoding_errors = strict | 返回指定文件的内容。 此关键字读取指定的文件并返回内容。内容中的换行符将转换为与平台无关的表单。另请参阅获取二进制文件。
|
||||||||||||||||||||||||||||||||
获取文件大小 | 路径 | 返回并将文件大小记录为整数(以字节为单位)。 |
||||||||||||||||||||||||||||||||
获得修改时间 | path, format = timestamp | 返回文件或目录的最后修改时间。 如何返回时间是根据给定的 1)如果 2)如果 3)否则,默认情况下,时间将作为格式的时间戳字符串返回 例子(当修改时间
=>
|
||||||||||||||||||||||||||||||||
Grep文件 | path, pattern, encoding = UTF-8, encoding_errors = strict | 返回与之匹配的指定文件的行 此关键字读取使用定义从文件系统中的文件 如果一行包含其中的 例子:
如果需要更复杂的模式匹配,则可以将Get File与字符串库关键字(如Get Lines Matching Regexp)结合使用。
|
||||||||||||||||||||||||||||||||
加入路径 | 基地, *部分 | 将给定的路径部分连接到给定的基本路径。 在需要时插入路径分隔符( 例子:
=>
|
||||||||||||||||||||||||||||||||
加入路径 | 基地, *路径 | 使用base连接给定路径并返回结果路径。 有关更多信息,请参阅加入路径 例子:
=>
|
||||||||||||||||||||||||||||||||
列出目录中的目录 | path, pattern = None, absolute = False | 列表目录的包装器,仅返回目录。 |
||||||||||||||||||||||||||||||||
列表目录 | path, pattern = None, absolute = False | 返回并记录目录中的项目,可选择使用 文件和目录名称以区分大小写的字母顺序返回,例如
如果 示例(使用其他列表目录变体):
|
||||||||||||||||||||||||||||||||
列出目录中的文件 | path, pattern = None, absolute = False | 列表目录的包装器,仅返回文件。 |
||||||||||||||||||||||||||||||||
记录环境变量 | 级= INFO | 使用给定的日志级别记录所有环境变量。 环境变量的返回方式与Get Environment Variables关键字的返回方式相同。 Robot Framework 2.7中的新功能。 |
||||||||||||||||||||||||||||||||
日志文件 | path, encoding = UTF-8,encoding_errors = strict | Get File的包装器也记录返回的文件。 使用INFO级别记录该文件。如果您需要其他内容,只需使用Get File和内置关键字Log以及所需级别。 有关和参数的更多信息,请参阅获取文件。
|
||||||||||||||||||||||||||||||||
移动目录 | 来源, 目的地 | 将源目录移动到目标。 使用复制目录关键字内部,并且 |
||||||||||||||||||||||||||||||||
移动文件 | 来源, 目的地 | 将源文件移动到目标。 参数与“ 复制文件”关键字具有完全相同的语义。从Robot Framework 2.9.2开始返回目标文件路径。 如果源和目标位于同一文件系统上,则使用重命名操作。否则,文件将复制到目标文件系统,然后从原始文件系统中删除。 另请参阅移动文件,复制文件和复制文件。 |
||||||||||||||||||||||||||||||||
移动文件 | * sources_and_destination | 将指定的文件移动到目标目录。 参数与Copy Files关键字具有完全相同的语义。 另请参阅移动文件,复制文件和复制文件。 Robot Framework 2.8.4中的新功能。 |
||||||||||||||||||||||||||||||||
规范化路径 | 路径 | 规范化给定路径。 例子:
=>
|
||||||||||||||||||||||||||||||||
删除目录 | path, recursive = False | 删除给定指向的目录 如果给第二个参数 如果指向的目录 |
||||||||||||||||||||||||||||||||
删除环境变量 | *名 | 删除指定的环境变量。 如果未设置环境变量,则不执行任何操作。 从Robot Framework 2.7开始,可以通过将多个变量作为单独的参数传递给此关键字来删除它们。 |
||||||||||||||||||||||||||||||||
删除文件 | 路径 | 删除具有给定路径的文件。 如果文件不存在则通过,但如果路径未指向常规文件(例如,它指向目录)则失败。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。如果路径是模式,则删除与其匹配的所有文件。 |
||||||||||||||||||||||||||||||||
删除文件 | *路径 | 使用“ 删除文件”逐个删除多个文件。 例:
|
||||||||||||||||||||||||||||||||
跑 | 命令 | 在系统中运行给定命令并返回输出。 此关键字不检查命令的执行状态,必须根据返回的输出单独完成。如果需要执行返回代码,可以使用Run And Return RC或Run And Return RC和Output。 通过 返回的输出包含命令写入标准输出或错误流的所有内容(除非其中任何一个显式重定向)。许多命令 例子:
提示: Process库提供的Run Process关键字支持更好的流程配置,通常建议将其替换为此关键字。 |
||||||||||||||||||||||||||||||||
运行并返回Rc | 命令 | 在系统中运行给定命令并返回返回码。 返回代码(RC)作为执行命令返回的0到255范围内的正整数返回。在某些操作系统(着名的Windows)上,原始返回代码可能是其他内容,但此关键字始终将它们映射到0-255范围。由于RC是一个整数,因此必须使用关键字Do Be Equal As Integers而不是Should Be Equal(两者都是内置关键字)进行检查。 例子:
如果需要获取已执行命令的输出,请参阅运行并运行并返回RC和输出。 提示: Process库提供的Run Process关键字支持更好的流程配置,通常建议将其替换为此关键字。 |
||||||||||||||||||||||||||||||||
运行并返回Rc和输出 | 命令 | 在系统中运行给定命令并返回RC和输出。 与Run和Return RC类似地返回返回代码(RC),输出与Run类似。 例子:
提示: Process库提供的Run Process关键字支持更好的流程配置,通常建议将其替换为此关键字。 |
||||||||||||||||||||||||||||||||
设置环境变量 | 名称, 价值 | 将环境变量设置为指定值。 值将自动转换为字符串。从Robot Framework 2.7开始,使用系统编码自动编码设置变量。 |
||||||||||||||||||||||||||||||||
设置修改时间 | 路径, mtime | 设置文件修改和访问时间。 将给定文件的修改和访问时间更改为由确定的值 1)如果 2)如果 3)如果 4)如果 5)如果 例子:
支持UTC时间是Robot Framework 2.7.5中的一项新功能。 |
||||||||||||||||||||||||||||||||
应该存在 | path, msg =无 | 除非给定的路径(文件或目录)存在,否则失败。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用 |
||||||||||||||||||||||||||||||||
不应该存在 | path, msg =无 | 如果给定的路径(文件或目录)存在,则失败。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用 |
||||||||||||||||||||||||||||||||
拆分扩展 | 路径 | 从给定路径拆分扩展。 给定的路径首先被归一化(例如,可能的拖尾路径分隔除去,特殊目录 例子:
=>
|
||||||||||||||||||||||||||||||||
拆分路径 | 路径 | 从最后一个路径分隔符( 给定的路径首先被归一化(例如,可能的拖尾路径分隔被去除,特殊目录 例子:
=>
|
||||||||||||||||||||||||||||||||
触摸 | 路径 | 模拟UNIX touch命令。 如果文件不存在,则创建该文件。否则将其访问和修改时间更改为当前时间。 如果与目录一起使用或给定文件的父目录不存在,则会失败。 |
||||||||||||||||||||||||||||||||
等到创建 | 路径, 超时= 1分钟 | 等待直到创建给定文件或目录。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。如果路径是模式,则关键字在创建与其匹配的项目时返回。 可选项 如果超时为负,则关键字永远不会超时。如果路径已存在,则关键字立即返回。 |
||||||||||||||||||||||||||||||||
等到删除 | 路径, 超时= 1分钟 | 等待直到删除给定的文件或目录。 路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。如果路径是模式,则关键字将等待,直到删除所有匹配项。 可选项 如果超时为负,则关键字永远不会超时。如果路径首先不存在,则关键字立即返回。 |
共有56个关键字。
由Libdoc于2018-04-25 23:41:28 生成。