ssh和sftp的robot框架测试库
robotframework-sshlibrar的Python项目详细描述
Introduction
SSHLibrary是一个Robot Framework测试 ssh和sftp的库。项目位于GitHub 可以从PyPI找到下载。
sshlibary独立于操作系统,也支持python 2.7 作为Python3.4或更新版本。除了普通的Python解释器之外, 它也适用于Jython 2.7。
库有以下主要用途:
- 在远程计算机上执行命令,可以使用阻塞或 非阻塞行为。
- 在一个交互式的shell中进行写作和阅读。
- 通过sftp传输文件和目录。
Documentation
有关可用关键字和详细信息,请参见keyword documentation 关于图书馆的总体情况。
有关在Robot框架中使用测试库的一般信息,请参见 Robot Framework User Guide。
Installation
建议的安装方法是使用pip:
pip install --upgrade robotframework-sshlibrary
运行此命令还将安装最新的robot框架paramiko 以及scp版本。支持的paramiko最低版本是1.15.3,并且 支持的最低scp版本是0.13.0。 在安装 第一次。
使用最新版本的pip,可以直接从 GitHub存储库。要从主分支安装最新源,请使用 此命令:
pip install git+https://github.com/robotframework/SSHLibrary.git
或者,您可以从PyPI下载源发行版,提取 它,并根据您使用的 python或jython:
python setup.py install jython setup.py install
使用pip的一个好处是它自动安装scp,paramiko 和Cryptography模块(或者PyCrypto如果paramiko版本是<;2.0) sshlibary在python上需要的。
在Jython上,sshlibrary需要三读ssh-jar发行版。你需要下载 Trilead SSH JAR distribution并将其添加到类路径。
在windows操作系统上,当使用python版本<;3.0时,sshlibrary将 需要win_inet_pton。支持的最低win-inet版本是1.1.0。
对于创建ssh隧道,robotbackgroundlogger>;1.2也是一个要求。
Docker
在容器(如alpine linux)中安装sshlibrary时,有更多的依赖项 必须安装:gcc、make、openssl-dev、musl-dev和libffi-dev。这些 可以使用以下命令安装软件包:
apk add gcc make openssl-dev musl-dev libffi-dev
Usage
要在robot框架测试中使用sshlibrary,首先需要 与任何其他库一样使用库设置导入。
使用robot框架时,通常建议编写为 尽可能容易理解的测试。提供的关键字 图书馆的水平很低,最好是 使用robot框架的高级关键字编写测试 sshlibary关键字内部。下面的例子说明了这一点 其中将Open Connection和Login等sshlibary关键字分组 在一个更高级的关键字中,比如Open Connection And Log In。
*** Settings ***DocumentationThis example demonstrates executing a command on a remote machine ... and getting its output. ... ... Notice how connections are handled as part of the suite setup and ... teardown. This saves some time when executing several test cases.LibrarySSHLibrarySuite SetupOpen Connection And Log InSuite TeardownClose All Connections*** Variables *** ${HOST} localhost ${USERNAME} test ${PASSWORD} test*** Test Cases ***Execute Command And Verify Output [Documentation] Execute Command can be used to run commands on the remote machine. ... The keyword returns the standard output by default. ${output}= Execute Commandecho Hello SSHLibrary!Should Be Equal ${output} Hello SSHLibrary!*** Keywords ***Open Connection And Log InOpen Connection ${HOST} Login ${USERNAME} ${PASSWORD}
Support
如果提供的文档不够,则有各种支持论坛 可用:
- robotframework-users邮件列表
- #sshlibrary和#sshlibrary-dev通道 机器人框架Slack community
- sshlibraryissue tracker用于错误报告和具体增强 请求
- Other support forums包括付费支持