希望我能理解你的问题:)
那这个呢:
将步骤:“当我将速度设置为速度时”更改为
当我将速度设置为 {speed} 时,它需要一个参数。
在您的功能中:当我测试速度 500 次并且在那一步中:当我测试速度 500 次时:
==> 创建一个 for 循环 500 次:
=====>选择随机速度
=====>使用 context.execute_steps 和 format(speed) 执行其他步骤
你必须解决这个问题,因为它需要 unicode,而不是整数。
==> 但是,有人可能同意 Szabo Peter 的观点,即为此使用 gherkin/python-behave 有点尴尬:)。这有点搞砸了目的。此外,即使按照我的想法,它可能会做得更优雅。
你可以在这里找到一些好东西:https:
//jenisys.github.io/behave.example/tutorials/tutorial08.html Cheerz
所以在评论后编辑:(在编辑和编写这个例子之后,它看起来比我想象的更傻,所以是的:不要为此使用行为。例如:
功能:测试功能场景:给定的测试场景当我以随机速度测试应用程序 500 次时打开应用程序,然后控制台说它完成了
脚步:
@given(u'我打开应用')
=>def I_open_the_app(上下文):
==>#code 打开应用程序
@when(u'我以随机速度测试应用程序 500 次')
=>def I_test_the_app_500_times_at_random_speed(上下文):
==>对于范围内的时间(1,500):
===>random_speed = random.randint(min_speed,max_speed)
===>context.execute_steps(u'''when I play at {speed}'''.format(speed=str(random_speed))
@when(u'我用 {speed}')
=>def I_play_at(上下文,速度)
==>play_at_speed(int(速度))
@then(u'控制台说它完成了')
=>def the_console_says_it_is_done ==>print('完成')