How to get the output from a kyword using robot.api?

只谈情不闲聊 提交于 2021-01-24 09:31:05

问题


I hope you can help me, I am quite stuck with this issue :(

I am trying to create all the tests using the robot api with python, I followed the example in the documentation, but I need to capture the output from a keyword and I dont find how can I do it

I tried as usual in rf-ride syntax:

 test.keywords.create('${greps}=  grep file', args=['log.txt', 'url:',  'encoding_errors=ignore'])

It says: No keyword with name '${grep}= grep file' found.

I tried:

output = test.keywords.create('grep file', args=['log.txt', 'url:',  'encoding_errors=ignore'])

but the variable output is having just the keyword name, not the output from kw

I dont know where to look for more info, all the examples are creating kw which dont return any value...


回答1:


The call to test.keywords.create(...) doesn't call the keyword, it merely creates one to be called later. If you want the results to be assigned to a variable, use the assign attribute when calling create. This argument takes a list of variable names.

For example, given this line in plain text format:

${greps}=    grep file    log.txt    url:    encoding_errors=ignore

... you would create it like this using the API:

test.keywords.create('grep file', 
                     args=['log.txt', 'url:',  'encoding_errors=ignore'],
                     assign=['${greps}'])


来源:https://stackoverflow.com/questions/38973452/how-to-get-the-output-from-a-kyword-using-robot-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!