我想将数据从场景1传递到场景2。是否存在内置方法?
scenario1:我正在生成具有详细信息的用户
scenarioa2:我想从scenario1中获取生成的用户名,并在后续步骤中使用
发布于 2018-06-26 00:03:55
您可以使用Behave的context对象在测试步骤之间存储数据。例如,假设您有两个场景:
Scenario: First one
# Some Given's and stuff
Then I am generating user with details
Scenario: Second one
# Some Given's and stuff
Then I fetch and use generated user details在steps/目录中的step实现文件中:
@then("I am generating user with details")
def step_impl(context):
context.user_details = function_to_generate_user_details()
@then("I fetch and use generated user details")
def step_impl(context):
function_to_do_something(context.user_details)请注意,您的步骤实现不必在同一文件中,因为Behave在使用功能文件时会搜索steps/目录中的所有文件。
发布于 2020-11-13 04:46:21
我认为与其处理行为逻辑,不如将数据保存在excel数据或任何文件中,然后在其他函数中解析这些数据。
https://stackoverflow.com/questions/51021969
复制相似问题