使用 Robot Framework 4.0 是否可以将值从 .body 传入和传出到 python 脚本以及从 python 脚本到 .body 测试套件? [英] With Robot Framework 4.0 is it possible to get values in and out from .body into python script and from python script into .body test suite?

查看:46
本文介绍了使用 Robot Framework 4.0 是否可以将值从 .body 传入和传出到 python 脚本以及从 python 脚本到 .body 测试套件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

bot.body.create_keyword('创建列表', args=['a', 'b', 'c'],assign=['@{list}'])bot.body.create_for(flavor='IN', variables=['${x}'], values=['@{list}'])bot.body.create_keyword('log', args=['${x}'])

如何从该关键字中获取值 @list 并将其放入 python 脚本中,但无需在另一个 python 脚本中创建新的关键字.像这样的例子:

list = bot.body.create_keyword('创建列表', args=['a', 'b', 'c'],assign=['@{list}'])print(list) # 这将在控制台而不是在 output.xml 和执行顺序中打印

解决方案

恐怕你不能这样做.问题是您正在以编程方式创建测试用例,您只是定义了一个步骤 Create List 但它在那个点没有执行,所以没有创建列表,没有执行上下文.>

create_keyword 函数返回关键字对象,而不是内部机器人框架关键字的返回值.同样,这里没有执行,当您调用 suite.run() 时将创建列表.

您可以尝试使用侦听器或 Log To Console,但这两者也会在执行期间被调用.

bot.body.create_keyword('Create List', args=['a', 'b', 'c'], assign=['@{list}'])
bot.body.create_for(flavor='IN', variables=['${x}'], values=['@{list}'])
bot.body.create_keyword('log', args=['${x}'])

How to get value @list out of this keyword and into python script but without creating new keyword in another python script. example like this:

list = bot.body.create_keyword('Create List', args=['a', 'b', 'c'], assign=['@{list}'])
print(list) # and this will print in console and not in output.xml and in the order of execution 

解决方案

I am afraid you cannot do this. The problem is that you are creating a test case programmatically, you just define a step Create List but it is not executed at that point, so the list is not created, there is no execution context.

The create_keyword function returns the keyword object not the return value of the inner Robot Framework keyword. Again that is not executed here, the list will be created when you call the suite.run().

You could try with a listener maybe or Log To Console but both of these will be invoked during execution as well.

这篇关于使用 Robot Framework 4.0 是否可以将值从 .body 传入和传出到 python 脚本以及从 python 脚本到 .body 测试套件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆