Cucumber JVM - how reuse steps into feature

6,190 views
Skip to first unread message

martino turturiello

unread,
Feb 11, 2013, 5:36:42 AM2/11/13
to cu...@googlegroups.com
Hi all,

I started using cucumber-jvm for a specific project and I have created already my steps definition

No that I have some steps like;

 I open page, I click on, I close page

I would like to create groups of steps outside java code, is it possible to create a feaure file or something like tahat to grate for example:

I am logged in
{
the steps to login
}


Thanks!

aslak hellesoy

unread,
Feb 11, 2013, 6:07:35 AM2/11/13
to Cucumber Users
I don't have time to write a long answer now, but I recommend you read this blog post:


To reuse code, just factor the reusable parts into regular java methods that you can call from stepdefs.

Aslak
 

Thanks!

--
-- 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 cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@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+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

martino turturiello

unread,
Feb 11, 2013, 8:15:52 AM2/11/13
to cu...@googlegroups.com
Thanks for the answer, but is still not clear to me...

I try to re-formulate me question:

I have already created some java basic steps like:
open browser, type user, type password, etc

Now outside java, I would like to create a kind of login module to re-using the steps, like

Given I am logged in
step open browser
step type user "username"
step type password "password"
step submit

Is it possible in any way?

Cheers

aslak hellesoy

unread,
Feb 11, 2013, 10:11:43 AM2/11/13
to Cucumber Users
On Mon, Feb 11, 2013 at 1:15 PM, martino turturiello <turturiel...@gmail.com> wrote:
Thanks for the answer, but is still not clear to me...

I try to re-formulate me question:

I have already created some java basic steps like:
open browser, type user, type password, etc

Now outside java, I would like to create a kind of login module to re-using the steps

This sounds like a classic XY problem [1],[2]. You want to avoid duplication (X), and you think this can be done by reusing steps (Y).

You can (and should) do this in plain code instead, using *methods*:

@Given("I am logged in")
public void I_am_logged_in() {
    openBrowser();
    type("user", "username");
    type("password", "password");
    click("submit");
}

HTH,
Aslak

martino turturiello

unread,
Feb 11, 2013, 10:19:23 AM2/11/13
to cu...@googlegroups.com
Thanks again, but as I said I would like to do it outside the Java code.
Is it possible to do it in ".feature"  file or somewhere esle?

Cheers

aslak hellesoy

unread,
Feb 11, 2013, 10:21:25 AM2/11/13
to Cucumber Users
On Mon, Feb 11, 2013 at 3:19 PM, martino turturiello <turturiel...@gmail.com> wrote:
Thanks again, but as I said I would like to do it outside the Java code.

Why?
 
Is it possible to do it in ".feature"  file or somewhere esle?

No.

martino turturiello

unread,
Feb 11, 2013, 10:26:00 AM2/11/13
to cu...@googlegroups.com
Well, lets imagine this:

I create basic steps to drive the browser (I click to, I wait for , etc)  then I give this to the testers and they can create Cucumber test without having to touch the Java code!

Do you think is possible to to something like this?

Cheers

2013/2/11 aslak hellesoy <aslak.h...@gmail.com>



--
-----------------------------------------------------
Chi non ha apprezzato il suo maestro né la sua lezione, un giorno sarà forse colto, ma non sarà mai saggio.


Numero telefonico 09711835500
Skype: turturiellomartino

aslak hellesoy

unread,
Feb 11, 2013, 10:30:45 AM2/11/13
to Cucumber Users
On Mon, Feb 11, 2013 at 3:26 PM, martino turturiello <turturiel...@gmail.com> wrote:
Well, lets imagine this:

I create basic steps to drive the browser (I click to, I wait for , etc)  then I give this to the testers and they can create Cucumber test without having to touch the Java code!


So you disagree with what I wrote in my blog post? You want to recreate web_steps for your own project?

martino turturiello

unread,
Feb 11, 2013, 10:48:58 AM2/11/13
to cu...@googlegroups.com
I agree with you, and what I am try to do is the same as you suggest in your post, the difference is that I would like to achieve the same by creating group of steps outside java code.

I would like to give to testers the chance to create reusable method in plane text without  touch java( just by create your small java libs and add as maven dependencies)

Does it sounds so bad?  :-)

George Dinwiddie

unread,
Feb 11, 2013, 12:33:15 PM2/11/13
to cu...@googlegroups.com
Martino,

May I suggest that having reusable steps in terms of your application
may help you. Having reusable steps in terms of the implementation
(e.g., browser interactions such as clicking and filling in fields) of
your application will probably hurt you in the long run. That's been the
experience of others in the past.

- George

On 2/11/13 10:48 AM, martino turturiello wrote:
> I agree with you, and what I am try to do is the same as you suggest in
> your post, the difference is that I would like to achieve the same by
> creating group of steps outside java code.
>
> I would like to give to testers the chance to create reusable method in
> plane text without touch java( just by create your small java libs and
> add as maven dependencies)
>
> Does it sounds so bad? :-)
>
> Cheers
>
>
> 2013/2/11 aslak hellesoy <aslak.h...@gmail.com
> <mailto:aslak.h...@gmail.com>>
>
>
>
>
> On Mon, Feb 11, 2013 at 3:26 PM, martino turturiello
> <turturiel...@gmail.com <mailto:turturiel...@gmail.com>>
> wrote:
>
> Well, lets imagine this:
>
> I create basic steps to drive the browser (I click to, I wait
> for , etc) then I give this to the testers and they can create
> Cucumber test without having to touch the Java code!
>
>
> So you disagree with what I wrote in my blog post? You want to
> recreate web_steps for your own project?
>
> Do you think is possible to to something like this?
>
> Cheers
>
>
> 2013/2/11 aslak hellesoy <aslak.h...@gmail.com
> <mailto:aslak.h...@gmail.com>>
>
>
>
>
> On Mon, Feb 11, 2013 at 3:19 PM, martino turturiello
> <turturiel...@gmail.com
> http://www.perlmonks.org/__index.pl?node_id=542341
> <http://www.perlmonks.org/index.pl?node_id=542341>
> [2]
> http://meta.stackoverflow.__com/questions/66377/what-is-__the-xy-problem
> http://aslakhellesoy.com/post/____11055981222/the-training-__wheel__s-came-off
> <http://aslakhellesoy.com/post/11055981222/the-training-wheels-came-off>
>
> To reuse code, just factor the reusable
> parts into regular java methods that you can
> call from stepdefs.
>
> Aslak
>
>
> Thanks!
>
> --
> -- Rules --
>
> 1) Please prefix the subject with
> [Ruby], [JVM] or [JS].
> 2) Please use interleaved answers
> http://en.wikipedia.org/wiki/__P__osting_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 cu...@googlegroups.com. To
> unsubscribe from this group, send email
> to cukes+un...@__googlegroups.com. For
> more options, visit this group at
> https://groups.google.com/d/__fo__rum/cukes?hl=en
> <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+un...@__googlegroups.com.
>
> For more options, visit
> https://groups.google.com/__grou__ps/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> -- 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
> cu...@googlegroups.com. To unsubscribe from this
> group, send email to
> cukes+un...@__googlegroups.com. For more
> options, visit this group at
> https://groups.google.com/d/__forum/cukes?hl=en
> <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+un...@__googlegroups.com.
> For more options, visit
> https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
> --
> -- 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 cu...@googlegroups.com
> <mailto:cu...@googlegroups.com>. To unsubscribe from
> this group, send email to
> cukes+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@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+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@googlegroups.com>.
> For more options, visit
> https://groups.google.com/groups/opt_out.
>
>
>
> --
> -- 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 cu...@googlegroups.com <mailto:cu...@googlegroups.com>.
> To unsubscribe from this group, send email to
> cukes+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@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+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@googlegroups.com>.
> For more options, visit
> https://groups.google.com/groups/opt_out.
>
>
>
>
>
> --
> -----------------------------------------------------
> Chi non ha apprezzato il suo maestro né la sua lezione, un
> giorno sarà forse colto, ma non sarà mai saggio.
>
>
> Numero telefonico 09711835500
> Skype: turturiellomartino
>
> --
> -- 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
> cu...@googlegroups.com <mailto:cu...@googlegroups.com>. To
> unsubscribe from this group, send email to
> cukes+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@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+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@googlegroups.com>.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
> --
> -- 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
> cu...@googlegroups.com <mailto:cu...@googlegroups.com>. To
> unsubscribe from this group, send email to
> cukes+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@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+un...@googlegroups.com
> <mailto:cukes%2Bunsu...@googlegroups.com>.
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

Matt Wynne

unread,
Feb 17, 2013, 5:44:09 PM2/17/13
to cu...@googlegroups.com
Dear Martino,

On 11 Feb 2013, at 15:26, martino turturiello <turturiel...@gmail.com> wrote:

give this to the testers and they can create Cucumber test without having to touch the Java code!

Here's your problem ^^^^^^

Test automation is software development. Dale Emery says so.[1]

Testers should not be wasting their time writing software, unless they're really good at it. Instead, they should focus on thinking up new test cases. For sure, they can write them up in Gherkin, but if having them automated matters to the team, they need to pair up with software developers to get that work done. That's the only way to end up with maintainable test code, in my experience.



martino turturiello

unread,
Feb 18, 2013, 2:05:56 AM2/18/13
to cu...@googlegroups.com
Thanks to all!

At the end I had to move to Robot framework as it supports the  creation of new keywords by grouping steps.

I agree with you guys that software testing is as well development, but it depends of the size of the company where you have to implement it. For big software factory I can see a group of automation Engs writing test as development, but for a samll company, probably, it will be east to write tests withut a deep knowledge of java, ruby, etc.
So what I am doing now is creating basic keywords in java for Robot framework and then the testers can use them in theirs tests by grouping steps and create test cases without know any programing language. I would be nice to have the same feature in cucumber!

Thanks again to all for your halp,
Martino

Dmitry K

unread,
Dec 9, 2013, 11:42:42 PM12/9/13
to cu...@googlegroups.com
Good day, Martino!

I've faced exactly the same problem and want to know if you succeed with your approach.
All in all, does it make sense to give a tester the ability to create reusable methods in plain text?

понедельник, 18 февраля 2013 г., 14:05:56 UTC+7 пользователь martino turturiello написал:

martino turturiello

unread,
Dec 11, 2013, 11:43:14 AM12/11/13
to cu...@googlegroups.com
Hi Dmitry,

well at then end I moved to robot framework and yes, it make sense. Give a little bit of flexibility helps testers to create new keywords based on they needs.

Cheers,
Martino



2013/12/9 Dmitry K <dmit...@gmail.com>
--
-- 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 cu...@googlegroups.com. To unsubscribe from this group, send email to cukes+un...@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 a topic in the Google Groups "Cukes" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cukes/OUy9go8AsTo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cukes+un...@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages