【问题标题】:Step data in BDD using python and differencess between Scenario Outline使用python的BDD中的步骤数据以及Scenario Outline之间的差异
【发布时间】:2019-09-11 13:33:07
【问题描述】:

步骤数据如何工作?例如,我有这部分代码

Scenario: some scenario
  Given a set of specific users
     | name      | department  |
     | jon       | Beer Cans   |
     | adda      | Silly Walks |
     | Two-Lumps | Silly Walks |
 When we count the number of people in each department
 Then we will find two people in "Silly Walks"
  But we will find one person in "Beer Cans"

和实施

@given('a set of specific users')
def step_impl(context):
    for row in context.table:
        model.add_user(name=row['name'], department=row['department'])

这对我不起作用。

@given 步骤是做什么的?我将不胜感激更多使用步骤和功能的示例


好的,这段代码和大纲场景下的代码一样吗?

Scenario: Update user detail
    Given I login to update user details
    When I update following user detail "<item_name>" and "<item_detail>"
      | item_name | item_detail           |
      | address   | Dragon street  Brazil |
      | contact   | 001 85208520 00       |
      | name      | Uncle scrooge         |
      | surname   | Mcduck                |
    Then User detail update should be successful

@when(u'I update following user detail "{item_name}" and "{item_detail}"')
def step_impl(context, item_name, item_detail):
    print('Following user details are being updated')
    for row in context.table:
        context.temp_item_name = row['item_name']
        context.temp_item_detail = row['item_detail']
        print('======  ' + context.temp_item_name + '  ' + context.temp_item_detail)


Scenario Outline: Update user detail
    Given I login to update user details
    When I update following user detail "<item_name>" and "<item_detail>"
    Then User detail update should be successful

  Examples: 
      | item_name | item_detail           |
      | address   | Dragon street  Brazil |
      | contact   | 001 85208520 00       |
      | name      | Uncle scrooge         |
      | surname   | Mcduck                |


【问题讨论】:

  • 您遇到错误了吗?什么是错误和堆栈跟踪?或者它只是行为不正确,如果是,您希望它如何行为,请提供有关它当前行为方式的更多信息。
  • add_user 找不到参考错误
  • 我不清楚问题是什么。您有两组不同的代码。你说你得到一个错误。哪组代码错了?有什么错误?哪一行代码触发了错误?请使用此信息更新您的问题。

标签: python bdd python-behave


【解决方案1】:

使用http://behave.github.io/behave.example/tutorials/tutorial06.html Github 存储库还包含可执行代码。查看 Git 存储库并运行它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-17
    • 2019-10-17
    相关资源
    最近更新 更多