RobotFramework使用SSHLibrary

本文介绍了如何在RobotFramework中使用SSHLibrary模块进行自动化测试,包括安装、加载库的方法及各种关键字的用法,如连接操作、命令执行等。

RobotFramework使用SSHLibrary

liqiang3@sugon.com

【参考文档】:

  1. 【1】 https://pypi.org/project/robotframework-sshlibrary/#introduction
  2. 【2】 https://github.com/robotframework/SSHLibrary

        在RobtoFramework自动化测试中,安装robotframework-sshlibrary模块后,即可使用SSH相关关键字,连接控制Linux或Windows完成自动化测试工作。

1. 安装加载

1.1 安装

pip install robotframework-sshlibrary

1.2 RobotFramework加载

       在Add Library时,输入“SSHLibrary”,注意大小写,即可在RobotFramework中加载robotframework-sshlibrary库。

2. 关键字

2.1 连接相关

Open Connection

Opens a new SSH connection to the given host and port.

Close Connection

Closes the current connection.

Switch Connection

Switches the active connection by index or alias.

Close All Connections

Closes all open connections.

Get Connection

RobotFramework中 中SSHLibrary学习与总结 学习与总结 ⼀、安装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
Robotframework】列表List的常⽤操作 1. Create List # 新建⼀个list变量 @{list} create list aa bb # 为list追加数据 同Append To List @{list} create list @{list} cc 打印list时,使⽤log many:log many @{list} 若⽤log打印,则写成:log ${list} 打印string时,使⽤log: log ${string} 以下关于list的操作类关键字,是在collections库中的,使⽤前,需要引⼊该库 2 Append To List-为list追加数据 ⽐如create list中的⽰例,也可以使⽤: # 新建⼀个list变量 @{list} create list aa bb # 为list追加数据 同Append To List Append To List @{list} cc 3 Get Slice From List-切⽚ 可以获取list的某⼀段⼦list,从两端截取或从中间截取 ⽰例: #list的下标从0开始 @{list} Create List lilei hanmeimei liming liliang liming # 获取从index=1及之后的数据 ${fromlist} Get Slice From List ${list} 1 # 获取从index=1~2的数据,不包括第3个 ${fromtolist} Get Slice From List ${list} 1 3 4 Remove Duplicates-去重 ⽰例: @{list} Create List lilei hanmeimei liming liliang liming # list去重并检查不包含重复数据 ${listnew} Remove Duplicates ${list} List Should Not Contain Duplicates ${listnew} 在log中会打印出来去掉了⼏个重复数据: 20201015 18:46:47.647 : INFO : 1 duplicate removed. 5 List Should Contain Sub List-包含⼦list ⽰例: @{list} Create List lilei hanmeimei liming liliang liming @{sublist} Create List lilei hanmeimei # 是否包含⼦list List Should Contain Sub List ${list} ${sublist} 6 List Should Not Contain Duplicates-判断不存在重复 ⽰例,去重后,list就不存在重复数据了,最后⼀⾏可执⾏通过: @{list} Create List lilei hanmeimei liming liliang liming ${listnew} Remove Duplicates ${list} List Should Not Contain Duplicates ${listnew} 7 Lists Should Be Equal-判断list相等 注意:@{list}是robot提供的语法,python并没有@{},只有${},所以要⽐较两个@{list},需要把@{list},直接写成英⽂dollar ${list}进 ⾏对⽐ ⽰例: @{list} Create List lilei hanmeimei liming liliang liming Remove From List ${list} 0 @{list1} Create List hanmeimei liming liliang liming Lists Should Be Equal ${list} ${list1} Remove Values From List ${list} liming @{list2} Create List hanmeimei liliang Lists Should Be Equal ${list} ${list2} 如果list转换成了string,也可以使⽤should be equal来做相等判断 8 Remove (Values) From List-删除list中某个值 Remove From List:按照index删除,⼀次删除1个 Remove Values From List:按照value值删除,⼀次可删除多个 ⽰例如2.6 9 Sort List–升序排序 对list做升序排序,⽰例: @{list} Create L
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值