您的位置:首页 > 运维架构

RobotFramework之OperatingSystem

2018-08-15 09:28 543 查看

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\<user>\robot
on Windows and
/home/<user>/robot
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

SettingValue
LibraryOperatingSystem
VariableValue
${PATH}${CURDIR}/example.txt
Test CaseActionArgumentArgument
ExampleCreate 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

KeywordArgumentsDocumentation
Append To Environment Variablename, *values, **configAppends given
values
to environment variable
name
.
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 (
;
on Windows,
:
elsewhere). This can be changed by giving a separator after the values like
separator=value
. No other configuration parameters are accepted.
Examples (assuming
NAME
and
NAME2
do not exist initially):

Append To Environment VariableNAMEfirst
Should Be Equal%{NAME}first
Append To Environment VariableNAMEsecondthird
Should Be Equal%{NAME}first${:}second${:}third
Append To Environment VariableNAME2firstseparator=-
Should Be Equal%{NAME2}first
Append To Environment VariableNAME2secondseparator=-
Should Be Equal%{NAME2}first-second
New in Robot Framework 2.8.4.
Append To Filepath, content,encoding=UTF-8Appends the given content to the specified file.
If the file does not exists, this keyword works exactly the same way as Create File.
Copy Directorysource, destinationCopies 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 Filesource, destinationCopies 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 (
/
or
\
), it is considered a directory. That directory is created and a source file copied into it. Possible missing intermediate directories are also created.
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_destinationCopies 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:

Copy Files${dir}/file1.txt${dir}/file2.txt${dir2}
Copy Files${dir}/file-*.txt${dir2}
See also Copy File, Move File, and Move Files.
New in Robot Framework 2.8.4.
Count Directories In Directorypath, pattern=NoneWrapper for Count Items In Directory returning only directory count.
Count Files In Directorypath, pattern=NoneWrapper for Count Items In Directory returning only file count.
Count Items In Directorypath, pattern=NoneReturns and logs the number of all items in the given directory.
The argument
pattern
has the same semantics as with List Directory keyword. The count is returned as an integer, so it must be checked e.g. with the built-in keyword Should Be Equal As Integers.
Create Binary Filepath, contentCreates 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:

Create Binary File${dir}/example.png${image content}
Create Binary File${path}\x01\x00\xe4\x00
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 DirectorypathCreates 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 Filepath, content=,encoding=UTF-8Creates 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
encoding
values, including special values
SYSTEM
and
CONSOLE
.
Examples:

Create File${dir}/example.txtHello, world!
Create File${path}Hyv\xe4 esimerkkiLatin-1
Create File/tmp/foo.txt${content}SYSTEM
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
SYSTEM
and
CONSOLE
encodings is new in Robot Framework 3.0.
Directory Should Be Emptypath, msg=NoneFails unless the specified directory is empty.
The default error message can be overridden with the
msg
argument.
Directory Should Existpath, msg=NoneFails 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
msg
argument.
Directory Should Not Be Emptypath, msg=NoneFails if the specified directory is empty.
The default error message can be overridden with the
msg
argument.
Directory Should Not Existpath, msg=NoneFails 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
msg
argument.
Empty DirectorypathDeletes 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 Setname, msg=NoneFails if the specified environment variable is not set.
The default error message can be overridden with the
msg
argument.
Environment Variable Should Not Be Setname, msg=NoneFails if the specified environment variable is set.
The default error message can be overridden with the
msg
argument.
File Should Be Emptypath, msg=NoneFails unless the specified file is empty.
The default error message can be overridden with the
msg
argument.
File Should Existpath, msg=NoneFails unless 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
msg
argument.
File Should Not Be Emptypath, msg=NoneFails if the specified directory is empty.
The default error message can be overridden with the
msg
argument.
File Should Not Existpath, msg=NoneFails 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
msg
argument.
Get Binary FilepathReturns the contents of a specified file.
This keyword reads the specified file and returns the contents as is. See also Get File.
Get Environment Variablename, default=NoneReturns 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
%{ENV_VAR_NAME}
.
Get Environment VariablesReturns 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 Filepath, encoding=UTF-8,encoding_errors=strictReturns 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.
encoding
defines the encoding of the file. The default value is
UTF-8
, which means that UTF-8 and ASCII encoded files are read correctly. In addition to the encodings supported by the underlying Python implementation, the following special encoding values can be used:

SYSTEM
: Use the default system encoding.

CONSOLE
: Use the console encoding. Outside Windows this is same as the system encoding.

encoding_errors
argument controls what to do if decoding some bytes fails. All values accepted by
decode
method in Python are valid, but in practice the following values are most useful:

strict
: Fail if characters cannot be decoded (default).

ignore
: Ignore characters that cannot be decoded.

replace
: Replace characters that cannot be decoded with a replacement character.

encoding_errors
argument was added in Robot Framework 2.8.5 and the support for
SYSTEM
and
CONSOLE
encodings in Robot Framework 3.0.
Get File SizepathReturns and logs file size as an integer in bytes.
Get Modified Timepath, format=timestampReturns the last modification time of a file or directory.
How time is returned is determined based on the given
format
string as follows. Note that all checks are case-insensitive. Returned time is also automatically logged.
1) If
format
contains the word
epoch
, the time is returned in seconds after the UNIX epoch. The return value is always an integer.
2) If
format
contains any of the words
year
,
month
,
day
,
hour
,
min
or
sec
, only the selected parts are returned. The order of the returned parts is always the one in the previous sentence and the order of the words in
format
is not significant. The parts are returned as zero-padded strings (e.g. May ->
05
).
3) Otherwise, and by default, the time is returned as a timestamp string in the format
2006-02-24 15:08:31
.
Examples (when the modified time of
${CURDIR}
is 2006-03-29 15:06:21):

${time} =Get Modified Time${CURDIR}
${secs} =Get Modified Time${CURDIR}epoch
${year} =Get Modified Time${CURDIR}return year
${y}${d} =Get Modified Time${CURDIR}year,day
@{time} =Get Modified Time${CURDIR}year,month,day,hour,min,sec
=>

${time} = '2006-03-29 15:06:21'

${secs} = 1143637581

${year} = '2006'

${y} = '2006' & ${d} = '29'

@{time} = ['2006', '03', '29', '15', '06', '21']

Grep Filepath, pattern,encoding=UTF-8,encoding_errors=strictReturns the lines of the specified file that match the
pattern
.
This keyword reads a file from the file system using the defined
path
,
encoding
and
encoding_errors
similarly as Get File. A difference is that only the lines that match the given
pattern
are returned. Lines are returned as a single string catenated back together with newlines and the number of matched lines is automatically logged. Possible trailing newline is never returned.
A line matches if it contains the
pattern
anywhere in it and it does not need to match the pattern fully. The pattern matching syntax is explained in introduction, and in this case matching is case-sensitive.
Examples:

${errors} =Grep File/var/log/myapp.logERROR
${ret} =Grep File${CURDIR}/file.txt[Ww]ildc??d ex*ple
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.
encoding_errors
argument is new in Robot Framework 2.8.5.
Join Pathbase, *partsJoins the given path part(s) to the given base path.
The path separator (
/
or
\
) is inserted when needed and the possible absolute paths handled as expected. The resulted path is also normalized.
Examples:

${path} =Join Pathmypath
${p2} =Join Pathmy/path/
${p3} =Join Pathmypathmyfile.txt
${p4} =Join Pathmy/path
${p5} =Join Path/my/path/..path2
=>

${path} = 'my/path'

${p2} = 'my/path'

${p3} = 'my/path/my/file.txt'

${p4} = '/path'

${p5} = '/my/path2'

Join Pathsbase,&n
4000
bsp;*paths
Joins given paths with base and returns resulted paths.
See Join Path for more information.
Examples:

@{p1} =Join Pathsbaseexampleother
@{p2} =Join Paths/my/base/exampleother
@{p3} =Join Pathsmy/baseexample/path/otherone/more
=>

@{p1} = ['base/example', 'base/other']

@{p2} = ['/example', '/my/base/other']

@{p3} = ['my/base/example/path', 'my/base/other', 'my/base/one/more']

List Directories In Directorypath, pattern=None,absolute=FalseWrapper for List Directory that returns only directories.
List Directorypath, pattern=None,absolute=FalseReturns and logs items in a directory, optionally filtered with
pattern
.
File and directory names are returned in case-sensitive alphabetical order, e.g.
['A Name', 'Second', 'a lower case name', 'one more']
. Implicit directories
.
and
..
are not returned. The returned items are automatically logged.
File and directory names are returned relative to the given path (e.g.
'file.txt'
) by default. If you want them be returned in absolute format (e.g.
'/home/robot/file.txt'
), give the
absolute
argument a true value (see Boolean arguments).
If
pattern
is given, only items matching it are returned. The pattern matching syntax is explained in introduction, and in this case matching is case-sensitive.
Examples (using also other List Directory variants):

@{items} =List Directory${TEMPDIR}
@{files} =List Files In Directory/tmp*.txtabsolute
${count} =Count Files In Directory${CURDIR}???
List Files In Directorypath, pattern=None,absolute=FalseWrapper for List Directory that returns only files.
Log Environment Variableslevel=INFOLogs 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 Filepath, encoding=UTF-8,encoding_errors=strictWrapper 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
encoding
and
encoding_errors
arguments.
encoding_errors
argument is new in Robot Framework 2.8.5.
Move Directorysource, destinationMoves the source directory into a destination.
Uses Copy Directory keyword internally, and
source
and
destination
arguments have exactly same semantics as with that keyword.
Move Filesource, destinationMoves 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_destinationMoves 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 PathpathNormalizes the given path.
Examples:

${path} =Normalize Pathabc
${p2} =Normalize Pathabc/
${p3} =Normalize Pathabc/../def
${p4} =Normalize Pathabc/./def
${p5} =Normalize Pathabc//def
=>

${path} = 'abc'

${p2} = 'abc'

${p3} = 'def'

${p4} = 'abc/def'

${p5} = 'abc/def'

Remove Directorypath, recursive=FalseRemoves the directory pointed to by the given
path
.
If the second argument
recursive
is given a true value (see Boolean arguments), the directory is removed recursively. Otherwise removing fails if the directory is not empty.
If the directory pointed to by the
path
does not exist, the keyword passes, but it fails, if the
path
points to a file.
Remove Environment Variable*namesDeletes 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 FilepathRemoves 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*pathsUses Remove File to remove multiple files one-by-one.
Example:

Remove Files${TEMPDIR}${/}foo.txt${TEMPDIR}${/}bar.txt${TEMPDIR}${/}zap.txt
RuncommandRuns 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
2>&1
after the executed command. This automatic redirection is done only when the executed command does not contain additional output redirections. You can thus freely forward the standard error somewhere else, for example, like
my_command 2>stderr.txt
.
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 (
\n
) after the output to make it easier to read in the console. To ease processing the returned output, this possible trailing newline is stripped by this keyword.
Examples:

${output} =Runls -lhF /tmp
Log${output}
${result} =Run${CURDIR}${/}tester.py arg1 arg2
Should Not Contain${result}FAIL
${stdout} =Run/opt/script.sh 2>/tmp/stderr.txt
Should Be Equal${stdout}TEST PASSED
File Should Be Empty/tmp/stderr.txt
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 RccommandRuns 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:

${rc} =Run and Return RC${CURDIR}${/}script.py arg
Should Be Equal As Integers${rc}0
${rc} =Run and Return RC/path/to/example.rb arg1 arg2
Should Be True0 < ${rc} < 42
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 OutputcommandRuns 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:

${rc}${output} =Run and Return RC and Output${CURDIR}${/}mytool
Should Be Equal As Integers${rc}0
Should Not Contain${output}FAIL
${rc}${stdout} =Run and Return RC and Output/opt/script.sh 2>/tmp/stderr.txt
Should Be True${rc} > 42
Should Be Equal${stdout}TEST PASSED
File Should Be Empty/tmp/stderr.txt
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 Variablename, valueSets 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 Timepath, mtimeSets the file modification and access times.
Changes the modification and access times of the given file to the value determined by
mtime
. The time can be given in different formats described below. Note that all checks involving strings are case-insensitive. Modified time can only be set to regular files.
1) If
mtime
is a number, or a string that can be converted to a number, it is interpreted as seconds since the UNIX epoch (1970-01-01 00:00:00 UTC). This documentation was originally written about 1177654467 seconds after the epoch.
2) If
mtime
is a timestamp, that time will be used. Valid timestamp formats are
YYYY-MM-DD hh:mm:ss
and
YYYYMMDD hhmmss
.
3) If
mtime
is equal to
NOW
, the current local time is used. This time is got using Python's
time.time()
function.
4) If
mtime
is equal to
UTC
, the current time in UTC is used. This time is got using
time.time() + time.altzone
in Python.
5) If
mtime
is in the format like
NOW - 1 day
or
UTC + 1 hour 30 min
, the current local/UTC time plus/minus the time specified with the time string is used. The time string format is described in an appendix of Robot Framework User Guide.
Examples:

Set Modified Time/path/file1177654467# Time given as epoch seconds
Set Modified Time/path/file2007-04-27 9:14:27# Time given as a timestamp
Set Modified Time/path/fileNOW# The local time of execution
Set Modified Time/path/fileNOW - 1 day# 1 day subtracted from the local time
Set Modified Time/path/fileUTC + 1h 2min 3s# 1h 2min 3s added to the UTC time
Support for UTC time is a new feature in Robot Framework 2.7.5.
Should Existpath, msg=NoneFails 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
msg
argument.
Should Not Existpath, msg=NoneFails 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
msg
argument.
Split ExtensionpathSplits the extension from the given path.
The given path is first normalized (e.g. possible trailing path separators removed, special directories
..
and
.
removed). The base path and extension are returned as separate components so that the dot used as an extension separator is removed. If the path contains no extension, an empty string is returned for it. Possible leading and trailing dots in the file name are never considered to be extension separators.
Examples:

${path}${ext} =Split Extensionfile.extension
${p2}${e2} =Split Extensionpath/file.ext
${p3}${e3} =Split Extensionpath/file
${p4}${e4} =Split Extensionp1/../p2/file.ext
${p5}${e5} =Split Extensionpath/.file.ext
${p6}${e6} =Split Extensionpath/.file
=>

${path} = 'file' & ${ext} = 'extension'

${p2} = 'path/file' & ${e2} = 'ext'

${p3} = 'path/file' & ${e3} = ''

${p4} = 'p2/file' & ${e4} = 'ext'

${p5} = 'path/.file' & ${e5} = 'ext'

${p6} = 'path/.file' & ${e6} = ''

Split PathpathSplits the given path from the last path separator (
/
or
\
).
The given path is first normalized (e.g. a possible trailing path separator is removed, special directories
..
and
.
removed). The parts that are split are returned as separate components.
Examples:

${path1}${dir} =Split Pathabc/def
${path2}${file} =Split Pathabc/def/ghi.txt
${path3}${d2} =Split Pathabc/../def/ghi/
=>

${path1} = 'abc' & ${dir} = 'def'

${path2} = 'abc/def' & ${file} = 'ghi.txt'

${path3} = 'def' & ${d2} = 'ghi'

TouchpathEmulates 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 Createdpath, timeout=1 minuteWaits 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
timeout
can be used to control the maximum time of waiting. The timeout is given as a timeout string, e.g. in a format
15 seconds
,
1min 10s
or just
10
. The time string format is described in an appendix of Robot Framework User Guide.
If the timeout is negative, the keyword is never timed-out. The keyword returns immediately, if the path already exists.
Wait Until Removedpath, timeout=1 minuteWaits 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
timeout
can be used to control the maximum time of waiting. The timeout is given as a timeout string, e.g. in a format
15 seconds
,
1min 10s
or just
10
. The time string format is described in an appendix of Robot Framework User Guide.
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\<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和输出 · 设置环境变量 · 设置修改时间 · 应该存在 · 不应存在 ·拆分扩展 · 拆分路径 · 触摸 · 等待直到创建 · 等待直到删除

关键词

7fe0
关键词参数文档
附加到环境变量name, * values, ** config附加
values
到环境变量
name

如果环境变量已存在,则在其后添加值,否则将创建新的环境变量。
默认情况下,值使用操作系统路径分隔符(
;
在Windows上,
:
其他位置)连接在一起。这可以通过在值之后给出一个分隔符来改变
separator=value
。不接受其他配置参数。
示例(假设
NAME
并且
NAME2
最初不存在):

附加到环境变量名称第一
应该是平等的%{名称}第一
附加到环境变量名称第二第三
应该是平等的%{名称}第一$ {:}第二$ {:}第三
附加到环境变量NAME2第一隔板= -
应该是平等的%{} NAME2第一
附加到环境变量NAME2第二隔板= -
应该是平等的%{} NAME2第一秒
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模式给出(请参阅模式匹配)。必须至少给出一个源,但如果它是一个与任何东西都不匹配的模式,则不是错误。
最后一个参数必须是目标目录。如果目标不存在,则将创建该目标。
例子:

复制文件3ff0
$ {DIR} /file1.txt
$ {DIR} /file2.txt$ {} DIR2
复制文件$ {DIR} /文件 - * TXT$ {} DIR2
另请参阅复制文件移动文件移动文件
Robot Framework 2.8.4中的新功能。
计算目录中的目录path, pattern = None计数项目的包装器在目录中仅返回目录计数。
计算目录中的文件path, pattern = None计数项目的包装在目录中仅返回文件计数。
计算目录中的项目path, pattern = None返回并记录给定目录中所有项的数量。
该参数
pattern
List Directory关键字具有相同的语义。计数以整数形式返回,因此必须使用内置关键字“ Be Be Equal As Integers”进行检查。
创建二进制文件路径, 内容创建具有给定内容的二进制文件。
如果内容以Unicode字符串形式给出,则首先将其逐个字符转换为字节。可以使用序号低于256的所有字符,并将其转换为具有相同值的字节。使用序号较高的字符是错误的。
字节字符串和可能的其他类型将按原样写入文件。
如果该文件的目录不存在,则会创建该目录以及缺少的中间目录。
例子:

创建二进制文件$ {DIR} /example.png$ {image content}
创建二进制文件$ {PATH}\ X01 \ X00 \ XE4 \ X00
如果要使用特定编码创建文本文件,请使用“ 创建文件”File Not Not Exist可用于避免覆盖现有文件。
机器人框架2.8.5中的新功能。
创建目录路径创建指定的目录。
还可以创建可能的中间目录。如果目录已存在则通过,但如果路径存在且不是目录则失败。
创建文件path, content =, encoding = UTF-8创建具有给定内容和编码的文件。
如果该文件的目录不存在,则会创建该目录以及缺少的中间目录。
有关可能的值的更多信息,请参阅获取文件
encoding
,包括特殊值
SYSTEM
CONSOLE

例子:

创建文件$ {DIR} /example.txt你好,世界!
创建文件$ {PATH}Hyv \ xe4 esimerkki拉丁-1
创建文件/tmp/foo.txt$ {}内容系统
如果要在不编码的情况下编写字节,则如果要附加到现有文件并创建二进制文件,请使用“ 附加到文件”File Not Not Exist可用于避免覆盖现有文件。
对Robot Framework 3.0 的支持
SYSTEM
CONSOLE
编码是新的。
目录应该是空的path, msg =无除非指定的目录为空,否则失败。
可以使用
msg
参数覆盖默认错误消息。
目录应该存在path, msg =无除非给定路径指向现有目录,否则失败。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用
msg
参数覆盖默认错误消息。
目录不应该是空的path, msg =无如果指定的目录为空,则失败。
可以使用
msg
参数覆盖默认错误消息。
目录不应该存在path, msg =无如果给定路径指向现有文件,则会失败。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用
msg
参数覆盖默认错误消息。
空目录路径删除给定目录中的所有内容。
删除文件和子目录,但如果未删除则删除指定的目录。如果要删除整个目录,请使用“ 删除目录”。
应该设置环境变量name, msg =无如果未设置指定的环境变量,则会失败。
可以使用
msg
参数覆盖默认错误消息。
不应设置环境变量name, msg =无如果设置了指定的环境变量,则会失败。
可以使用
msg
参数覆盖默认错误消息。
文件应该是空的path, msg =无除非指定的文件为空,否则失败。
可以使用
msg
参数覆盖默认错误消息。
文件应该存在path, msg =无除非给定
path
指向现有文件,否则失败。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用
msg
参数覆盖默认错误消息。
文件不应该是空的path, msg =无如果指定的目录为空,则失败。
可以使用
msg
参数覆盖默认错误消息。
文件不应该存在path, msg =无如果给定路径指向现有文件,则会失败。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用
msg
参数覆盖默认错误消息。
获取二进制文件路径返回指定文件的内容。
此关键字读取指定的文件并按原样返回内容。另请参阅获取文件
获取环境变量name, default = None返回具有给定名称的环境变量的值。
如果未设置此类环境变量,则返回默认值(如果给定)。否则测试用例失败。
从Robot Framework 2.7开始,返回的变量使用系统编码自动解码为Unicode。
请注意,您还可以使用变量语法直接访问环境变量
%{ENV_VAR_NAME}

获取环境变量将当前可用的环境变量作为字典返回。
使用系统编码将键和值都解码为Unicode。更改返回的字典对实际环境变量没有影响。
Robot Framework 2.7中的新功能。
获取文件path, encoding = UTF-8,encoding_errors = strict返回指定文件的内容。
此关键字读取指定的文件并返回内容。内容中的换行符将转换为与平台无关的表单。另请参阅获取二进制文件
encoding
定义文件的编码。默认值为
UTF-8
,表示正确读取UTF-8和ASCII编码文件。除了底层Python实现支持的编码之外,还可以使用以下特殊编码值:

SYSTEM
:使用默认系统编码。

CONSOLE
:使用控制台编码。在Windows之外,这与系统编码相同。

encoding_errors
如果解码某些字节失败,参数控制该怎么做。
decode
Python中方法接受的所有值都是有效的,但实际上以下值最有用:

strict
:如果无法解码字符,则失败(默认)。

ignore
:忽略无法解码的字符。

replace
:替换无法使用替换字符解码的字符。

encoding_errors
在Robot Framework 2.8.5中添加了参数,
SYSTEM
CONSOLE
在Robot Framework 3.0中支持和编码。
获取文件大小路径返回并将文件大小记录为整数(以字节为单位)。
获得修改时间path, format = timestamp返回文件或目录的最后修改时间。
如何返回时间是根据给定的
format
字符串确定的,如下所示。请注意,所有检查都不区分大小写。返回时间也会自动记录。
1)如果
format
包含单词
epoch
,则在UNIX纪元后以秒为单位返回时间。返回值始终为整数。
2)如果
format
包含任何的话
year
month
day
hour
min
sec
,仅选定部分被返回。返回部分的顺序始终是前一句中的顺序,单词的顺序
format
并不重要。这些部分作为零填充字符串返回(例如May - >
05
)。
3)否则,默认情况下,时间将作为格式的时间戳字符串返回
2006-02-24 15:08:31

例子(当修改时间
${CURDIR}
是2006-03-29 15:06:21):

$ {time} =获得修改时间$ {} CURDIR
$ {secs} =获得修改时间$ {} CURDIR时代
$ {year} =获得修改时间$ {} CURDIR回归年
$ {Y}$ {d} =获得修改时间$ {} CURDIR年,日
@ {time} =获得修改时间$ {} CURDIR年,月,日,时,分,秒
=>

$ {time} ='2006-03-29 15:06:21'

$ {secs} = 1143637581

$ {year} ='2006'

$ {y} ='2006'&$ {d} = '29'

@ {time} = ['2006','03','29','15','06','21']

Grep文件path, pattern, encoding = UTF-8, encoding_errors = strict返回与之匹配的指定文件的行
pattern

此关键字读取使用定义从文件系统中的文件
path
encoding
并且
encoding_errors
同样为获取文件。不同之处在于只
pattern
返回与给定匹配的行。行返回为与换行符一起连接的单个字符串,并自动记录匹配行的数量。永远不会返回可能的尾随换行符。
如果一行包含其中的
pattern
任何位置并且不需要完全匹配该模式,则该行匹配。模式匹配语法在介绍中进行了解释,在这种情况下,匹配区分大小写。
例子:

$ {errors} =Grep文件/var/log/myapp.log错误
$ {ret} =Grep文件$ {} CURDIR /file.txt[Ww] ildc ?? d ex * ple
如果需要更复杂的模式匹配,则可以将Get File与字符串库关键字(如Get Lines Matching Regexp)结合使用。
encoding_errors
参数是Robot Framework 2.8.5中的新功能。
加入路径基地, *部分将给定的路径部分连接到给定的基本路径。
在需要时插入路径分隔符(
/
\
),并按预期处理可能的绝对路径。结果路径也被标准化。
例子:

$ {path} =加入路径我的路径
$ {p2} =加入路径我的/路径/
$ {p3} =加入路径我的路径我的file.txt的
$ {p4} =加入路径我的/路径
$ {p5} =加入路径/我自己的路/..路径2
=>

$ {path} ='my / path'

$ {p2} ='我/路径'

$ {p3} ='my / path / my / file.txt'

$ {p4} ='/ path'

$ {p5} ='/ my / path2'

加入路径基地, *路径使用base连接给定路径并返回结果路径。
有关更多信息,请参阅加入路径
例子:

@ {p1} =加入路径基础其他
@ {p2} =加入路径/我的/基/例其他
@ {p3} =加入路径我/基例如/路径/其他多一个
=>

@ {p1} = ['base / example','base / other']

@ {p2} = ['/ example','/ my / base / other']

@ {p3} = ['my / base / example / path','my / base / other','my / base / one / more']

列出目录中的目录path, pattern = None, absolute = False列表目录的包装器,仅返回目录。
列表目录path, pattern = None, absolute = False返回并记录目录中的项目,可选择使用
pattern

文件和目录名称以区分大小写的字母顺序返回,例如
['A Name', 'Second', 'a lower case name', 'one more']
。隐式目录
.
并且
..
不会返回。返回的项目将自动记录。
'file.txt'
默认情况下,相对于给定路径(例如)返回文件和目录名称。如果您希望以绝对格式返回它们(例如
'/home/robot/file.txt'
),请为
absolute
参数赋予一个真值(请参阅布尔参数)。
如果
pattern
给出,则仅返回与其匹配的项目。模式匹配语法在介绍中进行了解释,在这种情况下,匹配区分大小写。
示例(使用其他列表目录变体):

@ {items} =列表目录$ {TEMPDIR}
@ {files} =列出目录中的文件/ tmp目录*。文本绝对
$ {count} =计算目录中的文件$ {} CURDIR???
列出目录中的文件path, pattern = None, absolute = False列表目录的包装器,仅返回文件。
记录环境变量级= INFO使用给定的日志级别记录所有环境变量。
环境变量的返回方式与Get Environment Variables关键字的返回方式相同。
Robot Framework 2.7中的新功能。
日志文件path, encoding = UTF-8,encoding_errors = strictGet File的包装器也记录返回的文件。
使用INFO级别记录该文件。如果您需要其他内容,只需使用Get File和内置关键字Log以及所需级别。
有关和参数的更多信息,请参阅获取文件
encoding
encoding_errors

encoding_errors
参数是Robot Framework 2.8.5中的新功能。
移动目录来源, 目的地将源目录移动到目标。
使用复制目录关键字内部,并且
source
destination
参数都完全一样的语义与该关键字。
移动文件来源, 目的地将源文件移动到目标。
参数与“ 复制文件”关键字具有完全相同的语义。从Robot Framework 2.9.2开始返回目标文件路径。
如果源和目标位于同一文件系统上,则使用重命名操作。否则,文件将复制到目标文件系统,然后从原始文件系统中删除。
另请参阅移动文件复制文件复制文件
移动文件* sources_and_destination将指定的文件移动到目标目录。
参数与Copy Files关键字具有完全相同的语义。
另请参阅移动文件复制文件复制文件
Robot Framework 2.8.4中的新功能。
规范化路径路径规范化给定路径。
例子:

$ {path} =规范化路径ABC
$ {p2} =规范化路径ABC /
$ {p3} =规范化路径ABC /../高清
$ {p4} =规范化路径ABC /./高清
$ {p5} =规范化路径ABC //高清
=>

$ {path} ='abc'

$ {p2} ='abc'

$ {p3} ='def'

$ {p4} ='abc / def'

$ {p5} ='abc / def'

删除目录path, recursive = False删除给定指向的目录
path

如果给第二个参数
recursive
一个真值(参见布尔参数),则递归删除该目录。否则,如果目录不为空,则删除失败。
如果指向的目录
path
不存在,则关键字传递,但如果
path
指向文件则失败。
删除环境变量*名删除指定的环境变量。
如果未设置环境变量,则不执行任何操作。
从Robot Framework 2.7开始,可以通过将多个变量作为单独的参数传递给此关键字来删除它们。
删除文件路径删除具有给定路径的文件。
如果文件不存在则通过,但如果路径未指向常规文件(例如,它指向目录)则失败。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。如果路径是模式,则删除与其匹配的所有文件。
删除文件*路径使用“ 删除文件”逐个删除多个文件。
例:

删除文件$ {TEMPDIR} $ {/} foo.txt的$ {TEMPDIR} $ {/}跳回到bar.txt$ {TEMPDIR} $ {/} zap.txt
命令在系统中运行给定命令并返回输出。
此关键字不检查命令的执行状态,必须根据返回的输出单独完成。如果需要执行返回代码,可以使用Run And Return RCRun And Return RC和Output
通过
2>&1
在执行的命令之后添加,标准错误流自动重定向到标准输出流。仅当执行的命令不包含其他输出重定向时,才会执行此自动重定向。因此,您可以在其他地方自由转发标准错误,例如
my_command 2>stderr.txt

返回的输出包含命令写入标准输出或错误流的所有内容(除非其中任何一个显式重定向)。许多命令
\n
在输出后添加一个额外的换行符(),以便在控制台中更容易阅读。为了便于处理返回的输出,此关键字将删除此可能的尾随换行符。
例子:

$ {output} =ls -lhF / tmp
日志$ {}输出
$ {result} =$ {CURDIR} $ {/} tester.py arg1 arg2
不应该包含$ {}结果失败
$ {stdout} =/opt/script.sh 2> /tmp/stderr.txt
应该是平等的$ {}标准输出考试通过了
文件应该是空的/tmp/stderr.txt
提示: Process库提供的Run Process关键字支持更好的流程配置,通常建议将其替换为此关键字。
运行并返回Rc命令在系统中运行给定命令并返回返回码。
返回代码(RC)作为执行命令返回的0到255范围内的正整数返回。在某些操作系统(着名的Windows)上,原始返回代码可能是其他内容,但此关键字始终将它们映射到0-255范围。由于RC是一个整数,因此必须使用关键字Do Be Equal As Integers而不是Should Be Equal(两者都是内置关键字)进行检查。
例子:

$ {rc} =运行并返回RC$ {CURDIR} $ {/} script.py arg
应该与整数相等$ {} RC0
$ {rc} =运行并返回RC/path/to/example.rb arg1 arg2
应该是真的0 <$ {rc} <42
如果需要获取已执行命令的输出,请参阅运行运行并返回RC和输出
提示: Process库提供的Run Process关键字支持更好的流程配置,通常建议将其替换为此关键字。
运行并返回Rc和输出命令在系统中运行给定命令并返回RC和输出。
Run和Return RC类似地返回返回代码(RC),输出与Run类似。
例子:

$ {} RC$ {output} =运行并返回RC和输出$ {CURDIR} $ {/} mytool
应该与整数相等$ {} RC0
不应该包含$ {}输出失败
$ {} RC$ {stdout} =运行并返回RC和输出/opt/script.sh 2> /tmp/stderr.txt
应该是真的$ {rc}> 42
应该是平等的$ {}标准输出考试通过了
文件应该是空的/tmp/stderr.txt
提示: Process库提供的Run Process关键字支持更好的流程配置,通常建议将其替换为此关键字。
设置环境变量名称, 价值将环境变量设置为指定值。
值将自动转换为字符串。从Robot Framework 2.7开始,使用系统编码自动编码设置变量。
设置修改时间路径, mtime设置文件修改和访问时间。
将给定文件的修改和访问时间更改为由确定的值
mtime
。时间可以以下面描述的不同格式给出。请注意,涉及字符串的所有检查都不区分大小写。修改时间只能设置为常规文件。
1)如果
mtime
是数字或可以转换为数字的字符串,则将其解释为自UNIX纪元(1970-01-01 00:00:00 UTC)以来的秒数。该文档最初是在纪元后的1177654467秒写的。
2)如果
mtime
是时间戳,将使用该时间。有效的时间戳格式为
YYYY-MM-DD hh:mm:ss
YYYYMMDD hhmmss

3)如果
mtime
等于
NOW
,则使用当前本地时间。这次是使用Python的
time.time()
功能。
4)如果
mtime
等于
UTC
,则使用UTC中的当前时间。这次是
time.time() + time.altzone
在Python中使用的。
5)如果
mtime
格式为
NOW - 1 day
UTC + 1 hour 30 min
,则使用当前本地/ UTC时间加/减时间字符串指定的时间。时间字符串格式在Robot Framework用户指南的附录中描述。
例子:

设置修改时间/路径/文件1177654467#给出时间秒的时间
设置修改时间/路径/文件2007-04-27 9:14:27#作为时间戳给出的时间
设置修改时间/路径/文件现在#本地执行时间
设置修改时间/路径/文件现在 - 1天从当地时间减去#1天
设置修改时间/路径/文件UTC + 1h 2min 3s#1h 2min 3s添加到UTC时间
支持UTC时间是Robot Framework 2.7.5中的一项新功能。
应该存在path, msg =无除非给定的路径(文件或目录)存在,否则失败。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用
msg
参数覆盖默认错误消息。
不应该存在path, msg =无如果给定的路径(文件或目录)存在,则失败。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。可以使用
msg
参数覆盖默认错误消息。
拆分扩展路径从给定路径拆分扩展。
给定的路径首先被归一化(例如,可能的拖尾路径分隔除去,特殊目录
..
.
移除)。基本路径和扩展名作为单独的组件返回,以便删除用作扩展分隔符的点。如果路径不包含扩展名,则为其返回空字符串。文件名中可能的前导和尾随点永远不会被视为扩展分隔符。
例子:

$ {PATH}$ {ext} =拆分扩展文件扩展名
$ {} P2$ {e2} =拆分扩展路径/ file.ext
$ {} P3$ {e3} =拆分扩展路径/文件
$ {} P4$ {e4} =拆分扩展P1 /../ P2 / file.ext
$ {} P5$ {e5} =拆分扩展路径/ .file.ext
$ {} P6$ {e6} =拆分扩展路径/ .file
=>

$ {path} ='file'&$ {ext} ='extension'

$ {p2} ='路径/文件'&$ {e2} ='ext'

$ {p3} ='路径/文件'和$ {e3} =''

$ {p4} ='p2 / file'&$ {e4} ='ext'

$ {p5} ='path / .file'和$ {e5} ='ext'

$ {p6} ='path / .file'和$ {e6} =''

拆分路径路径从最后一个路径分隔符(
/
\
)拆分给定路径。
给定的路径首先被归一化(例如,可能的拖尾路径分隔被去除,特殊目录
..
.
移除)。拆分的部件作为单独的组件返回。
例子:

$ {PATH1}$ {dir} =拆分路径ABC / DEF
$ {} PATH2$ {file} =拆分路径ABC / DEF / ghi.txt
$ {} path3时,$ {d2} =拆分路径ABC DEF /../ / GHI /
=>

$ {path1} ='abc'和$ {dir} ='def'

$ {path2} ='abc / def'和$ {file} ='ghi.txt'

$ {path3} ='def'&$ {d2} ='ghi'

触摸路径模拟UNIX touch命令。
如果文件不存在,则创建该文件。否则将其访问和修改时间更改为当前时间。
如果与目录一起使用或给定文件的父目录不存在,则会失败。
等到创建路径, 超时= 1分钟等待直到创建给定文件或目录。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。如果路径是模式,则关键字在创建与其匹配的项目时返回。
可选项
timeout
可用于控制最长等待时间。超时给出超时字符串,例如在一个格式
15 seconds
1min 10s
或者只
10
。时间字符串格式在Robot Framework用户指南的附录中描述。
如果超时为负,则关键字永远不会超时。如果路径已存在,则关键字立即返回。
等到删除路径, 超时= 1分钟等待直到删除给定的文件或目录。
路径可以作为精确路径或全局模式给出。模式匹配语法在介绍中进行了解释。如果路径是模式,则关键字将等待,直到删除所有匹配项。
可选项
timeout
可用于控制最长等待时间。超时给出超时字符串,例如在一个格式
15 seconds
1min 10s
或者只
10
。时间字符串格式在Robot Framework用户指南的附录中描述。
如果超时为负,则关键字永远不会超时。如果路径首先不存在,则关键字立即返回。
共有56个关键字。
Libdoc于2018-04-25 23:41:28 生成。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Robot Framework