1

I have a request template that is used across multiple scenario outlines, and examples in each scenario outline differs.

for ex:
Scenario Outline: 1
* def query = { name: <name>}
---do something else---
Examples:
|name|
|bob|
|ram|

Scenario Outline: 2
* def query = { name:<name>}
---do something else---

Examples:
|name|
|eve|

How can I avoid duplicating query definition in each scenario outline? Defining it in background and reusing it in outline request is not dynamically building the request from the values in examples.

gayathri
  • 11
  • 2

1 Answers1

1

Personally I think you may be over-engineering things. Some amount of duplication is OK for tests - especially where it improves readability. Also see this answer: https://stackoverflow.com/a/54126724/143475

That said - you can switch to a loop data-driven style like this:

Scenario Outline: 1 
* table data = 
| name  |
| 'bob' |
| 'ram' |
* call read('second.feature') data

And in second.feature you can do this:

* def query = { name: '#(name)' }

If you want to avoid the second feature file, the only other option is this: https://stackoverflow.com/a/55192450/143475

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248