用例中关键字如下:
测试123 ${ssh_channel} &{ap_message}[ip] ${ap_ssh_pwd}
关键字python脚本部分
@keyword("测试123")
def wac_ssh_to_ap(self,ssh_channel,ip,ap_pwd,port=22):
print("entering")
result=self.ssh_excute_cmd()
time.sleep(1)
#for i in range(0,10):
while 1:
print("循环中...")
if "yes/no" in result:
result=self.ssh_excute_cmd()
time.sleep(1)
elif "(none)#" in result:
result=self.ssh_excute_cmd()
time.sleep(1)
elif "Sundray-AP" in result:
return
运行时,大概率会卡住,但是不会报错,(小概率会执行成功),一直在运行中,也不会打印entering ,不会打印循环中...,仿佛没有进入函数,和函数没什么关系。
多次尝试,发现将while循环去掉就可以执行成功,因此这里规避的方法,将while循环改成for循环。
@keyword("wac连接ap")
def wac_ssh_to_ap(self,ssh_channel,ip,ap_pwd,port=22):
print("entering")
result=self.ssh_excute_cmd(ssh_channel,"ssh -p%s admin@%s\n"%(port,ip))
time.sleep(1)
for i in range(0,10):
print("循环中...")
if "yes/no" in result:
result=self.ssh_excute_cmd(ssh_channel,"yes\n")
time.sleep(1)
elif "(none)#" in result:
result=self.ssh_excute_cmd(ssh_channel,"aadmin\n")
time.sleep(1)
elif "password" in result or "Password" in result:
result=self.ssh_excute_cmd(ssh_channel,"%s\n"%ap_pwd)
time.sleep(1)
elif "Sundray-AP" in result:
print("登录成功")
return
else:
result=self.ssh_excute_cmd(ssh_channel,"\n")
time.sleep(1)
原因未知,但是建议robotframework中尽量避免使用while循环。