• 一、安装SSHLibrary

  • 二.关键字

    • 1.与连接相关的

      • Open Connection
      • Get Connection
      • Get Connections
      • Switch  Connection
      • Close Connection
      • Close All Connections
      • Login
      • Login With Public Key
      • Set Client Configuration
      • Set Default  Configuration
      • Enable Ssh Logging
    • 2.与文件/目录相关的

      • 2.1 File Should Exist ,      File Should Not Exist,     Directory Should Exist ,    Directory Should Not Exist
      • 2.2 List Directory,   List Files In Directory ,    List Directories In Directory
      • 2.3 Put Directory ,Get Directory,Put File,Get File
    • 3.与读写执行相关的

      • Write
      • Write Bare
      • Write Until Expected Output
      • Read
      • Read Until
      • Read Until Prompt
      • Read Until Regexp
      • Execute Command
      • Start Command
      • Read Command Output

一、安装SSHLibrary

安装命令:pip install robotframework-sshlibrary

二.关键字

1.与连接相关的

Open Connection

用法: [ host | alias=None | port=22 | timeout=None | newline=None | prompt=None | term_type=None | width=None | height=None | path_separator=None | encoding=None ]

默认设置:timeout=3 seconds, newline=LF, prompt=None, loglevel=INFO, term_type=vt100, width=80,height=24, path_separator=/, encoding=UTF-8.其中,newline=LF/CRLF(\n,\r\n)

更改默认设置:

1.导入库时: Library SSHLibrary 10 seconds prompt=$

2.使用 Set Client Configuration/Set Default  Configuration

3.调用Open Connection时:

结果:

${con1} =index=1 path_separator=/ prompt=# width=80 newline= height=24 encoding=UTF-8 alias=backend host=10.69.140.112 timeout=3 seconds term_type=vt100 port=2222

Get Connection

用法:[ index_or_alias=None | index=False | host=False | alias=False | port=False | timeout=False | newline=False | prompt=False | term_type=False | width=False | height=False | encoding=False ]

1.获取connection的信息,如果调用时没有加 index_or_alias,返回当前的conection信息。

2.获取connection的特定属性信息,后边加属性名=非false/False字符串。

结果:

${con1} =index=1 path_separator=/ prompt=# width=80 newline= height=24 encoding=UTF-8 alias=backend host=10.69.140.112 timeout=3 seconds term_type=vt100 port=2222

${con2} = (2222, 3.0)

Get Connections

用法:没有输入值,获取所有打开的connection的信息

结果:

${con1} = index=1 path_separator=/ prompt=$ width=80 newline= height=24 encoding=UTF-8 alias=None host=10.69.144.140 timeout=3 seconds term_type=vt100 port=2222

${con2} = index=2 path_separator=/ prompt=# width=80 newline= height=24 encoding=UTF-8 alias=None host=10.69.144.139 timeout=3 seconds term_type=vt100 port=2222

Switch  Connection

用法:[ index_or_alias ],跳转到另一个active的connection。

Close Connection

用法:没有输入值,关闭当前的connection

Close All Connections

用法:没有输入值,关闭所有打开的connection

Login

用法:[ username | password | delay=0.5 seconds ]

Login With Public Key

用法:[ username | keyfile | password= | delay=0.5 seconds ]

Set Client Configuration

用法:[ timeout=None | newline=None | prompt=None | term_type=None | width=None | height=None | path_separator=None | encoding=None ],设置当前connection的配置

Set Default  Configuration

用法:[ timeout=None | newline=None | prompt=None | term_type=None | width=None | height=None | path_separator=None | encoding=None ],设置默认的配置,但不影响已经open的connection。

结果:

20180418 17:11:20.688 : INFO : 10.0

20180418 17:11:20.689 : INFO : 5.0

20180418 17:11:20.689 : INFO : 3.0

Enable Ssh Logging

用法:[ logfile ],将SSH协议的日志输出到本地给定的“日志文件”中。Enables logging of SSH protocol output to given `logfile`.

note:

1.文件存在时,文件内容被重写。

2.没有指定路径时,该文件在RF文件夹中。

2.与文件/目录相关的

2.1 File Should Exist ,      File Should Not Exist,     Directory Should Exist ,    Directory Should Not Exist

用法:[ path ] ,无返回值

2.2 List Directory,   List Files In Directory ,    List Directories In Directory

用法: [ path | pattern=None | absolute=False ],返回值为list。其中absolute=true ,返回绝对路径。

结果:

20180417 14:38:58.281 :  INFO : ${dir} = [u'cmd', u'service']

20180417 14:38:58.286 : INFO : ${dir2} = [u'/opt/ygomi/roadDB/jar/cmd', u'/opt/ygomi/roadDB/jar/service']

20180417 14:38:58.290 : INFO : ${dir3} = [u'service']

2.3 Put Directory ,Get Directory,Put File,Get File

Put File

用法:[ source | destination=. | mode=0744 | newline= ],无返回值,将文件从本地上传到远程机器上。

`newline` can be used to force the line break characters that are written to the remote files. Valid values are `LF` and `CRLF`.

Put Directory

用法:[ source | destination=. | mode=0744 | newline= | recursive=False ],将目录由本地上传到远程机器上。如果recursive=True,将子目录中文件也上传至远程机器上。

Get File

用法:[ source | destination=. ],从远程机器中下载文件

Get Directory

用法:[ source | destination=. | recursive=False ],从远程机器中下载目录。如果recursive=True,将子目录中文件也下载至本地上。

其中:/data 是docker的工作目录,/home/test 是本机目录

3.与读写执行相关的

Write

用法:[ text | loglevel=None ],将text写入到远端机器上并回车执行,返回值为text+换行符

loglevel:TRACE, DEBUG, INFO and WARN

Write Bare

用法:[ text ],将text写入到远端机器上,没有执行没有返回值。

结果:

关键字write 有返回值,执行命令后,用read读取终端输出时不会读取到输入的text;

关键字write bare没有返回值,执行命令后,用read读取终端输出时会读取到输入的text;

Write Until Expected Output

用法:[ text | expected | timeout | retry_interval | loglevel=None ],没有返回值,输入的 text 在设定的timeout内每隔retry_interval重复执行,直到终端输出的结果中包含期望的输出expected。

Read

用法: [ loglevel=None | delay=None ] ,读取终端输出

Read Until

用法:[ expected | loglevel=None ]

Read Until Prompt

用法:[ loglevel=None ]

Read Until Regexp

用法:[ regexp | loglevel=None ]

结果:

Execute Command

用法:[ command | return_stdout=True | return_stderr=False | return_rc=False ]

在远端机器上执行命令,并返回执行结果,需要等待command执行完才返回结果。

Start Command

用法:[command]

没有返回值,不等待command执行完成就返回。

Read Command Output

用法:[ return_stdout=True | return_stderr=False | return_rc=False ]

与Start Command配合使用,执行Read Command Output前至少要先执行一次Start Command关键字,返回最近一次start command的返回值。

结果:

${var} = [u'/home/roaddb', u'', 0]

Other:

1.For executing commands on the remote machine, there are two possibilities:

  • Execute Command and Start Command. The command is executed in a new shell on the remote machine, which means that possible changes to the environment (e.g. changing working directory, setting environment variables, etc.) are not visible to the subsequent keywords.

2.SSHLibrary 官方文档:http://robotframework.org/SSHLibrary/SSHLibrary.html#Importing

Robot Framework中SSHLibrary 学习与总结的更多相关文章

  1. Robot Framework中使用HttpLibrary教程and中文支持

    Robot Framework中使用and转参数时,默认不支持中文模式,如图场景: 会出现这种错误 FAIL : UnicodeDecodeError: 'ascii' codec can't dec ...

  2. Robot Framework测试框架学习笔记

    一.Robot Framework框架简介         Robot Framework是一种基于Python的可扩展关键字驱动自动化测试框架,通常用于端到端的可接收测试和可接收测试驱动的开发.可以 ...

  3. 虫师自动化测试robot Framework 框架的学习

    1.python关键字的定义 #coding=utf-8 def add(a,b): return a+b if __name__ == "__main__": c = add(4 ...

  4. Robot Framework中DatabaseLibrary应用

    DatabaseLibrary: 在RF的官网上,有DatabaseLibrary的下载链接,DatabaseLibrary有2个版本,Python和Java版.本人使用的是Python版本. 1.下 ...

  5. Robot Framework中经常用的第三方库的安装方法

    pip升级:python -m pip install --upgrade pip 一.安装robotframework-selenium2library,相当于python中的selenium    ...

  6. robot framework中的返回值

    1.若想要再setup中有返回值,给后续的操作使用 A)在setup的关键词中需要的返回值,设置为global variable或者suit variable:如下图:但是在编译器中,会报错,但是执行 ...

  7. robot framework中的timeout的关键词

    1.默认robotframework中的含有等待的关键词(如:Wait Until Element Is Enabled),未手动设置时默认该参数为5sec 2.关键词:sleep A)一般在调试的时 ...

  8. jenkins+gitlab+robot framework 中遇到的坑

    问题一:拉Git源代码时提示无权限 原来之前用的ssh密钥一直都是自己的用户生成的.其实在Jenkins系统使用的都是Jenkins这个系统帐号的. 解决方法: 切换到jenkins这个帐号下生成个新 ...

  9. Robot Framework中的未解之谜

    今天在写测试用例的时候偶然发现了一个问题: 一.看脚本逻辑上没有问题,但是在引用变量的时候不能成功引用,脚本截图如下: 这个是关键字A的截图,没有参数. 此时在case中引用${phonesign}和 ...

随机推荐

  1. shell进阶之tree、pstree、lsof命令详解

    一.tree命令详解: 主要功能是创建文件列表,将所有文件以树的形式列出来 -a 显示所有文件和目录. -A 使用ASNI绘图字符显示树状图而非以ASCII字符组合. -C 在文件和目录清单加上色彩, ...

  2. 11.4 iftop:动态显示网络接口流量信息

    iftop是一款实时流量监控工具,可用于监控TCP/IP连接等,必须以root用户的身份运行. 一般最小化安装系统都是没有这个命令的,需要使用yum命令额外安装,而且还要从epel源下载.   ift ...

  3. linux环境下时区无法设置(UTC无法更改为CST)的问题解决

    在进行linux下修改时区的时候 总是修改不了 修改成 Asia/Shanghai  但是 时区总是 +0000 却不是想要的+0800 按照网上的方法 A方法:tzselect:执行tzselect ...

  4. Docker之tomcat安装与部署项目

    docker安装tomcat  docker pull tomcat:8.5 等待... (1)正常的方式启动tomcat  docker run -d --name tomcat -p 80:808 ...

  5. [论文阅读笔记] Community aware random walk for network embedding

    [论文阅读笔记] Community aware random walk for network embedding 本文结构 解决问题 主要贡献 算法原理 参考文献 (1) 解决问题 先前许多算法都 ...

  6. Python Xpath语法

    Python    Xpath语法   一.选取节点 常用的路劲表达式: 表达式 描述 实例   nodename 选取nodename节点的所有子节点 xpath('//div') 选取了div节点 ...

  7. 永远的ace 实验七 团队作业4—团队项目需求建模与系统设计(1)

    项目 内容 课程班级博客链接 https://edu.cnblogs.com/campus/xbsf/2018CST/ 这个作业要求链接 https://www.cnblogs.com/nwnu-da ...

  8. Paddle Inference推理部署

    Paddle Inference推理部署 飞桨(PaddlePaddle)是集深度学习核心框架.工具组件和服务平台为一体的技术先进.功能完备的开源深度学习平台,已被中国企业广泛使用,深度契合企业应用需 ...

  9. GEMM与AutoKernel算子优化

    GEMM与AutoKernel算子优化 随着AI技术的快速发展,深度学习在各个领域得到了广泛应用.深度学习模型能否成功在终端落地应用,满足产品需求,一个关键的指标就是神经网络模型的推理性能.一大波算法 ...

  10. [NOIP1998 提高组] 拼数

    题目描述 设有 n 个正整数​ a1-an,将它们联接成一排,相邻数字首尾相接,组成一个最大的整数. 输入格式 第一行有一个整数,表示数字个数 n. 第二行有 n 个整数,表示给出的 n 个整数 a_ ...