我尝试使用在那里运行的应用程序登录数据库服务器。我可以毫无问题地登录,但是当我尝试在服务器上记录工作目录时,它会在登录后显示默认目录,而不是我更改的目录。
整个测试用例如下所示:
*** 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
谁能告诉我我做错了什么?
提前致谢。
答案 0 :(得分:0)
Execute Command
始终在新shell中运行指定的命令 - 因此第一次调用中的cd
不会保留,第二次调用中pwd
可见。这实际上是documentation:
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