0

我目前正在使用 Eclipse 和 RED 插件在 Robot Framework 中开发测试用例,以在 Linux VM 上自动化测试用例。其中一个关键字的代码如下所示

**Check Auth Certificate** 
    [Documentation]    To Check Whether the Authentication certificate is present or not   
    Log    *** Needs to be implemented ***
    Send Command    pwd
    Send Command    cd /root/.ssh/
    Send Command    pwd
    ${fileExist}    File Should Exist    'mqtt-server.crt'

Send Command是一个自定义关键字,用于使用 Write & Read 关键字执行命令并记录结果。问题是 - 此位置存在一个文件 (mqtt-server.crt) - /root/.ssh/。从控制台输出中,我能够验证控件是否已到达所需文件夹中。但是,当执行来自 SSHLibrary- File Should Exist的关键字时,它会失败。我想验证文件夹中是否存在提到的文件,如果存在,则需要将其删除。控制台中的输出是

20210623 00:23:47.024 : INFO : *** Needs to be implemented ***
20210623 00:23:47.118 : INFO : pwd
20210623 00:23:48.120 : INFO : /root
[root@<host> ~]#
20210623 00:23:48.121 : INFO : Response After :: pwd - -> /root
[root@<host> ~]# 
20210623 00:23:48.226 : INFO : cd /root/.ssh/
20210623 00:23:49.227 : INFO : [root@<host> .ssh]#
20210623 00:23:49.227 : INFO : ${resultCommand} = [root@<host> .ssh]# 
20210623 00:23:49.228 : INFO : Response After :: cd /root/.ssh/ - -> [root@<host> .ssh]# 
20210623 00:23:49.320 : INFO : pwd
20210623 00:23:50.321 : INFO : /root/.ssh
20210623 00:23:50.321 : INFO : ${resultCommand} = /root/.ssh
20210623 00:23:50.408 : INFO : ls
20210623 00:23:50.408 : INFO : ${responseCommand} = ls
20210623 00:23:52.411 : INFO : known_hosts  mqtt-server.crt
20210623 00:23:52.411 : INFO : ${resultCommand} = known_hosts  mqtt-server.crt
[root@<host> .ssh]# 
20210623 00:23:52.413 : INFO : Response After :: ls - -> known_hosts  mqtt-server.crt
[root@<host> .ssh]# 
20210623 00:23:52.413 : INFO : ${listOfFiles} = None
**20210623 00:23:52.415 : DEBUG : [chan 1] Max packet in: 32768 bytes
20210623 00:23:52.529 : INFO : [chan 1] Opened sftp connection (server version 3)
20210623 00:23:52.529 : DEBUG : [chan 1] normalize(b'.')
20210623 00:23:52.570 : DEBUG : [chan 1] stat(b'mqtt-server.crt')
20210623 00:23:52.603 : FAIL : File 'mqtt-server.crt' does not exist.
20210623 00:23:52.604 : DEBUG : Traceback (most recent call last):
  File "D:\Program Files (x86)\Python\Python39\Lib\site-packages\SSHLibrary\library.py", line 1809, in file_should_exist
    raise AssertionError("File '%s' does not exist." % path)**
Ending test: Demo-Telemetry.TestCases.ConnectToJumpServer.First Jump

您能否告诉我,需要更改哪些内容才能使其正常工作或如何解决此问题。

4

1 回答 1

2

在“文件应该存在”关键字中使用绝对路径。或使用“移动目录”关键字。我认为如果您更改自定义关键字中的目录,该目录不会更改为操作系统库。

${fileExist}    File Should Exist    /root/.ssh/mqtt-server.crt
于 2021-06-23T05:37:26.870 回答