简体   繁体   English

在机器人框架中使用 python 脚本

[英]Use python script in robot framework

Please help to understand.请帮助理解。

I have script (SplitModule.py) :我有脚本(SplitModule.py):

from robot.api.deco import keyword

@keyword('Split Function')
def splitfunction(string):
    print "atata"
    new_list = string.split(",")
    return new_list

And robot framework script test.txt :和机器人框架脚本 test.txt :

*** Settings ***
Library           DiffLibrary
Library           String
Library           OperatingSystem
Library           Collections
Library       SplitModule.py

*** Test Cases ***
Example of calling a python keyword that calls a robot keyword
    Split Function ${services}

But I have a problem with function, there is out :但我的功能有问题,有:

============================================================================== Robot ============================================================================== Robot.Check Services ============================================================================== Example of calling a python keyword that calls a robot keyword ================================================== ============================ 机器人 ==================== ================================================== ======== Robot.Check 服务 ======================================== ====================================== 调用机器人关键字的python关键字示例
| | FAIL |失败 | No keyword with name 'Split Function ${services}' found.未找到名称为“拆分函数 ${services}”的关键字。 ------------------------------------------------------------------------------ Robot.Check Services -------------------------------------------------- ---------------------------- Robot.Check 服务
| | FAIL |失败 | 1 critical test, 0 passed, 1 failed 1 test total, 0 passed, 1 failed ============================================================================== Robot 1 个关键测试,0 个通过,1 个失败 总共 1 个测试,0 个通过,1 个失败 ================================ ============================================== 机器人
| | FAIL |失败 | 1 critical test, 0 passed, 1 failed 1 test total, 0 passed, 1 failed ============================================================================== Output: /opt/robot/logs/output.xml Log: /opt/robot/logs/log.html Report: /opt/robot/logs/report.html 1 个关键测试,0 个通过,1 个失败 总共 1 个测试,0 个通过,1 个失败 ================================ ============================================== 输出:/opt /robot/logs/output.xml 日志:/opt/robot/logs/log.html 报告:/opt/robot/logs/report.html

What's the problem?有什么问题? thanks谢谢

Read what the error message is telling you:阅读错误消息告诉您的内容:

No keyword with name 'Split Function ${services}' found.未找到名称为“拆分函数 ${services}”的关键字。

It thinks the test is trying to call the keyword Split Function ${services} .它认为测试试图调用关键字Split Function ${services} You don't have a keyword with that name.您没有具有该名称的关键字。 What you do have is a keyword named Split Function which takes an argument.拥有的是一个名为Split Function的关键字,它接受一个参数。 Therefore, you need to use the proper syntax for passing the argument to the keyword.因此,您需要使用正确的语法将参数传递给关键字。

In other words, you need two or more spaces between the keyword and the argument:换句话说,关键字和参数之间需要两个或多个空格:

Split Function  ${services}  # need at least two spaces before $

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM