Discussion:
[Cucumber] Passing an example value between different step deffs
(too old to reply)
matthew thomas
2018-05-24 07:15:33 UTC
Permalink
Raw Message
I'm unsure of the way I should be tackling this scenario.

I have a Scenario Outline where one step is as follows:

When I make a payment by "<Payment Method>"

Then I have my example table as follows:

Examples:
|Payment Method|
|One off credit card|
|Direct debit bank account|
|Direct debit credit card |

Now in the step def code I can handle this just fine for the step def which
reads as @When("^I make a payment by \"([^\"]*)\"$") which contains my
various if statements to handle each of the examples.

But I then have a generic line at the end of my feature which reads
something like "And payment is completed". For this step I'd like to run
some queries on the source system to ensure payment went through as
expected. But there are different outcomes to test depending on what
example is being run.

So whats the best way to pass an example value into another step def? Or am
I thinking about this the wrong way?
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
aslak hellesoy
2018-05-24 09:50:30 UTC
Permalink
Raw Message
Post by matthew thomas
I'm unsure of the way I should be tackling this scenario.
When I make a payment by "<Payment Method>"
|Payment Method|
|One off credit card|
|Direct debit bank account|
|Direct debit credit card |
Now in the step def code I can handle this just fine for the step def
my various if statements to handle each of the examples.
But I then have a generic line at the end of my feature which reads
something like "And payment is completed". For this step I'd like to run
some queries on the source system to ensure payment went through as
expected. But there are different outcomes to test depending on what
example is being run.
So whats the best way to pass an example value into another step def? Or
am I thinking about this the wrong way?
Don't try to shoehorn what's different scenarios into a Scenario Outline.

Write independent Scenarios.

HTH,
Aslak
Post by matthew thomas
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
matthew thomas
2018-05-24 09:59:12 UTC
Permalink
Raw Message
Thanks.

So I’m thinking you’re saying we should have different scenarios, for each
payment method then, yes?

These will be identically worded scenarios with the exception of the
payment method. Although the underlying code that verifies the payment will
be different. I just thought this would be a bit of a tedious read for a
business user who sees 3 almost identical scenarios if you see what I’m
saying.
Post by aslak hellesoy
Post by matthew thomas
I'm unsure of the way I should be tackling this scenario.
When I make a payment by "<Payment Method>"
|Payment Method|
|One off credit card|
|Direct debit bank account|
|Direct debit credit card |
Now in the step def code I can handle this just fine for the step def
my various if statements to handle each of the examples.
But I then have a generic line at the end of my feature which reads
something like "And payment is completed". For this step I'd like to run
some queries on the source system to ensure payment went through as
expected. But there are different outcomes to test depending on what
example is being run.
So whats the best way to pass an example value into another step def? Or
am I thinking about this the wrong way?
Don't try to shoehorn what's different scenarios into a Scenario Outline.
Write independent Scenarios.
HTH,
Aslak
Post by matthew thomas
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
aslak hellesoy
2018-05-24 10:06:47 UTC
Permalink
Raw Message
Post by matthew thomas
Thanks.
So I’m thinking you’re saying we should have different scenarios, for each
payment method then, yes?
Correct
Post by matthew thomas
These will be identically worded scenarios with the exception of the
payment method. Although the underlying code that verifies the payment will
be different. I just thought this would be a bit of a tedious read for a
business user who sees 3 almost identical scenarios if you see what I’m
saying.
You said "But there are different outcomes to test depending on what
example is being run."

Does the business care about what those different outcomes are? If so, you
could be more explicit about what they are in the When steps.
In this case the scenarios would be rather different.

If the business doesn't care about the different outcomes, and are happy
with "And payment is completed", you could keep using a Scenario Outline.
The stepdef verifying completed payment would call a different method based
on what card was used. Simply store the card type in an instance variable
in your When step.
Post by matthew thomas
Post by aslak hellesoy
Post by matthew thomas
I'm unsure of the way I should be tackling this scenario.
When I make a payment by "<Payment Method>"
|Payment Method|
|One off credit card|
|Direct debit bank account|
|Direct debit credit card |
Now in the step def code I can handle this just fine for the step def
my various if statements to handle each of the examples.
But I then have a generic line at the end of my feature which reads
something like "And payment is completed". For this step I'd like to run
some queries on the source system to ensure payment went through as
expected. But there are different outcomes to test depending on what
example is being run.
So whats the best way to pass an example value into another step def? Or
am I thinking about this the wrong way?
Don't try to shoehorn what's different scenarios into a Scenario Outline.
Write independent Scenarios.
HTH,
Aslak
Post by matthew thomas
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google
Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Koen Prins
2018-05-24 10:26:11 UTC
Permalink
Raw Message
My thought was to use the payment type as a variable in the payment type
step
"And payment by "<Payment Method>" is processed"
Aslaks instance variable is probably better tho.
Post by aslak hellesoy
Post by matthew thomas
Thanks.
So I’m thinking you’re saying we should have different scenarios, for
each payment method then, yes?
Correct
Post by matthew thomas
These will be identically worded scenarios with the exception of the
payment method. Although the underlying code that verifies the payment will
be different. I just thought this would be a bit of a tedious read for a
business user who sees 3 almost identical scenarios if you see what I’m
saying.
You said "But there are different outcomes to test depending on what
example is being run."
Does the business care about what those different outcomes are? If so, you
could be more explicit about what they are in the When steps.
In this case the scenarios would be rather different.
If the business doesn't care about the different outcomes, and are happy
with "And payment is completed", you could keep using a Scenario Outline.
The stepdef verifying completed payment would call a different method
based on what card was used. Simply store the card type in an instance
variable in your When step.
Post by matthew thomas
Post by aslak hellesoy
Post by matthew thomas
I'm unsure of the way I should be tackling this scenario.
When I make a payment by "<Payment Method>"
|Payment Method|
|One off credit card|
|Direct debit bank account|
|Direct debit credit card |
Now in the step def code I can handle this just fine for the step def
my various if statements to handle each of the examples.
But I then have a generic line at the end of my feature which reads
something like "And payment is completed". For this step I'd like to run
some queries on the source system to ensure payment went through as
expected. But there are different outcomes to test depending on what
example is being run.
So whats the best way to pass an example value into another step def?
Or am I thinking about this the wrong way?
Don't try to shoehorn what's different scenarios into a Scenario Outline.
Write independent Scenarios.
HTH,
Aslak
Post by matthew thomas
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google
Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google
Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
matthew thomas
2018-05-24 10:34:51 UTC
Permalink
Raw Message
Yep. Business don’t care about the different outcomes as they’re just
technical differences so instance variable it is. I’ll do some digging on
how to implement this as not had the need before.

Thanks for the input guys. Really helpful!
Post by Koen Prins
My thought was to use the payment type as a variable in the payment type
step
"And payment by "<Payment Method>" is processed"
Aslaks instance variable is probably better tho.
Post by aslak hellesoy
Post by matthew thomas
Thanks.
So I’m thinking you’re saying we should have different scenarios, for
each payment method then, yes?
Correct
Post by matthew thomas
These will be identically worded scenarios with the exception of the
payment method. Although the underlying code that verifies the payment will
be different. I just thought this would be a bit of a tedious read for a
business user who sees 3 almost identical scenarios if you see what I’m
saying.
You said "But there are different outcomes to test depending on what
example is being run."
Does the business care about what those different outcomes are? If so,
you could be more explicit about what they are in the When steps.
In this case the scenarios would be rather different.
If the business doesn't care about the different outcomes, and are happy
with "And payment is completed", you could keep using a Scenario Outline.
The stepdef verifying completed payment would call a different method
based on what card was used. Simply store the card type in an instance
variable in your When step.
Post by matthew thomas
Post by aslak hellesoy
Post by matthew thomas
I'm unsure of the way I should be tackling this scenario.
When I make a payment by "<Payment Method>"
|Payment Method|
|One off credit card|
|Direct debit bank account|
|Direct debit credit card |
Now in the step def code I can handle this just fine for the step def
my various if statements to handle each of the examples.
But I then have a generic line at the end of my feature which reads
something like "And payment is completed". For this step I'd like to run
some queries on the source system to ensure payment went through as
expected. But there are different outcomes to test depending on what
example is being run.
So whats the best way to pass an example value into another step def?
Or am I thinking about this the wrong way?
Don't try to shoehorn what's different scenarios into a Scenario Outline.
Write independent Scenarios.
HTH,
Aslak
Post by matthew thomas
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google
Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google
Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google
Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an
For more options, visit https://groups.google.com/d/optout.
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...