文档章节

RobotFramework之Process

海盐宝宝
 海盐宝宝
发布于 08/15 09:31
字数 8811
阅读 0
收藏 0

Process

Library version: 3.0.4
Library scope: global
Named arguments: supported

Introduction

Robot Framework test library for running processes.

This library utilizes Python's subprocess module and its Popen class.

The library has following main usages:

This library is new in Robot Framework 2.8.

Table of contents

Specifying command and arguments

Both Run Process and Start Process accept the command to execute and all arguments passed to the command as separate arguments. This makes usage convenient and also allows these keywords to automatically escape possible spaces and other special characters in commands and arguments. Notice that if a command accepts options that themselves accept values, these options and their values must be given as separate arguments.

When running processes in shell, it is also possible to give the whole command to execute as a single string. The command can then contain multiple commands to be run together. When using this approach, the caller is responsible on escaping.

Examples:

Run Process ${tools}${/}prog.py argument second arg with spaces    
Run Process java -jar ${jars}${/}example.jar --option value
Run Process prog.py "one arg" && tool.sh shell=yes cwd=${tools}    

Starting from Robot Framework 2.8.6, possible non-string arguments are converted to strings automatically.

Process configuration

Run Process and Start Process keywords can be configured using optional **configuration keyword arguments. Configuration arguments must be given after other arguments passed to these keywords and must use syntax like name=value. Available configuration arguments are listed below and discussed further in sections afterwards.

Name Explanation
shell Specifies whether to run the command in shell or not.
cwd Specifies the working directory.
env Specifies environment variables given to the process.
env:<name> Overrides the named environment variable(s) only.
stdout Path of a file where to write standard output.
stderr Path of a file where to write standard error.
output_encoding Encoding to use when reading command outputs.
alias Alias given to the process.

Note that because **configuration is passed using name=value syntax, possible equal signs in other arguments passed to Run Process and Start Process must be escaped with a backslash like name\=value. See Run Process for an example.

Running processes in shell

The shell argument specifies whether to run the process in a shell or not. By default shell is not used, which means that shell specific commands, like copy and dir on Windows, are not available. You can, however, run shell scripts and batch files without using a shell.

Giving the shell argument any non-false value, such as shell=True, changes the program to be executed in a shell. It allows using the shell capabilities, but can also make the process invocation operating system dependent. Having a shell between the actually started process and this library can also interfere communication with the process such as stopping it and reading its outputs. Because of these problems, it is recommended to use the shell only when absolutely necessary.

When using a shell it is possible to give the whole command to execute as a single string. See Specifying command and arguments section for examples and more details in general.

Current working directory

By default the child process will be executed in the same directory as the parent process, the process running tests, is executed. This can be changed by giving an alternative location using the cwd argument. Forward slashes in the given path are automatically converted to backslashes on Windows.

Standard output and error streams, when redirected to files, are also relative to the current working directory possibly set using the cwd argument.

Example:

Run Process prog.exe cwd=${ROOT}/directory stdout=stdout.txt

Environment variables

By default the child process will get a copy of the parent process's environment variables. The env argument can be used to give the child a custom environment as a Python dictionary. If there is a need to specify only certain environment variable, it is possible to use the env:<name>=<value> format to set or override only that named variables. It is also possible to use these two approaches together.

Examples:

Run Process program env=${environ}  
Run Process program env:http_proxy=10.144.1.10:8080 env:PATH=%{PATH}${:}${PROGDIR}
Run Process program env=${environ} env:EXTRA=value

Standard output and error streams

By default processes are run so that their standard output and standard error streams are kept in the memory. This works fine normally, but if there is a lot of output, the output buffers may get full and the program can hang. Additionally on Jython, everything written to these in-memory buffers can be lost if the process is terminated.

To avoid the above mentioned problems, it is possible to use stdout and stderr arguments to specify files on the file system where to redirect the outputs. This can also be useful if other processes or other keywords need to read or manipulate the outputs somehow.

Given stdout and stderr paths are relative to the current working directory. Forward slashes in the given paths are automatically converted to backslashes on Windows.

As a special feature, it is possible to redirect the standard error to the standard output by using stderr=STDOUT.

Regardless are outputs redirected to files or not, they are accessible through the result object returned when the process ends. Commands are expected to write outputs using the console encoding, but output encoding can be configured using the output_encoding argument if needed.

Examples:

${result} = Run Process program stdout=${TEMPDIR}/stdout.txt stderr=${TEMPDIR}/stderr.txt
Log Many stdout: ${result.stdout} stderr: ${result.stderr}    
${result} = Run Process program stderr=STDOUT  
Log all output: ${result.stdout}      

Note that the created output files are not automatically removed after the test run. The user is responsible to remove them if needed.

Output encoding

Executed commands are, by default, expected to write outputs to the standard output and error streams using the encoding used by the system console. If the command uses some other encoding, that can be configured using the output_encoding argument. This is especially useful on Windows where the console uses a different encoding than rest of the system, and many commands use the general system encoding instead of the console encoding.

The value used with the output_encoding argument must be a valid encoding and must match the encoding actually used by the command. As a convenience, it is possible to use strings CONSOLE and SYSTEM to specify that the console or system encoding is used, respectively. If produced outputs use different encoding then configured, values got through the result object will be invalid.

Examples:

Start Process program output_encoding=UTF-8  
Run Process program stdout=${path} output_encoding=SYSTEM

The support to set output encoding is new in Robot Framework 3.0.

Alias

A custom name given to the process that can be used when selecting the active process.

Examples:

Start Process program alias=example    
Run Process python -c print 'hello' alias=hello

Active process

The test library keeps record which of the started processes is currently active. By default it is latest process started with Start Process, but Switch Process can be used to select a different one. Using Run Process does not affect the active process.

The keywords that operate on started processes will use the active process by default, but it is possible to explicitly select a different process using the handle argument. The handle can be the identifier returned by Start Process or an alias explicitly given to Start Process or Run Process.

Result object

Run ProcessWait For Process and Terminate Process keywords return a result object that contains information about the process execution as its attributes. The same result object, or some of its attributes, can also be get using Get Process Result keyword. Attributes available in the object are documented in the table below.

Attribute Explanation
rc Return code of the process as an integer.
stdout Contents of the standard output stream.
stderr Contents of the standard error stream.
stdout_path Path where stdout was redirected or None if not redirected.
stderr_path Path where stderr was redirected or None if not redirected.

Example:

${result} = Run Process program
Should Be Equal As Integers ${result.rc} 0
Should Match ${result.stdout} Some t?xt*
Should Be Empty ${result.stderr}  
${stdout} = Get File ${result.stdout_path}
Should Be Equal ${stdout} ${result.stdout}
File Should Be Empty ${result.stderr_path}  

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 falsenoneor no. Other strings are considered true regardless their value, and other argument types are tested using the same rules as in Python.

True examples:

Terminate Process kill=True # Strings are generally true.
Terminate Process kill=yes # Same as the above.
Terminate Process kill=${TRUE} # Python True is true.
Terminate Process kill=${42} # Numbers other than 0 are true.

False examples:

Terminate Process kill=False # String false is false.
Terminate Process kill=no # Also string no is false.
Terminate Process kill=${EMPTY} # Empty string is false.
Terminate Process kill=${FALSE} # Python False is false.

Prior to Robot Framework 2.9, all non-empty strings, including false and no, were considered to be true. Considering none false is new in Robot Framework 3.0.3.

Example

*** Settings ***
Library           Process
Suite Teardown    Terminate All Processes    kill=True

*** Test Cases ***
Example
    Start Process    program    arg1    arg2    alias=First
    ${handle} =    Start Process    command.sh arg | command2.sh    shell=True    cwd=/path
    ${result} =    Run Process    ${CURDIR}/script.py
    Should Not Contain    ${result.stdout}    FAIL
    Terminate Process    ${handle}
    ${result} =    Wait For Process    First
    Should Be Equal As Integers    ${result.rc}    0

Shortcuts

Get Process Id · Get Process Object · Get Process Result · Is Process Running · Join Command Line · Process Should Be Running · Process Should Be Stopped · Run Process · Send Signal To Process · Split Command Line · Start Process ·Switch Process · Terminate All Processes · Terminate Process · Wait For Process

Keywords

Keyword Arguments Documentation
Get Process Id handle=None

Returns the process ID (pid) of the process as an integer.

If handle is not given, uses the current active process.

Notice that the pid is not the same as the handle returned by Start Process that is used internally by this library.

Get Process Object handle=None

Return the underlying subprocess.Popen object.

If handle is not given, uses the current active process.

Get Process Result handle=None, rc=False,stdout=False, stderr=False,stdout_path=False,stderr_path=False

Returns the specified result object or some of its attributes.

The given handle specifies the process whose results should be returned. If no handle is given, results of the current active process are returned. In either case, the process must have been finishes before this keyword can be used. In practice this means that processes started with Start Process must be finished either with Wait For Process or Terminate Process before using this keyword.

If no other arguments than the optional handle are given, a whole result object is returned. If one or more of the other arguments are given any true value, only the specified attributes of the result object are returned. These attributes are always returned in the same order as arguments are specified in the keyword signature. See Boolean arguments section for more details about true and false values.

Examples:

Run Process python -c print 'Hello, world!' alias=myproc  
# Get result object          
${result} = Get Process Result myproc      
Should Be Equal ${result.rc} ${0}      
Should Be Equal ${result.stdout} Hello, world!      
Should Be Empty ${result.stderr}        
# Get one attribute          
${stdout} = Get Process Result myproc stdout=true    
Should Be Equal ${stdout} Hello, world!      
# Multiple attributes          
${stdout} ${stderr} = Get Process Result myproc stdout=yes stderr=yes
Should Be Equal ${stdout} Hello, world!      
Should Be Empty ${stderr}        

Although getting results of a previously executed process can be handy in general, the main use case for this keyword is returning results over the remote library interface. The remote interface does not support returning the whole result object, but individual attributes can be returned without problems.

New in Robot Framework 2.8.2.

Is Process Running handle=None

Checks is the process running or not.

If handle is not given, uses the current active process.

Returns True if the process is still running and False otherwise.

Join Command Line *args

Joins arguments into one command line string.

In resulting command line string arguments are delimited with a space, arguments containing spaces are surrounded with quotes, and possible quotes are escaped with a backslash.

If this keyword is given only one argument and that is a list like object, then the values of that list are joined instead.

Example:

${cmd} = Join Command Line --option value with spaces
Should Be Equal ${cmd} --option "value with spaces"  

New in Robot Framework 2.9.2.

Process Should Be Running handle=None,error_message=Process is not running.

Verifies that the process is running.

If handle is not given, uses the current active process.

Fails if the process has stopped.

Process Should Be Stopped handle=None,error_message=Process is running.

Verifies that the process is not running.

If handle is not given, uses the current active process.

Fails if the process is still running.

Run Process command, *arguments,**configuration

Runs a process and waits for it to complete.

command and *arguments specify the command to execute and arguments passed to it. See Specifying command and arguments for more details.

**configuration contains additional configuration related to starting processes and waiting for them to finish. See Process configuration for more details about configuration related to starting processes. Configuration related to waiting for processes consists of timeout and on_timeout arguments that have same semantics as with Wait For Process keyword. By default there is no timeout, and if timeout is defined the default action on timeout is terminate.

Returns a result object containing information about the execution.

Note that possible equal signs in *arguments must be escaped with a backslash (e.g. name\=value) to avoid them to be passed in as **configuration.

Examples:

${result} = Run Process python -c print 'Hello, world!'
Should Be Equal ${result.stdout} Hello, world!    
${result} = Run Process ${command} stderr=STDOUT timeout=10s
${result} = Run Process ${command} timeout=1min on_timeout=continue
${result} = Run Process java -Dname\=value Example shell=True cwd=${EXAMPLE}

This keyword does not change the active process.

timeout and on_timeout arguments are new in Robot Framework 2.8.4.

Send Signal To Process signal, handle=None,group=False

Sends the given signal to the specified process.

If handle is not given, uses the current active process.

Signal can be specified either as an integer as a signal name. In the latter case it is possible to give the name both with or without SIG prefix, but names are case-sensitive. For example, all the examples below send signal INT (2):

Send Signal To Process 2   # Send to active process
Send Signal To Process INT    
Send Signal To Process SIGINT myproc # Send to named process

This keyword is only supported on Unix-like machines, not on Windows. What signals are supported depends on the system. For a list of existing signals on your system, see the Unix man pages related to signal handling (typically man signal or man 7 signal).

By default sends the signal only to the parent process, not to possible child processes started by it. Notice that when running processes in shell, the shell is the parent process and it depends on the system does the shell propagate the signal to the actual started process.

To send the signal to the whole process group, group argument can be set to any true value (see Boolean arguments). This is not supported by Jython, however.

New in Robot Framework 2.8.2. Support for group argument is new in Robot Framework 2.8.5.

Split Command Line args, escaping=False

Splits command line string into a list of arguments.

String is split from spaces, but argument surrounded in quotes may contain spaces in them. If escaping is given a true value, then backslash is treated as an escape character. It can escape unquoted spaces, quotes inside quotes, and so on, but it also requires using double backslashes when using Windows paths.

Examples:

@{cmd} = Split Command Line --option "value with spaces"
Should Be True $cmd == ['--option', 'value with spaces']  

New in Robot Framework 2.9.2.

Start Process command, *arguments,**configuration

Starts a new process on background.

See Specifying command and arguments and Process configuration for more information about the arguments, and Run Process keyword for related examples.

Makes the started process new active process. Returns an identifier that can be used as a handle to activate the started process if needed.

Starting from Robot Framework 2.8.5, processes are started so that they create a new process group. This allows sending signals to and terminating also possible child processes. This is not supported by Jython in general nor by Python versions prior to 2.7 on Windows.

Switch Process handle

Makes the specified process the current active process.

The handle can be an identifier returned by Start Process or the alias given to it explicitly.

Example:

Start Process prog1 alias=process1
Start Process prog2 alias=process2
# currently active process is process2    
Switch Process process1  
# now active process is process1    
Terminate All Processes kill=False

Terminates all still running processes started by this library.

This keyword can be used in suite teardown or elsewhere to make sure that all processes are stopped,

By default tries to terminate processes gracefully, but can be configured to forcefully kill them immediately. See Terminate Process that this keyword uses internally for more details.

Terminate Process handle=None, kill=False

Stops the process gracefully or forcefully.

If handle is not given, uses the current active process.

By default first tries to stop the process gracefully. If the process does not stop in 30 seconds, or kill argument is given a true value, (see Boolean arguments) kills the process forcefully. Stops also all the child processes of the originally started process.

Waits for the process to stop after terminating it. Returns a result object containing information about the execution similarly as Wait For Process.

On Unix-like machines graceful termination is done using TERM (15) signal and killing using KILL (9). Use Send Signal To Process instead if you just want to send either of these signals without waiting for the process to stop.

On Windows graceful termination is done using CTRL_BREAK_EVENT event and killing using Win32 API function TerminateProcess().

Examples:

${result} = Terminate Process    
Should Be Equal As Integers ${result.rc} -15 # On Unixes
Terminate Process myproc kill=true  

Limitations:

  • Graceful termination is not supported on Windows by Jython nor by Python versions prior to 2.7. Process is killed instead.
  • Stopping the whole process group is not supported by Jython at all nor by Python versions prior to 2.7 on Windows.
  • On Windows forceful kill only stops the main process, not possible child processes.

Automatically killing the process if termination fails as well as returning a result object are new features in Robot Framework 2.8.2. Terminating also possible child processes, including using CTRL_BREAK_EVENT on Windows, is new in Robot Framework 2.8.5.

Wait For Process handle=None, timeout=None,on_timeout=continue

Waits for the process to complete or to reach the given timeout.

The process to wait for must have been started earlier with Start Process. If handle is not given, uses the current active process.

timeout defines the maximum time to wait for the process. It can be given in various time formats supported by Robot Framework, for example, 4242 s, or 1 minute 30 seconds.

on_timeout defines what to do if the timeout occurs. Possible values and corresponding actions are explained in the table below. Notice that reaching the timeout never fails the test.

Value Action
continue The process is left running (default).
terminate The process is gracefully terminated.
kill The process is forcefully stopped.

See Terminate Process keyword for more details how processes are terminated and killed.

If the process ends before the timeout or it is terminated or killed, this keyword returns a result object containing information about the execution. If the process is left running, Python None is returned instead.

Examples:

# Process ends cleanly      
${result} = Wait For Process example  
Process Should Be Stopped example    
Should Be Equal As Integers ${result.rc} 0  
# Process does not end      
${result} = Wait For Process timeout=42 secs  
Process Should Be Running      
Should Be Equal ${result} ${NONE}  
# Kill non-ending process      
${result} = Wait For Process timeout=1min 30s on_timeout=kill
Process Should Be Stopped      
Should Be Equal As Integers ${result.rc} -9  

timeout and on_timeout are new in Robot Framework 2.8.2.

Altogether 15 keywords. 
Generated by Libdoc on 2018-04-25 23:41:29.

处理

图书馆版本: 3.0.4
图书馆范围: 全球
命名参数: 支持的

介绍

用于运行进程的Robot Framework测试库。

该库使用Python的子进程模块及其Popen类。

该图书馆有以下主要用途:

这个库是Robot Framework 2.8中的新增功能。

目录

指定命令和参数

无论运行过程启动过程接受执行命令,并传递给命令作为独立参数,所有参数。这使得使用方便,并且还允许这些关键字自动转义命令和参数中的可能空格和其他特殊字符。请注意,如果命令接受自己接受值的选项,则必须将这些选项及其值作为单独的参数给出。

运行在壳进程,它也可以给整个命令来执行作为单个字符串。然后,该命令可以包含多个要一起运行的命令。使用此方法时,调用者负责转义。

例子:

运行流程 $ {工具} $ {/} prog.py 论据 第二个arg有空格    
运行流程 java的 -罐 $ {罐} $ {/} example.jar - 选项
运行流程 prog.py“one arg”&& tool.sh 壳= YES CWD = $ {}工具    

从Robot Framework 2.8.6开始,可能的非字符串参数会自动转换为字符串。

流程配置

可以使用可选的关键字参数配置Run ProcessStart Process关键字**configuration。必须在传递给这些关键字的其他参数之后给出配置参数,并且必须使用类似语法name=value。下面列出了可用的配置参数,然后在后面的章节中进一步讨论。

名称 说明
贝壳 指定是否在shell中运行命令。
CWD 指定工作目录。
ENV 指定为进程指定的环境变量。
ENV:<名称> 仅覆盖指定的环境变量。
标准输出 文件的路径写入标准输出的位置。
标准错误 文件的路径在哪里写标准错误。
output_encoding 在读取命令输出时使用的编码。
别号 别名给予该过程。

请注意,因为**configuration使用name=value语法传递,所以传递给Run ProcessStart Process的其他参数中的可能等号必须使用反斜杠转义name\=value。有关示例,请参阅运行过程

在shell中运行进程

shell参数指定是否在外壳或无法运行的过程。默认情况下,外壳没有使用,这意味着外壳特定命令,就像copydir在Windows,不可用。但是,您可以在不使用shell的情况下运行shell脚本和批处理文件。

shell参数赋予任何非假值,例如shell=True,更改要在shell中执行的程序。它允许使用shell功能,但也可以使进程调用操作系统依赖。在实际启动的进程和此库之间具有shell也可能干扰与进程的通信,例如停止它并读取其输出。由于这些问题,建议仅在绝对必要时才使用shell。

使用shell时,可以将整个命令作为单个字符串执行。有关示例和更多详细信息,请参阅指定命令和参数部分。

当前的工作目录

默认情况下,子进程将在与父进程相同的目录中执行,执行运行测试的进程。这可以通过使用cwd参数提供替代位置来更改。在给定路径中的正斜杠自动转换为Windows上的反斜杠。

重定向到文件时,标准输出和错误流也与可能使用cwd参数设置的当前工作目录相关。

例:

运行流程 prog.exe CWD = $ {ROOT} /目录 标准输出= stdout.txt

环境变量

默认情况下,子进程将获取父进程的环境变量的副本。该env参数可用于为子项提供自定义环境作为Python字典。如果只需要指定某个环境变量,则可以使用该env:<name>=<value>格式来设置或仅覆盖该命名变量。也可以将这两种方法结合使用。

例子:

运行流程 程序 ENV = $ {} ENVIRON  
运行流程 程序 ENV:HTTP_PROXY = 10.144.1.10:8080 ENV:PATH =%{PATH} $ {:} $ {} PROGDIR
运行流程 程序 ENV = $ {} ENVIRON ENV:EXTRA =值

标准输出和错误流

默认情况下,运行进程以使其标准输出和标准错误流保留在内存中。这通常工作正常,但如果有很多输出,输出缓冲区可能会满,程序可能会挂起。此外,在Jython上,如果进程终止,写入这些内存缓冲区的所有内容都可能会丢失。

为了避免上述问题,可以使用stdoutstderr参数来指定文件系统上重定向输出的文件。如果其他进程或其他关键字需要以某种方式读取或操作输出,这也很有用。

给定stdoutstderr路径相对于当前工作目录。在给定路径中的正斜杠自动转换为Windows上的反斜杠。

作为一项特殊功能,可以使用标准错误将标准错误重定向到标准输出stderr=STDOUT

无论是否重定向到文件的输出,都可以通过进程结束时返回的结果对象访问它们。命令期望使用控制台编码写入输出,但是如果需要,可以使用参数配置输出编码output_encoding

例子:

$ {result} = 运行流程 程序 标准输出= $ {TEMPDIR} /stdout.txt 标准错误= $ {TEMPDIR} /stderr.txt
记录很多 stdout:$ {result.stdout} stderr:$ {result.stderr}    
$ {result} = 运行流程 程序 标准错误= STDOUT  
日志 所有输出:$ {result.stdout}      

请注意,测试运行后不会自动删除创建的输出文件。如果需要,用户有责任将其删除。

输出编码

默认情况下,执行的命令希望使用系统控制台使用的编码将输出写入标准输出和错误流。如果该命令使用某些其他编码,则可以使用该output_encoding参数进行配置。这在Windows上使用与系统其他部分不同的编码时非常有用,并且许多命令使用通用系统编码而不是控制台编码。

output_encoding参数一起使用的值必须是有效编码,并且必须与命令实际使用的编码匹配。为方便起见,可以使用字符串CONSOLESYSTEM分别指定使用控制台或系统编码。如果生成的输出使用随后配置的不同编码,则通过结果对象获得的值将无效。

例子:

开始流程 程序 output_encoding = UTF-8  
运行流程 程序 标准输出= $ {路径} output_encoding = SYSTEM

设置输出编码的支持是Robot Framework 3.0中的新增功能。

别号

选择活动进程时可以使用的自定义名称。

例子:

开始流程 程序 别名=示例    
运行流程 蟒蛇 -C 打印'你好' 别名=你好

积极的过程

测试库记录哪些已启动的进程当前处于活动状态。默认情况下,它是使用Start Process启动的最新流程,但Switch Process可用于选择其他流程。使用“运行进程 ”不会影响活动进程。

默认情况下,对已启动进程执行操作的关键字将使用活动进程,但可以使用该handle参数显式选择其他进程。该手柄可以是该标识符由返回开始处理alias显式地提供给启动过程运行过程

结果对象

“运行进程”,“ 等待进程”和“ 终止进程”关键字返回一个结果对象,该对象包含有关进程执行的信息作为其属性。使用Get Process Result关键字也可以获得相同的结果对象或其某些属性。对象中可用的属性记录在下表中。

属性 说明
RC 将进程的代码作为整数返回。
标准输出 标准输出流的内容。
标准错误 标准错误流的内容。
stdout_path stdout被重定向或未重定向的路径None
stderr_path 重定向stderr或未重定向的路径None

例:

$ {result} = 运行流程 程序
应该与整数相等 $ {} result.rc 0
应该匹配 $ {} result.stdout 一些t?xt *
应该是空的 $ {} result.stderr  
$ {stdout} = 获取文件 $ {} result.stdout_path
应该是平等的 $ {}标准输出 $ {} result.stdout
文件应该是空的 $ {} result.stderr_path  

布尔参数

某些关键字接受以布尔值true或false处理的参数。如果这样的参数以字符串形式给出,则如果它是空字符串或不区分大小写,则被视为false falsenoneno。无论其值如何,其他字符串都被视为true,其他参数类型使用与Python相同的规则进行测试。

真实的例子:

终止流程 杀=真 #字符串通常是正确的。
终止流程 杀= YES #与上述相同。
终止流程 杀= $ {TRUE} #Pcthon True是真的。
终止流程 杀= $ {42} #0以外的数字为真。

错误的例子:

终止流程 杀=假 #String false为false。
终止流程 杀=无 #字符串no也是false。
终止流程 杀= $ {EMPTY} #Empty字符串为false。
终止流程 杀= $ {FALSE} #Python False是假的。

在Robot Framework 2.9之前,所有非空字符串(包括falseno)都被认为是真的。none在Robot Framework 3.0.3中考虑false是新的。

***设置*** 
库进程
套件拆解     终止所有进程     kill = True ***测试用例*** 
示例启动进程     程序arg1 arg2 alias = First 
    $ {handle} =     启动进程     command.sh arg | command2.sh shell = True cwd = / path 
    $ {result} =     运行流程     $ {CURDIR} /script.py
     不应包含     $ {result.stdout} FAIL
     终止流程     $ {handle} 
    $ {result} =     等待流程     优先
     应该与整数相等


        $ {result.rc} 0

快捷键

获取进程ID · 获取进程对象 · 获取进程结果 · 进程正在运行 · 加入命令行 · 进程应该运行 · 进程应该停止 · 运行进程 · 发送信号进行处理 · 拆分命令行 · 启动进程 · 切换进程 · 终止所有进程 · 终止进程 · 等待进程

关键词

关键词 参数 文档
获取进程ID 手柄=无

以整数形式返回进程的进程ID(pid)。

如果handle未给出,则使用当前活动进程

请注意,pid与此库内部使用的Start Process返回的句柄不同。

获取流程对象 手柄=无

返回底层subprocess.Popen对象。

如果handle未给出,则使用当前活动进程

获取流程结果 handle = None, rc = False, stdout = False, stderr = False, stdout_path = False, stderr_path = False

返回指定的结果对象或其某些属性。

给定handle指定应返回其结果的进程。如果不handle给出,则返回当前活动进程的结果。在任何一种情况下,都必须在使用此关键字之前完成该过程。实际上,这意味着在使用此关键字之前,必须使用“ 等待进程”或“ 终止进程”完成以“ 启动进程”启动的进程

如果没有handle给出除可选之外的其他参数,则返回整个结果对象。如果一个或多个其他参数被赋予任何真值,则仅返回结果对象的指定属性。始终以与关键字签名中指定的参数相同的顺序返回这些属性。有关true和false值的更多详细信息,请参阅布尔参数部分。

例子:

运行流程 蟒蛇 -C 打印'你好,世界!' 别名= myproc的  
#获取结果对象          
$ {result} = 获取流程结果 在myproc      
应该是平等的 $ {} result.rc $ {0}      
应该是平等的 $ {} result.stdout 你好,世界!      
应该是空的 $ {} result.stderr        
#获取一个属性          
$ {stdout} = 获取流程结果 在myproc 标准输出=真    
应该是平等的 $ {}标准输出 你好,世界!      
#多个属性          
$ {}标准输出 $ {stderr} = 获取流程结果 在myproc 标准输出= YES 标准错误= YES
应该是平等的 $ {}标准输出 你好,世界!      
应该是空的 $ {}标准错误        

虽然获取先前执行的进程的结果通常很方便,但此关键字的主要用例是通过远程库接口返回结果。远程接口不支持返回整个结果对象,但可以毫无问题地返回各个属性。

机器人框架2.8.2中的新功能。

流程正在运行 手柄=无

检查是否正在运行。

如果handle未给出,则使用当前活动进程

True如果进程仍在运行,False则返回。

加入命令行 * ARGS

将参数连接到一个命令行字符串。

在结果命令行中,字符串参数用空格分隔,包含空格的参数用引号括起来,可能的引号用反斜杠转义。

如果此关键字只给出一个参数,并且是一个像object这样的列表,那么将加入该列表的值。

例:

$ {cmd} = 加入命令行 - 选项 空格的价值
应该是平等的 $ {cmd},在 - 选择“带空格的价值”  

Robot Framework 2.9.2中的新功能。

流程应该运行 handle = None, error_message =进程未运行。

验证进程是否正在运行。

如果handle未给出,则使用当前活动进程

如果进程已停止,则会失败。

流程应该停止 handle = None, error_message =进程正在运行。

验证进程未运行。

如果handle未给出,则使用当前活动进程

如果进程仍在运行,则会失败。

运行流程 命令, *参数, **配置

运行一个进程并等待它完成。

command*arguments指定要执行的命令和传递给它的参数。有关更多详细信息,请参阅指定命令和参数

**configuration包含与启动进程和等待它们完成相关的其他配置。有关与启动进程相关的配置的详细信息,请参阅进程配置。有关等待进程配置包括timeouton_timeout具有相同的语义与参数等待过程的关键字。默认情况下没有超时,如果定义了超时,则超时的默认操作为terminate

返回包含有关执行信息的结果对象

请注意,*arguments必须使用反斜杠(例如name\=value)转义可能的等号,以避免它们被传入**configuration

例子:

$ {result} = 运行流程 蟒蛇 -C 打印'你好,世界!'
应该是平等的 $ {} result.stdout 你好,世界!    
$ {result} = 运行流程 $ {}命令 标准错误= STDOUT 超时= 10S
$ {result} = 运行流程 $ {}命令 超时= 1分钟 on_timeout =继续
$ {result} = 运行流程 java -Dname \ = value示例 壳=真 CWD = $ {实施例}

此关键字不会更改活动进程

timeouton_timeout参数是Robot Framework 2.8.4中的新功能。

发送信号进行处理 signal, handle = None, group = False

将给定发送signal到指定的进程。

如果handle未给出,则使用当前活动进程

可以将信号指定为整数作为信号名称。在后一种情况下,可以给出带或不带SIG前缀的名称,但名称区分大小写。例如,以下所有示例都发送信号INT (2)

发送信号进行处理 2   #发送到活动进程
发送信号进行处理 INT    
发送信号进行处理 SIGINT 在myproc #发送到命名进程

此关键字仅在类Unix机器上支持,而不在Windows上支持。支持哪些信号取决于系统。有关系统上现有信号的列表,请参阅与信号处理相关的Unix手册页(通常man signalman 7 signal)。

默认情况下,仅将信号发送到父进程,而不是发送给它启动的子进程。请注意,在shell中运行进程时,shell是父进程,它取决于系统shell是否将信号传播到实际启动的进程。

要将信号发送到整个进程组,group可以将参数设置为任何真值(请参阅布尔参数)。但是,Jython不支持此功能。

机器人框架2.8.2中的新功能。支持group参数是Robot Framework 2.8.5中的新功能。

拆分命令行 args, escaping = False

将命令行字符串拆分为参数列表。

字符串从空格中拆分,但用引号括起来的参数可能包含空格。如果escaping给出一个真值,则反斜杠被视为转义字符。它可以转义不带引号的空格,引号内的引号等,但在使用Windows路径时也需要使用双反斜杠。

例子:

@ {cmd} = 拆分命令行 - 选择“带空格的价值”
应该是真的 $ cmd == [' - 选项','带空格的值']  

Robot Framework 2.9.2中的新功能。

开始流程 命令, *参数, **配置

在后台启动新流程。

有关参数的详细信息,请参阅指定命令和参数以及进程配置 ;有关相关示例,请参阅Run Process关键字。

使启动的进程成为新的活动进程。返回一个标识符,该标识符可用作句柄以在需要时激活已启动的进程。

从Robot Framework 2.8.5开始,启动进程以便创建新的进程组。这允许向可能的子进程发送信号并终止它们。Jython一般也不支持这种方法,也不支持Windows上2.7之前的Python版本。

切换过程 处理

使指定的进程成为当前活动进程

该手柄可以是由返回的标识符开始处理alias明确地给它。

例:

开始流程 PROG1 别名=过程1
开始流程 PROG2 别名=过程2
#当前活动的进程是process2    
切换过程 过程1  
#now active进程是process1    
终止所有进程 杀=假

终止此库启动的所有仍在运行的进程。

此关键字可以在套件拆解或其他地方使用,以确保所有进程都已停止,

默认情况下尝试正常终止进程,但可以配置为立即强制终止它们。有关详细信息,请参阅此关键字在内部使用的终止进程

终止流程 handle = None, kill = False

优雅地或强制地停止该过程。

如果handle未给出,则使用当前活动进程

默认情况下,首先尝试正常停止该过程。如果进程在30秒内没有停止,或者kill参数被赋予真值,则(参见布尔参数)强制终止进程。停止最初启动的进程的所有子进程。

在终止进程后等待进程停止。返回一个结果对象,其中包含与Wait For Process类似的执行信息。

在类似Unix的机器上,使用TERM (15)信号和kill进行优雅终止KILL (9)。如果您只想发送这些信号中的任何一个而不等待进程停止,请使用发送信号来处理

在Windows上CTRL_BREAK_EVENT,使用Win32 API函数使用事件和查杀完成正常终止TerminateProcess()

例子:

$ {result} = 终止流程    
应该与整数相等 $ {} result.rc -15 #在Unix上
终止流程 在myproc 杀=真  

限制:

  • Windows上不支持Jython的优雅终止,也不支持2.7之前的Python版本。进程被杀死了。
  • Jython根本不支持停止整个进程组,也不支持Windows上2.7之前的Python版本。
  • 在Windows上强制kill只会停止主进程,而不是子进程。

如果终止失败以及返回结果对象,则自动终止进程是Robot Framework 2.8.2中的新功能。终止可能的子进程,包括CTRL_BREAK_EVENT在Windows上使用,是Robot Framework 2.8.5中的新功能。

等待过程 handle = None, timeout = None, on_timeout = continue

等待进程完成或达到给定的超时。

必须先使用“ 启动过程”启动等待过程。如果handle未给出,则使用当前活动进程

timeout定义等待进程的最长时间。它可以被赋予不同的时间格式由机器人框架的支持,例如4242 s1 minute 30 seconds

on_timeout定义超时发生时要执行的操作。可能的值和相应的操作在下表中说明。请注意,达到超时永远不会失败测试。

行动
继续 该过程保持运行(默认)。
终止 该过程优雅地终止。
该过程被强制停止。

有关如何终止和终止进程的详细信息,请参阅Terminate Process关键字。

如果进程在超时之前结束或者终止或终止,则此关键字返回包含有关执行信息的结果对象。如果进程保持运行,None则返回Python 。

例子:

#流程彻底结束      
$ {result} = 等待过程  
流程应该停止    
应该与整数相等 $ {} result.rc 0  
#进程没有结束      
$ {result} = 等待过程 超时= 42秒  
流程应该运行      
应该是平等的 $ {}结果 $ {无}  
#终止不结束的过程      
$ {result} = 等待过程 超时= 1分30秒 on_timeout =杀
流程应该停止      
应该与整数相等 $ {} result.rc -9  

timeout并且on_timeout是Robot Framework 2.8.2中的新功能。

共有15个关键字。 
Libdoc于2018-04-25 23:41:29 生成。

 

© 著作权归作者所有

共有 人打赏支持
海盐宝宝
粉丝 0
博文 25
码字总数 132622
作品 0
崇明
Robot Framework+SSHLibrary实现自动化运维质量检测

Robot Framework+SSHLibrary介绍 首先,介绍一下robotframework,oschina这么介绍: Robot Framework 是一个关键词驱动的自动测试框架。测试用例位于HTML或者TSV(以tab分隔值)文件,使用在测...

超爱fitnesse
2015/02/10
0
0
RobotFramework的相关命令参数的使用方法

RobotFramework的相关命令参数的使用方法(指定log的路径,重新运行上一轮Fail的case) Posted on 2015年1月29日 by Roy Xu RobotFramework 除了可以使用ride 运行以外,本身也提供了一些命令...

xxjbs001
2015/01/30
0
0
开源自动化测试解决方案 - AutoLine

AutoLine开源平台 AutoLine开源平台是一个开源自动化测试解决方案,基于 RobotFramework 进行二次开发,支持 RobotFramework 几乎所有的库。 特色 支持 Mac、Linux、Windows 平台 支持 Chro...

苦叶子
05/16
0
0
自动化测试集成解决方案 - AutoLink

介绍 AutoLink 开源自动化测试集成解决方案。 AutoLink 是 RobotFramework 的 web 集成开发环境。 AutoLink 支持 RobotFramework 语法高亮,自动提示等功能。 AutoLink 可以帮助你轻易的构建...

苦叶子
08/13
0
0
Robot Framework帮助文档详解

pybot是来执行robotframework的案例, pybot提供的参数有很多,详细的可以在控制台中执行pybot --help 这里介绍下常用的参数 -d outputdir --- 指定robotframework执行后的report目录为outpu...

江边望海
2015/11/06
0
0

没有更多内容

加载失败,请刷新页面

加载更多

Windows 下双 Python 开发环境配置

Windows 下双 Python 开发环境配置作者:老农民(刘启华)QQ: 46715422Email: 46715422@qq.com微信: 46715422 本人曾经在 Windows 下被两个版本环境折腾够呛,现在总结两个 Python...

新疆老农民
昨天
0
0
CentOS7全局安装composer

1. 下载composer-setup.php到当前目录 php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" 2. 安装 php composer-setup.php 3. 将composer设置成全局 mv c......

月夜中徘徊
昨天
1
0
20180920上课截图

小丑鱼00
昨天
1
0
基于TCP的远程服务调用

前言 上篇,分析了基于HTTP方式的RPC调用。本篇将在上篇的基础上,分析基于TCP方式的RPC调用。代码的整体思路是一致的,可以看作是在上篇功能上的扩展——即通信的方式。 代码:https://git...

MarvelCode
昨天
1
0
67:shell脚本介绍 | shell脚本结构 | 执行data命令用法 | shell脚本中变量

1、shell脚本介绍: shell是一种脚本语言和传统的开发语言相比,会比较简单: shell有自己语法,可以支持逻辑判断、循环等语法: 可以自定义函数,目的是减少重复的代码: shell是系统命令的集合...

芬野de博客
昨天
1
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部