开发者

How do I re-run a cucumber scenario outline with different parameters?

开发者 https://www.devze.com 2023-04-03 01:23 出处:网络
I have a cucumber scenario outline for testing a webservice that is similar to: Scenario Outline: Check the limit functionality

I have a cucumber scenario outline for testing a webservice that is similar to:

Scenario Outline: Check the limit functionality
  When I GET "/api/activity-schedule-items.xml" with parameters {<filter>}
  Then the xml attribute "total-count" is "<count>"

  Scenarios:
  | filter        | count |
  | 'limit' => 0  | 0     |
  | 'limit' => 2  | 2     |
  | 'limit' => 2  | 2     |
  | 'limit' => -1 | 15    |

which works fine, however I want to re-run the same scenario outline and scenarios for each of our webservices. Basically, I would like to add another Scenarios block like:

Scenario Outline: Check the limit functionality
  When I GET "<api>" with parameters {<filter>}
  Then the xml attribute "total-count" is "<count>"

  Scenarios:
  | filter        | count |
开发者_如何学编程  | 'limit' => 0  | 0     |
  | 'limit' => 2  | 2     |
  | 'limit' => 2  | 2     |
  | 'limit' => -1 | 15    |

  Scenarios:
  | api                              |
  | /api/activity-schedule-items.xml |
  | /api/activity-schedules.xml      |
  | /api/tasks.xml                   |

and have cucumber do a cross join between the two tables.

Even better would be a way to specify the "api" table in a way to have it apply to all scenarios in the feature.

Is there a way to implement this in cucumber?


Cucumber doesn't really support 'iteration' over scenarios. Your only 'native' option really is to do the 'cross join' yourself, by hand.

Where I work we have a very similar situation, and we run Cucumber 8 separate times and then aggregate the results, which requires a lot of plumbing and the performance is terrible.

I recently put together a gem intended to help with this type of problem, it's very rough and I haven't personally used it in anger, but it may help you, take a look at https://github.com/jmerrifield/cuke_iterations. I'd be happy to help you get up and running with it if you think it might be of use.


you can use table , but table only iterates single step over number of rows , so I converted two steps into one. code is as follows :

Scenario Outline: Check the limit functionality
  When I GET api with following parameters Then the xml attribute "total-count" is as follows
    | 'limit' => 0  | 0     | <api> |
    | 'limit' => 2  | 2     | <api> |
    | 'limit' => 2  | 2     | <api> | 
    | 'limit' => -1 | 15    | <api> |

    Examples:
     |         api                     |
     |/api/activity-schedule-items.xml |
     |/api/activity-schedules.xml      |
     |/api/tasks.xml                   |

Second is conventional way which you might be using

Scenario Outline: Check the limit functionality
  When I GET "<api>" with parameters {<filter>}
  Then the xml attribute "total-count" is "<count>"

    Examples:
    | filter        | count |           api                    |
    | 'limit' => 0  | 0     | /api/activity-schedule-items.xml |
    | 'limit' => 2  | 2     | /api/activity-schedule-items.xml |
    | 'limit' => 2  | 2     | /api/activity-schedule-items.xml |
    | 'limit' => -1 | 15    | /api/activity-schedule-items.xml |
    | 'limit' => 0  | 0     | /api/activity-schedules.xml      |
    | 'limit' => 2  | 2     | /api/activity-schedules.xml      |
    | 'limit' => 2  | 2     | /api/activity-schedules.xml      |
    | 'limit' => -1 | 15    | /api/activity-schedules.xml      |
    | 'limit' => 0  | 0     | /api/tasks.xml                 |
    | 'limit' => 2  | 2     | /api/tasks.xml                     |
    | 'limit' => 2  | 2     | /api/tasks.xml                     |
    | 'limit' => -1 | 15    | /api/tasks.xml                     |
0

精彩评论

暂无评论...
验证码 换一张
取 消