我正在尝试在Robotframework中创建一个自定义关键字,该关键字应该运行一个.vbs文件,然后将该关键字添加到测试摘要中,以便该.vbs文件应在每个测试用例完成后运行。但是,当我运行代码时,出现错误“关键字'Common.CallVBS'预期为0参数,得到1”。我是Python和编码的新手,无法弄清楚。
Import subprocess
def call_vbs(scriptpath):
try:
subprocess.call('cscript.exe ' + scriptpath)
return "PASS"
except:
return "FAIL"
*** Settings ***
Documentation It holds common functionalities related to all the Test Cases
Library SeleniumLibrary
Library ../CustomLibraries/Calling_VBS.py
*** Variables ***
${scriptpath} ${EXECDIR}\\CustomLibraries\\saving.vbs
*** Keywords ***
CallVBS
${success} call_vbs ${scriptpath}
Run Keyword If "${success}"=="FAIL" FAIL Not able to launch VBS file
log ${scriptpath}
答案 0 :(得分:2)
这不是与库中的call_vbs
关键字链接,而是与Robot文件中的CallVBS
关键字链接。
调用CallVBS
关键字时,您不应添加任何参数。或者,像这样在CallVBS关键字中添加一个arugments行:
CallVBS
[Arguments] ${argument1}
${success} call_vbs ${scriptpath}
Run Keyword If "${success}"=="FAIL" FAIL Not able to launch VBS file
log ${scriptpath}
此外,我建议您将python关键字包装在一个类中,如下所示:
Import subprocess
class Custom(object):
def call_vbs(self, scriptpath):
try:
subprocess.call('cscript.exe ' + scriptpath)
return "PASS"
except:
return "FAIL"