简体   繁体   English

从功能文件读取数据表-Pytest-bdd

[英]Reading Data tables from feature file - Pytest-bdd

I am new to pytest-bdd framework. 我是pytest-bdd框架的新手。

Below is sample feature file Content: 以下是示例功能文件内容:

Scenario Outline: Google multiple search request

  Given I want to search in Google
    When I search for '<search_request>'
    Then I should see link to '<search_result>'

  Examples:
  | search_request | search_result |
  | Pytest BDD | Python BDD - Behaviour driven development framework |
  |  Cucumber | Cucumber |

The sample python file generated from the pytest-bdd: # coding=utf-8 """example.feature feature tests.""" 从pytest-bdd生成的示例python文件:#coding = utf-8“”“” example.feature功能测试。“”“

from pytest_bdd import (
    given,
    scenario,
    then,
    when,
) 

 @scenario('example.feature', 'Google multiple search request')
def test_google_multiple_search_request():
    """Google multiple search request."""


@given('I want to search in Google')
def i_want_to_search_in_google():
    """I want to search in Google."""


@when('I search for '<search_request>'')
def i_search_for_search_request():
    """I search for '<search_request>'."""


@then('I should see link to '<search_result>'

Examples:
| search_request | search_result |
| Pytest BDD | Python BDD - Behaviour driven development framework |
|  Cucumber | Cucumber |
|  Cucumber2 | Cucumber2 |')
def i_should_see_link_to_search_resultexamples_search_request__search_result__pytest_bdd__python_bdd__behaviour_driven_development_framework___cucumber__cucumber___cucumber2__cucumber2_():
    """I should see link to '<search_result>'

Examples:
| search_request | search_result |
| Pytest BDD | Python BDD - Behaviour driven development framework |
|  Cucumber | Cucumber |
|  Cucumber2 | Cucumber2 |."""

Is there a way in pytest-bdd where it recognizes the example data set provided in the feature file and converts into valid python file like it generates the skeleton code pytest-bdd中是否有一种方法可以识别功能文件中提供的示例数据集并转换为有效的python文件,就像生成骨架代码一样
Or We need to code it manually to accept the input data in the feature file 或者我们需要手动对其进行编码,以接受特征文件中的输入数据

Any help much appreciated. 任何帮助,不胜感激。

Regards, Sanjay BS 此致Sanjay BS

It looks like something went very wrong with the code generation. 看起来代码生成有些错误。 The following should not be there: 以下内容不应该存在:

@then('I should see link to '' @then('我应该看到指向''的链接

Examples: | 示例: search_request | search_request | search_result | search_result | | | Pytest BDD | Pytest BDD | Python BDD - Behaviour driven development framework | Python BDD-行为驱动的开发框架| | | Cucumber | 黄瓜 Cucumber | 黄瓜 | | Cucumber2 | 黄瓜2 | Cucumber2 |') 黄瓜2 |')

First let's fix the feature file (those single quotes are not required): 首先让我们修复功能文件(不需要单引号):

Scenario Outline: Google multiple search request 方案大纲: Google多个搜索请求

Given I want to search in Google 鉴于我想在Google中搜索

When I search for <search_request> 我搜索<search_request>

Then I should see link to <search_result> 然后,我应该看到指向<search_result>的链接

Examples: 例子:

| | search_request | search_request | search_result | search_result |

| | Pytest BDD | Pytest BDD | Python BDD - Behaviour driven development framework | Python BDD-行为驱动的开发框架|

| | Cucumber | 黄瓜 Cucumber | 黄瓜

This is how you pass a variable from your example table to the step function: 这是将变量从示例表传递到step函数的方式:

@when('I search for <search_request>')
def i_search_for_search_request(search_request):
    """I search for <search_request>."""
    print(search_request)

Hope it helps! 希望能帮助到你!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM