0

我正在尝试登录到那里运行应用程序的数据库服务器。我可以毫无问题地登录,但是当我尝试在服务器上登录工作目录时,它会在登录后显示默认目录,而不是我更改的目录。

整个测试用例如下所示:

*** Settings ***
Library  SSHLibrary

*** Variables ***
${IP}  IP
${user}  user
${password}  password
*** Test Cases ***
CMD
    Open connection  ${IP}
    login  ${user}  ${password}
    execute command  cd gtms/bin
    ${pwd}  execute commanrd  pwd
    log  ${pwd}

我希望在使用 pwd 时获得有关我所在目录的信息,但它不起作用。我在LOG中得到这个:

KEYWORD BuiltIn . Log ${pwd}
Documentation:  
Logs the given message with the given level.
Start / End / Elapsed:  20170807 16:07:14.266 / 20170807 16:07:14.267 /         
00:00:00.001
16:07:14.267    INFO    /home/ollie

谁能告诉我我做错了什么?

提前致谢。

4

1 回答 1

0

Execute Command总是在新的 shell 中运行指定的命令——因此cd第一次调用pwd中的 这实际上是其文档中的示例:

The command is always executed in a new shell. Thus possible changes to the environment (e.g. changing working directory) are not visible to the later keywords:
${pwd}= Execute Command pwd
Should Be Equal ${pwd}  /home/johndoe
Execute Command cd /tmp 
${pwd}= Execute Command pwd
Should Be Equal ${pwd}  /home/johndoe

为了实现你想要的,只需链接目标命令,并执行一次:

${output}=    Execute Command  cd gtms/bin; pwd
Log    ${output}    # will log the output of the executed command(s) - in this case, pwd
于 2017-08-09T09:32:30.427 回答