Discussion:
[Cucumber] How to handle multiple things to be checked?
(too old to reply)
Christian Baumann
2018-03-12 10:24:29 UTC
Permalink
Raw Message
Hi all,

I have couple of scenarios, where I want to check multiple things, like eg

*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product
*And* the description of the product should be correct
*And* the price should be correct
*And* I should be able to add the product to the shopping card

While this is not an issue when testing manually, I see problems when
automating:
Assuming the automated execution fails, I donÂŽt know immediately which of
the conditions hasnÂŽt been satisfied, and I need to dig into the logs to
find out.
Also, when eg. the price is not correct, itÂŽs not checked of the product
can be added to the card.

I could write 4 different scenarios, each of them just checking for one
single assumptions:

*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product

*Given* I am logged in to the system
*When* I open a product page
*Then* the description of the product should be correct

*...*

...but that would mean quite some duplication...

Any advice on how to solve this?

Many Thanks & Best Regards,
Christian
--
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-03-13 13:20:13 UTC
Permalink
Raw Message
Basically these type of issues have as a root cause the amount of control
you have over the source system and specifically, the source data.

The real solution is to gain control over your data and use the Given step
as data setup where you insert a product into the database that meets the
criteria for the test you wish to execute. Only with true control over your
source data, can you write robust automated tests that will not give you
false negatives on the functionality. How you wrestle this control is very
much down to the system under test, but it is needed one way or the other.

What condition is not met is in fact less relevant, as they are in the same
test. You see, tests cannot pass "a bit" or fail "somewhat" in the
automation world. It is super binairy. A cucumber scenario is either passed
or failed (yeahyeah, skipped) and the fact that you add all four of the
asserts (image, description, etc) to a scenario means all these four need
to be met unless a test is considered failed. If you think that each assert
is valid by itself, set it apart.

You can prevent some duplication by using the "Background"
https://github.com/cucumber/cucumber/wiki/Background as a setup.
Post by Christian Baumann
Hi all,
I have couple of scenarios, where I want to check multiple things, like eg
*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product
*And* the description of the product should be correct
*And* the price should be correct
*And* I should be able to add the product to the shopping card
While this is not an issue when testing manually, I see problems when
Assuming the automated execution fails, I donÂŽt know immediately which of
the conditions hasnÂŽt been satisfied, and I need to dig into the logs to
find out.
Also, when eg. the price is not correct, itÂŽs not checked of the product
can be added to the card.
I could write 4 different scenarios, each of them just checking for one
*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product
*Given* I am logged in to the system
*When* I open a product page
*Then* the description of the product should be correct
*...*
...but that would mean quite some duplication...
Any advice on how to solve this?
Many Thanks & Best Regards,
Christian
--
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.
Christian Baumann
2018-03-13 14:55:32 UTC
Permalink
Raw Message
Hi Koen,

thanks for your answer.

The real solution is to gain control over your data and use the Given step
Post by Koen Prins
as data setup where you insert a product into the database that meets the
criteria for the test you wish to execute. Only with true control over your
source data, can you write robust automated tests that will not give you
false negatives on the functionality. How you wrestle this control is very
much down to the system under test, but it is needed one way or the other.
Well understood, although I donÂŽt see how this is related to my question?

What condition is not met is in fact less relevant, as they are in the same
Post by Koen Prins
test. You see, tests cannot pass "a bit" or fail "somewhat" in the
automation world. It is super binairy. A cucumber scenario is either passed
or failed (yeahyeah, skipped) and the fact that you add all four of the
asserts (image, description, etc) to a scenario means all these four need
to be met unless a test is considered failed. If you think that each assert
is valid by itself, set it apart.
So what youÂŽre saying is, that I want to verify that the product is
displayed correctly (all aspects of it, including picture, description,
...), so if that fails, it doesnÂŽt matter so much for what reason, right?
Thanks for that perspective, didnÂŽt see it like that yet, but will conider
it for sure.

Best,
Christian
Post by Koen Prins
Basically these type of issues have as a root cause the amount of control
you have over the source system and specifically, the source data.
The real solution is to gain control over your data and use the Given step
as data setup where you insert a product into the database that meets the
criteria for the test you wish to execute. Only with true control over your
source data, can you write robust automated tests that will not give you
false negatives on the functionality. How you wrestle this control is very
much down to the system under test, but it is needed one way or the other.
What condition is not met is in fact less relevant, as they are in the
same test. You see, tests cannot pass "a bit" or fail "somewhat" in the
automation world. It is super binairy. A cucumber scenario is either passed
or failed (yeahyeah, skipped) and the fact that you add all four of the
asserts (image, description, etc) to a scenario means all these four need
to be met unless a test is considered failed. If you think that each assert
is valid by itself, set it apart.
You can prevent some duplication by using the "Background"
https://github.com/cucumber/cucumber/wiki/Background as a setup.
Post by Christian Baumann
Hi all,
I have couple of scenarios, where I want to check multiple things, like eg
*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product
*And* the description of the product should be correct
*And* the price should be correct
*And* I should be able to add the product to the shopping card
While this is not an issue when testing manually, I see problems when
Assuming the automated execution fails, I donÂŽt know immediately which of
the conditions hasnÂŽt been satisfied, and I need to dig into the logs to
find out.
Also, when eg. the price is not correct, itÂŽs not checked of the product
can be added to the card.
I could write 4 different scenarios, each of them just checking for one
*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product
*Given* I am logged in to the system
*When* I open a product page
*Then* the description of the product should be correct
*...*
...but that would mean quite some duplication...
Any advice on how to solve this?
Many Thanks & Best Regards,
Christian
--
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.
Andrew Premdas
2018-03-16 03:25:49 UTC
Permalink
Raw Message
As far as your scenario is concerned I think

Given there is a product
When I view the product
Then I should see the product

captures the business intent, that the system can show products.

Now what you can do is delegate the nitty gritty of what seeing the product
is to something else. So if we implement the Then as

Then 'I should see the product' do
should_see_product @product # we set @product in the Given
end

We can write a helper method in a module that looks for all the things that
make up a product e.g.

module ProductStepHelper
def should_see_product(product
should_see_product_image(product)
should_see_product_price(product)
...
# add other things when required
end
end
World ProductStepHelper

Some points here about putting the details in the scenario
- they provide little benefit for a quite a bit of work.
- you have to add new steps every time a product is expanded to have other
things, increasing cost of change for small changes
- the scenario quickly becomes difficult to read and maintain
- the details are about HOW you are displaying a product, you should always
'push the how down' out of scenarios if you can

HTH

Andrew
Post by Christian Baumann
Hi Koen,
thanks for your answer.
The real solution is to gain control over your data and use the Given step
Post by Koen Prins
as data setup where you insert a product into the database that meets the
criteria for the test you wish to execute. Only with true control over your
source data, can you write robust automated tests that will not give you
false negatives on the functionality. How you wrestle this control is very
much down to the system under test, but it is needed one way or the other.
Well understood, although I donÂŽt see how this is related to my question?
What condition is not met is in fact less relevant, as they are in the
Post by Koen Prins
same test. You see, tests cannot pass "a bit" or fail "somewhat" in the
automation world. It is super binairy. A cucumber scenario is either passed
or failed (yeahyeah, skipped) and the fact that you add all four of the
asserts (image, description, etc) to a scenario means all these four need
to be met unless a test is considered failed. If you think that each assert
is valid by itself, set it apart.
So what youÂŽre saying is, that I want to verify that the product is
displayed correctly (all aspects of it, including picture, description,
...), so if that fails, it doesnÂŽt matter so much for what reason, right?
Thanks for that perspective, didnÂŽt see it like that yet, but will conider
it for sure.
Best,
Christian
Post by Koen Prins
Basically these type of issues have as a root cause the amount of control
you have over the source system and specifically, the source data.
The real solution is to gain control over your data and use the Given
step as data setup where you insert a product into the database that meets
the criteria for the test you wish to execute. Only with true control over
your source data, can you write robust automated tests that will not give
you false negatives on the functionality. How you wrestle this control is
very much down to the system under test, but it is needed one way or the
other.
What condition is not met is in fact less relevant, as they are in the
same test. You see, tests cannot pass "a bit" or fail "somewhat" in the
automation world. It is super binairy. A cucumber scenario is either passed
or failed (yeahyeah, skipped) and the fact that you add all four of the
asserts (image, description, etc) to a scenario means all these four need
to be met unless a test is considered failed. If you think that each assert
is valid by itself, set it apart.
You can prevent some duplication by using the "Background"
https://github.com/cucumber/cucumber/wiki/Background as a setup.
Post by Christian Baumann
Hi all,
I have couple of scenarios, where I want to check multiple things, like eg
*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product
*And* the description of the product should be correct
*And* the price should be correct
*And* I should be able to add the product to the shopping card
While this is not an issue when testing manually, I see problems when
Assuming the automated execution fails, I donÂŽt know immediately which
of the conditions hasnÂŽt been satisfied, and I need to dig into the logs to
find out.
Also, when eg. the price is not correct, itÂŽs not checked of the product
can be added to the card.
I could write 4 different scenarios, each of them just checking for one
*Given* I am logged in to the system
*When* I open a product page
*Then* I should see an image of the product
*Given* I am logged in to the system
*When* I open a product page
*Then* the description of the product should be correct
*...*
...but that would mean quite some duplication...
Any advice on how to solve this?
Many Thanks & Best Regards,
Christian
--
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.
--
------------------------
Andrew Premdas
blog.andrew.premdas.org
--
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...