Robotframework SSH隧道与Robot框架SSH库
我正在使用Robot框架SSH库实现自动化 我需要使用Robot框架建立到远程机器的SSH隧道,然后在远程机器上执行一组测试 RF SSH库似乎不支持此功能 有人能告诉我还有什么其他的选择吗Robotframework SSH隧道与Robot框架SSH库,robotframework,Robotframework,我正在使用Robot框架SSH库实现自动化 我需要使用Robot框架建立到远程机器的SSH隧道,然后在远程机器上执行一组测试 RF SSH库似乎不支持此功能 有人能告诉我还有什么其他的选择吗 谢谢大家! 您可以使用Robot框架打开SSH连接,复制测试文件,运行它们并将结果复制回来 您将需要两个文件,第一个是ssh.txt *** Settings *** Library SSHLibrary Suite Setup Open Connection And Log
谢谢大家! 您可以使用Robot框架打开SSH连接,复制测试文件,运行它们并将结果复制回来 您将需要两个文件,第一个是ssh.txt
*** Settings ***
Library SSHLibrary
Suite Setup Open Connection And Log In
Suite Teardown Copy And Delete Files And Close Connections
*** Variables ***
${HOST} your.server.here
${USERNAME} username
${PASSWORD} password
*** Testcases ***
Run Tests on remote server
Put File real-test.txt
Run Test In Server real-test.txt
Sleep 1s
*** Keywords ***
Open Connection And Log In
Open Connection ${HOST}
Login ${USERNAME} ${PASSWORD}
Copy And Delete Files And Close Connections
Copy Results From Server
Clean Up Server real-text.txt
Close All Connections
Run Test In Server
[Arguments] ${filename}
${rc}= Execute Command pybot ${filename} return_stdout=False return_rc=True
Should Be Equal As Numbers ${rc} 0
Copy Results From Server
GetFile log.html
GetFile output.xml
GetFile report.html
Clean Up Server
[Arguments] ${filename}
Write rm log.html
Write rm output.xml
Write rm report.html
Write rm ${filename}
第二个文件是real-test所在的位置,real-test.txt:
*** Settings ***
Library OperatingSystem
*** Testcases ***
Test 1
FileShouldExist real-test.txt
通过指定输出文件来运行此操作,以避免从服务器复制日志文件时发生文件名冲突:
pybot-o conn.xml-r conn.html-l connlog.html ssh.txt
我最近做了类似的事情,但用Python创建了功能,然后将其作为关键字导入Robot 它的jist是: 在
SSHTunnel.py
中:
from sshtunnel import SSHTunnelForwarder
(other imports)
class SSHTunnel:
def create_ssh_tunnel(self):
ssh_server = SSHTunnelForwarder(
(host, int(port)),
ssh_username=username,
ssh_password=pass,
remote_bind_address=(remote_bind_host, int(remote_bind_port))
)
ssh_server.start()
def stop_ssh_tunnel(self):
ssh_server.stop()
现在,您将SSHTunnel.py
文件添加到Robot库中,并在测试用例的开头调用关键字Create SSH Tunnel
(也可以在测试设置或套件设置中),最后调用关键字Stop SSH Tunnel
希望对您有所帮助。您可以借助“本地端口转发”功能实现这一点 参考号:
ssh-4-L::目的地\u端口>username@jump_box.com
ssh-4-l50025:10.122.56.45:23anishg@jumpbox.teski.com
telnet localhost
telnet本地主机50025
在这里,当会话打开时,您可以像在目标服务器上工作一样执行命令
在Robot中,这也可以通过以下方式实现:
ssh-4-l50025:10.122.56.45:23anishg@jumpbox.teski.com
机器人代码:
***测试用例***
端口转发
启动进程./sample.sh shell=True#端口已打开
正在执行控制台SHELL日志
Telnet.Open Connection localhost port=50025#与destn服务器中一样正常运行
注意:我使用跳转框,因为我无法从测试实例访问目标服务器