Library version: | 3.0.4 |
---|---|
Library scope: | global |
Named arguments: | supported |
A test library providing keywords for OS related tasks.html
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).python
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.app
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.框架
Some keywords allow their arguments to be specified as glob patterns where:less
* |
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.ide
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.測試
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.ui
Tilde expansion is a new feature in Robot Framework 2.8. The ~username
form does not work on Jythonthis
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.
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 |
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
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的系統中執行各類與操做系統相關的任務。除其餘外,它能夠執行命令(例如運行),建立和刪除文件和目錄(例如建立文件,刪除目錄),檢查文件或目錄是否存在或包含某些內容(例如文件應該存在,目錄應該爲空)和操縱環境變量(例如設置環境變量)。
由於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。
分別以當前或指定用戶的主目錄開頭~
或~username
擴展的路徑。生成的路徑取決於操做系統,但一般例如在Windows和Unix 上~/robot
擴展。C:\Users\<user>\robot
/home/<user>/robot
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 生成。