Use behave tags to execute only a subcase of such tag

核能气质少年 提交于 2019-12-11 04:39:10

问题


I have the following scenario definition in a sample.feature file, with scenario with two sub-cases using the Examples syntax:

  @ninja
  Scenario Outline: this is a sample scenario
    Given ...
    And ...
    And ..
    When ...
    Then ...

    Examples:
      | param1 | param2 | param3 |
      |     10 |      4 |      9 | 
      |     20 |      8 |     23 |

I can use the tag ninja to execute only that scenario, among all the others defined in the sample.feature file, as follows:

$ behave sample.feature --tags=ninja
...
Scenario Outline: this is a sample scenario -- @1.1
...
Scenario Outline: this is a sample scenario -- @1.2
...

Note that behave "marks" each subcase execution, i.e. @1.1 and @1.2 in execution log.

I'd like to know if I can be even more "sharp" and use behave to execute only one (or a subset) of subcases of a given tag. I have tried the following, with no luck (i.e. both subcases are executes, not only the second one):

$ behave sample.feature --tags=ninja,1.2

Is that possible? Any help on how doing it, please?


回答1:


Yes, it is possible to execute only one row in a Scenario Outline (Examples), first is necessary to define a placeholder in the tag into the feature file, example:
@test.row<row.id> Reference in Behave

After, to execute:

behave example.feature -t @test.row1.2 -- run only the row: 2 with this tag.

Also it is posible create several examples, like this:

    Examples:
      | param1 | param2 | param3 |
      |     10 |      4 |      9 | 
      |     20 |      8 |     23 |
    Examples:
      | param1 | param2 | param3 |
      |     30 |     12 |      1 | 
      |     40 |     13 |     45 |
      |     50 |     14 |     49 | 
      |     60 |     15 |     13 |

And,

behave example.feature -t @test.row2.4 -- run only the row: 4 in the second examples with this tag:

      |     60 |     15 |     13 |


来源:https://stackoverflow.com/questions/45186323/use-behave-tags-to-execute-only-a-subcase-of-such-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!