Discussion:
[Cucumber] [Cucumber JVM] No After Step hook
(too old to reply)
j***@public.gmane.org
2013-01-15 18:45:24 UTC
Permalink
To Whom it may concern,

Hi, I am new to this message board and wanted to make a feature request (if
agreed upon).

Basically, I thought it would be nice to have an @AfterStep hook like there
is in Ruby that can take a Scenario object (if needed for special logic).
Essentially, I want a test to be able to see if something already exists,
and then continue executing if it doesn't, or skip all other steps if it
does (data setup features). I think I can possibly do this another way, but
as a feature request I think it is sound...
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
aslak hellesoy
2013-01-15 19:01:32 UTC
Permalink
Post by j***@public.gmane.org
To Whom it may concern,
Hi, I am new to this message board and wanted to make a feature request
(if agreed upon).
there is in Ruby that can take a Scenario object (if needed for special
logic).
AfterStep is one of thos Cucumber-Ruby features that I have never used
myself, and I can't remember a good reason to use it. I'd rather not add
features that I think encourage bad practices, and my current thinking is
that AfterStep does just that.
Post by j***@public.gmane.org
Essentially, I want a test to be able to see if something already exists,
and then continue executing if it doesn't, or skip all other steps if it
does (data setup features).
Wouldn't it be better if the various steps themselves made a check to
decide whether or not they should do something? Perhaps you could give a
concrete example illustrating what you mean?

Cheers,
Aslak
Post by j***@public.gmane.org
I think I can possibly do this another way, but as a feature request I
think it is sound...
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group, send email to
https://groups.google.com/d/forum/cukes?hl=en
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
j***@public.gmane.org
2013-01-15 19:09:29 UTC
Permalink
Typically I would skip steps in a scenario which had a Given step like this:

Scenario: Setup Data User
Given the "data user" doesn't exisit
When I navigate to the create user page
And I perform a "create data user" form submit
Then the "data user" should exist

If the Given step fails (data user already exists) I want to skip the rest
of the steps in this scenario so I don't create duplicate data. Its not a
fail, because its a setup script and should only fail if data cannot be
created as intended.

This is how I would create test data sets to reduce run times of tests (so
the data is already there and doesn't need to be created at run time)
Post by aslak hellesoy
Post by j***@public.gmane.org
To Whom it may concern,
Hi, I am new to this message board and wanted to make a feature request
(if agreed upon).
there is in Ruby that can take a Scenario object (if needed for special
logic).
AfterStep is one of thos Cucumber-Ruby features that I have never used
myself, and I can't remember a good reason to use it. I'd rather not add
features that I think encourage bad practices, and my current thinking is
that AfterStep does just that.
Post by j***@public.gmane.org
Essentially, I want a test to be able to see if something already exists,
and then continue executing if it doesn't, or skip all other steps if it
does (data setup features).
Wouldn't it be better if the various steps themselves made a check to
decide whether or not they should do something? Perhaps you could give a
concrete example illustrating what you mean?
Cheers,
Aslak
Post by j***@public.gmane.org
I think I can possibly do this another way, but as a feature request I
think it is sound...
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group, send email to
group at https://groups.google.com/d/forum/cukes?hl=en
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
aslak hellesoy
2013-01-15 19:51:48 UTC
Permalink
Post by j***@public.gmane.org
Scenario: Setup Data User
Given the "data user" doesn't exisit
It sounds like you are checking whether or not "data user" exists here.
Don't do that.

Instead, delete any "data user" users.
Post by j***@public.gmane.org
When I navigate to the create user page
And I perform a "create data user" form submit
Then the "data user" should exist
If the Given step fails (data user already exists) I want to skip the rest
of the steps in this scenario so I don't create duplicate data. Its not a
fail, because its a setup script and should only fail if data cannot be
created as intended.
This is how I would create test data sets to reduce run times of tests (so
the data is already there and doesn't need to be created at run time)
It sounds like your scenarios are coupled, i.e. data created in one
scenario may seep into the next. This causes brittle scenarios with a lot
of conditional logic. You should avoid this.

How to do this is discussed thoroughly in the Cucumber Book.

Aslak
Post by j***@public.gmane.org
Post by aslak hellesoy
Post by j***@public.gmane.org
To Whom it may concern,
Hi, I am new to this message board and wanted to make a feature request
(if agreed upon).
there is in Ruby that can take a Scenario object (if needed for special
logic).
AfterStep is one of thos Cucumber-Ruby features that I have never used
myself, and I can't remember a good reason to use it. I'd rather not add
features that I think encourage bad practices, and my current thinking is
that AfterStep does just that.
Post by j***@public.gmane.org
Essentially, I want a test to be able to see if something already
exists, and then continue executing if it doesn't, or skip all other steps
if it does (data setup features).
Wouldn't it be better if the various steps themselves made a check to
decide whether or not they should do something? Perhaps you could give a
concrete example illustrating what you mean?
Cheers,
Aslak
Post by j***@public.gmane.org
I think I can possibly do this another way, but as a feature request I
think it is sound...
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/**
Posting_style#Interleaved_**style<http://en.wikipedia.org/wiki/Posting_style#Interleaved_style>
3) If you have a question, don't reply to an existing message. Start a
new topic instead.
You received this message because you are subscribed to the Google
Groups Cukes group. To post to this group, send email to
https://groups.google.com/d/**forum/cukes?hl=en<https://groups.google.com/d/forum/cukes?hl=en>
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group, send email to
https://groups.google.com/d/forum/cukes?hl=en
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Jason Smiley
2013-01-15 20:15:04 UTC
Permalink
So these are my thoughts about using test data:

1) You can create the data on the fly for the test to use
2) You can query for existing test data to use
3) You can create test data once and have it always be used.

1 isn't ideal since it increases the run time and makes it so "creating the
test data" functionality a dependency for the test.

2 isn't ideal since the scenario I wish to test may not always exist
already in the system. Additionally, depending on the complexity of the DB,
the query requests can time out (I have had this happen)

3 is the solution I came up with - See if I can create the data manually on
prod and let it sync down or have a setup feature run its thing before
tests are called. If the data is already there, do nothing, otherwise
create it. I can make the tests recreate the data though instead of
checking if it is there first.

If you are saying the Cucumber Book mentions some 4th way for writing tests
I would love to hear it...
Post by aslak hellesoy
Post by j***@public.gmane.org
Scenario: Setup Data User
Given the "data user" doesn't exisit
It sounds like you are checking whether or not "data user" exists here.
Don't do that.
Instead, delete any "data user" users.
Post by j***@public.gmane.org
When I navigate to the create user page
And I perform a "create data user" form submit
Then the "data user" should exist
If the Given step fails (data user already exists) I want to skip the
rest of the steps in this scenario so I don't create duplicate data. Its
not a fail, because its a setup script and should only fail if data cannot
be created as intended.
This is how I would create test data sets to reduce run times of tests
(so the data is already there and doesn't need to be created at run time)
It sounds like your scenarios are coupled, i.e. data created in one
scenario may seep into the next. This causes brittle scenarios with a lot
of conditional logic. You should avoid this.
How to do this is discussed thoroughly in the Cucumber Book.
Aslak
Post by j***@public.gmane.org
Post by aslak hellesoy
Post by j***@public.gmane.org
To Whom it may concern,
Hi, I am new to this message board and wanted to make a feature request
(if agreed upon).
there is in Ruby that can take a Scenario object (if needed for special
logic).
AfterStep is one of thos Cucumber-Ruby features that I have never used
myself, and I can't remember a good reason to use it. I'd rather not add
features that I think encourage bad practices, and my current thinking is
that AfterStep does just that.
Post by j***@public.gmane.org
Essentially, I want a test to be able to see if something already
exists, and then continue executing if it doesn't, or skip all other steps
if it does (data setup features).
Wouldn't it be better if the various steps themselves made a check to
decide whether or not they should do something? Perhaps you could give a
concrete example illustrating what you mean?
Cheers,
Aslak
Post by j***@public.gmane.org
I think I can possibly do this another way, but as a feature request I
think it is sound...
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/**
Posting_style#Interleaved_**style<http://en.wikipedia.org/wiki/Posting_style#Interleaved_style>
3) If you have a question, don't reply to an existing message. Start a
new topic instead.
You received this message because you are subscribed to the Google
Groups Cukes group. To post to this group, send email to
https://groups.google.com/d/**forum/cukes?hl=en<https://groups.google.com/d/forum/cukes?hl=en>
--
-- Rules --
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
You received this message because you are subscribed to the Google Groups
To unsubscribe from this group, send email to
group at https://groups.google.com/d/forum/cukes?hl=en
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
George Dinwiddie
2013-01-15 20:31:14 UTC
Permalink
Jason,
Post by Jason Smiley
1) You can create the data on the fly for the test to use
2) You can query for existing test data to use
3) You can create test data once and have it always be used.
1 isn't ideal since it increases the run time and makes it so "creating
the test data" functionality a dependency for the test.
In practice, I find this is best. Yes, it can take time. There are
strategies for bulk loading a known database state that may or may not
apply to your situation. This is, however, the most robust approach, in
my experience. (And that experience predates Cucumber; I learned this
using DbUnit under JUnit.)
Post by Jason Smiley
2 isn't ideal since the scenario I wish to test may not always exist
already in the system. Additionally, depending on the complexity of the
DB, the query requests can time out (I have had this happen)
3 is the solution I came up with - See if I can create the data manually
on prod and let it sync down or have a setup feature run its thing
before tests are called. If the data is already there, do nothing,
otherwise create it. I can make the tests recreate the data though
instead of checking if it is there first.
You can do this in a Before hook. I think you'll find this also
expensive in time, as well as being less reliable in assuring the
desired known starting state. It's easy to make your setup get
complicated enough to fool yourself. I tend to avoid conditional logic
in test code, with the exception of "if this exists, delete it" code.

- George
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
Tom Dunstan
2013-03-25 23:19:42 UTC
Permalink
Post by j***@public.gmane.org
is in Ruby that can take a Scenario object (if needed for special logic).
<snip>

Perhaps you could give a concrete example illustrating what you mean?
I have a case where an AfterStep would be extremely useful. I have cucumber
driving Geb driving WebDriver to test end-to-end interactions in our code.
I'm trying to debug a bug in the chrome driver (
https://code.google.com/p/chromedriver/issues/detail?id=201) and it would
be really helpful to be able to insert a configurable delay after each step
so that I can see when it gets triggered. As it is I'll have to go and add
a sleep after each of the steps around where it happens, so that I can see
exactly where it gets triggered. Would be much easier to do in one place.

Cheers

Tom
--
-- Rules --

1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.

You received this message because you are subscribed to the Google Groups Cukes group. To post to this group, send email to cukes-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org To unsubscribe from this group, send email to cukes+***@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/cukes?hl=en
---
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Jason Smiley
2014-01-15 15:21:28 UTC
Permalink
Another good reason for before/after step hooks is for error handle.

//perform some step
@AfterStep
public myAfterEveryStep(){
if(has404ErrorOnPage() || has500ErrorOnPage()){
*driver.navigate().refresh();*
}
}

Basically, I find myself having to copy and paste error recovery code on a
regular basis. It would be great if I could handle this in an afterStep
hook so I don't have to copy and paste my code everywhere (even if it is
only 3 lines). I see a lot of times the server just times out in my QA or
Stage ENV and refreshing the page would fix my issue (since there isn't any
actual bug in the code, just ENV isn't as stable as prod)
Post by Tom Dunstan
Post by j***@public.gmane.org
there is in Ruby that can take a Scenario object (if needed for special
logic).
<snip>
Perhaps you could give a concrete example illustrating what you mean?
I have a case where an AfterStep would be extremely useful. I have
cucumber driving Geb driving WebDriver to test end-to-end interactions in
our code. I'm trying to debug a bug in the chrome driver (
https://code.google.com/p/chromedriver/issues/detail?id=201) and it would
be really helpful to be able to insert a configurable delay after each step
so that I can see when it gets triggered. As it is I'll have to go and add
a sleep after each of the steps around where it happens, so that I can see
exactly where it gets triggered. Would be much easier to do in one place.
Cheers
Tom
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Oscar Rieken
2014-01-15 15:39:00 UTC
Permalink
Post by Jason Smiley
Another good reason for before/after step hooks is for error handle.
//perform some step
@AfterStep
public myAfterEveryStep(){
if(has404ErrorOnPage() || has500ErrorOnPage()){
*driver.navigate().refresh();*
}
}
Post by Jason Smiley
Basically, I find myself having to copy and paste error recovery code on a
regular basis. It would be great if I could handle this in an afterStep
hook so I don't have to copy and paste my code everywhere (even if it is
only 3 lines). I see a lot of times the server just times out in my QA or
Stage ENV and refreshing the page would fix my issue (since there isn't any
actual bug in the code, just ENV isn't as stable as prod)
Why not FIX the QA and Staging ENV instead of trying to work around what is
obviously and environmental problem in those environments? Solving the
actual problem is always better than trying working around it. you dont
know if your workaround is changing the results of your tests and giving
you false positives. It could be an actual performance issue in the site.
that you don't notice in prod because there is beefier hardware supporting
prod.
Post by Jason Smiley
Post by Tom Dunstan
Post by j***@public.gmane.org
there is in Ruby that can take a Scenario object (if needed for special
logic).
<snip>
Perhaps you could give a concrete example illustrating what you mean?
I have a case where an AfterStep would be extremely useful. I have
cucumber driving Geb driving WebDriver to test end-to-end interactions in
our code. I'm trying to debug a bug in the chrome driver (
https://code.google.com/p/chromedriver/issues/detail?id=201) and it
would be really helpful to be able to insert a configurable delay after
each step so that I can see when it gets triggered. As it is I'll have to
go and add a sleep after each of the steps around where it happens, so that
I can see exactly where it gets triggered. Would be much easier to do in
one place.
Cheers
Tom
--
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/groups/opt_out.
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Seb Rose
2014-01-15 23:01:52 UTC
Permalink
Or code up a utilit in the support layer.

If you read The Cucumber Book you'll see an example implementation of an
"eventually" method in Ruby. You can do something similar in Java using
functors or lambdas.
Post by Oscar Rieken
Post by Jason Smiley
Another good reason for before/after step hooks is for error handle.
//perform some step
@AfterStep
public myAfterEveryStep(){
if(has404ErrorOnPage() || has500ErrorOnPage()){
*driver.navigate().refresh();*
}
}
Post by Jason Smiley
Basically, I find myself having to copy and paste error recovery code on
a regular basis. It would be great if I could handle this in an afterStep
hook so I don't have to copy and paste my code everywhere (even if it is
only 3 lines). I see a lot of times the server just times out in my QA or
Stage ENV and refreshing the page would fix my issue (since there isn't any
actual bug in the code, just ENV isn't as stable as prod)
Why not FIX the QA and Staging ENV instead of trying to work around what
is obviously and environmental problem in those environments? Solving the
actual problem is always better than trying working around it. you dont
know if your workaround is changing the results of your tests and giving
you false positives. It could be an actual performance issue in the site.
that you don't notice in prod because there is beefier hardware supporting
prod.
Post by Jason Smiley
Post by Tom Dunstan
Post by j***@public.gmane.org
there is in Ruby that can take a Scenario object (if needed for special
logic).
<snip>
Perhaps you could give a concrete example illustrating what you mean?
I have a case where an AfterStep would be extremely useful. I have
cucumber driving Geb driving WebDriver to test end-to-end interactions in
our code. I'm trying to debug a bug in the chrome driver (
https://code.google.com/p/chromedriver/issues/detail?id=201) and it
would be really helpful to be able to insert a configurable delay after
each step so that I can see when it gets triggered. As it is I'll have to
go and add a sleep after each of the steps around where it happens, so that
I can see exactly where it gets triggered. Would be much easier to do in
one place.
Cheers
Tom
--
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/groups/opt_out.
--
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/groups/opt_out.
--
ACCU - Professionalism in Programming - http://accu.org

http://www.claysnow.co.uk
http://twitter.com/#!/sebrose
http://uk.linkedin.com/in/sebrose
--
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+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/***@public.gmane.org
For more options, visit https://groups.google.com/groups/opt_out.
Continue reading on narkive:
Loading...