Help on getting a unique ID per scenario

1,332 views
Skip to first unread message

bruno cruz

unread,
Mar 26, 2012, 10:16:53 AM3/26/12
to cu...@googlegroups.com
Hello everyone.

I've been given a project where, when using cucumber, I need to automatically create (per scenario in a .feature file) a unique ID; such ID would be a tag on top of the scenarios, so I would be able to call them individually. 

I've been looking around Gherkin, trying to find a spot where I could use its parser so, when he reads the .feature files for the scenarios, I could write the tag, creating the mentioned unique ID.

However, I've had a hard time, since I can't really find out where the parser reads the files and how to create this functionality. Do you have any idea where the best place to make this change is or where I could start?

Thank you for the help. Best regards

aslak hellesoy

unread,
Mar 26, 2012, 10:23:41 AM3/26/12
to cu...@googlegroups.com
On Mon, Mar 26, 2012 at 3:16 PM, bruno cruz <bscr...@gmail.com> wrote:
> Hello everyone.
>
> I've been given a project where, when using cucumber, I need
> to automatically create (per scenario in a .feature file) a unique ID; such
> ID would be a tag on top of the scenarios, so I would be able to call
> them individually.
>

You don't need a unique id to call (execute?) a specific scenario. Just:

cucumber path/to/the.feature:98

If I misunderstood what you're trying to accomplish, please give an example.

Aslak

> I've been looking around Gherkin, trying to find a spot where I could use
> its parser so, when he reads the .feature files for the scenarios, I could
> write the tag, creating the mentioned unique ID.
>
> However, I've had a hard time, since I can't really find out where the
> parser reads the files and how to create this functionality. Do you have
> any idea where the best place to make this change is or where I could start?
>
> Thank you for the help. Best regards
>

> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cukes/-/FE-TqAtwwSMJ.
> 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
> http://groups.google.com/group/cukes?hl=en.

Oscar Rieken

unread,
Mar 26, 2012, 10:24:27 AM3/26/12
to cu...@googlegroups.com
I don't really understand what you are trying to do but why not just call the scenarios by their line number

features/something.feature:12 features/some_other.feature:35 features/third_feature.feature:8



--

bc-pt

unread,
Mar 26, 2012, 10:28:56 AM3/26/12
to cu...@googlegroups.com
@Aslak:

For example:

@important
Feature: Test::Unit
  In order to please people who like Test::Unit
  As a Cucumber user
  I want to be able to use assert* in my step definitions

  @high
  Scenario: assert_equal
    Given x = 5
    And y = 5
    Then I can assert that x == y

Instead of the tag @high (or next to the tag @high) I need a unique ID for it, created automatically - I figured, during the parsing, but I'm open to suggestions.

Doing it by line isn't really an option, because the feature files will be done by more than one person, a single slip and the lines could get messed up.

aslak hellesoy

unread,
Mar 26, 2012, 10:33:40 AM3/26/12
to cu...@googlegroups.com
On Mon, Mar 26, 2012 at 3:28 PM, bc-pt <bscr...@gmail.com> wrote:
> @Aslak:
>
> For example:
>
> @important
> Feature: Test::Unit
>   In order to please people who like Test::Unit
>   As a Cucumber user
>   I want to be able to use assert* in my step definitions
>
>   @high
>   Scenario: assert_equal
>     Given x = 5
>     And y = 5
>     Then I can assert that x == y
>
> Instead of the tag @high (or next to the tag @high) I need a unique ID for
> it, created automatically - I figured, during the parsing, but I'm open to
> suggestions.
>
> Doing it by line isn't really an option, because the feature files will be
> done by more than one person, a single slip and the lines could get messed
> up.
>

If you look at the feature file in an text editor you will see the
line numbers. That's hard to mess up.

I don't understand what higher level problem you are trying to solve.
Do you have a lot of people who each need to run their individual
scenarios?

Aslak

> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/cukes/-/Y5H1YOtZyYYJ.

bc-pt

unread,
Mar 26, 2012, 10:39:04 AM3/26/12
to cu...@googlegroups.com
Basically, yes. I really need this feature, for later usages in this project.

Any idea where I could start?

aslak hellesoy

unread,
Mar 26, 2012, 10:44:12 AM3/26/12
to cu...@googlegroups.com
On Mon, Mar 26, 2012 at 3:39 PM, bc-pt <bscr...@gmail.com> wrote:
> Basically, yes.

I don't know what "Basically yes" is a reply to. Please use
interleaved posting style so we can follow the conversation:
http://en.wikipedia.org/wiki/Posting_style

> I really need this feature, for later usages in this
> project.
>
> Any idea where I could start?
>

You'd have to start by convincing us why this feature is needed, by
explaining what you are trying to accomplish.

Aslak

> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/cukes/-/AWQKOoS8pQoJ.

bc-pt

unread,
Mar 26, 2012, 10:55:48 AM3/26/12
to cu...@googlegroups.com
I need this for a college project. Using a CI engine (Hudson) and a issue-tracker (JIRA), when a report comes from the CI engine showing what went wrong, I need to create a related issue on the tracker. 

This ID would be used on the report and on the issue. The report would show what issue was created for each failed scenario, what went wrong and a ID to run it individually. And the presence of the ID on the issue would make it possible for an unrelated team to read the problem in a more fashionable way and make them capable of running the scenario themselves.

Segunda-feira, 26 de Março de 2012 15h16min53s UTC+1, bc-pt escreveu:

bc-pt

unread,
Mar 26, 2012, 10:57:20 AM3/26/12
to cu...@googlegroups.com
Oh, so sorry. I was saying yes to your question, "Do you have a lot of people who each need to run their individual scenarios?". My bad


Segunda-feira, 26 de Março de 2012 15h16min53s UTC+1, bc-pt escreveu:

Oscar Rieken

unread,
Mar 26, 2012, 11:11:09 AM3/26/12
to cu...@googlegroups.com
if thats the case why not use the jira ticket number as the tag for the scenario that is creates?

the problem I see is that this could lead to a lot of duplicate scenarios for issues if this was being done in code. and you would end up with tag names that don't really mean anything. @something_I_care_about99999 doesnt make a lot of sense

if you were going to do something like this you could use information from jira to create the feature file but then you would still potentially end up with thousands of scenarios that don't mean a whole lot or are duplicates



--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/fFiHH4U3Yo8J.

bc-pt

unread,
Mar 26, 2012, 11:31:11 AM3/26/12
to cu...@googlegroups.com
Well that was one of my problems, I want to avoid having two or more issues for just one scenario. If I can link one specific scenario (using something that can make it unique) to one specific issue (which already has a ticket number created automatically), I can just update the information with what went wrong in the latest testing round.
To unsubscribe from this group, send email to cukes+unsubscribe@googlegroups.com.

Niklas Delißen

unread,
Mar 26, 2012, 11:39:02 AM3/26/12
to cu...@googlegroups.com
The scenario name should be unique. I use it together with the testlink
plugin from jenkins and report the junit xml in testlink.

> +unsub...@googlegroups.com.


> For more options, visit this group at
> http://groups.google.com/group/cukes?hl=en.
>
>
>

> --
> You received this message because you are subscribed to the Google
> Groups "Cukes" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/cukes/-/ECXKVGCi5KMJ.


> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to cukes

> +unsub...@googlegroups.com.

bc-pt

unread,
Mar 26, 2012, 11:46:24 AM3/26/12
to cu...@googlegroups.com
Yeah, but with different people creating different feature files with multiple scenarios, things can get a little bit tricky. Having something done automatically to single each scenario out if needed, would be nice. 

Could you tell me more about your approach please Snow? 

Matt Wynne

unread,
Mar 26, 2012, 12:27:20 PM3/26/12
to cu...@googlegroups.com

On 26 Mar 2012, at 15:28, bc-pt wrote:

Doing it by line isn't really an option, because the feature files will be done by more than one person, a single slip and the lines could get messed up.

This is the problem that the scenario ID (used in the gherkin json formatter) is meant to solve.

e.g.

cheers,
Matt


aslak hellesoy

unread,
Mar 26, 2012, 12:33:09 PM3/26/12
to cu...@googlegroups.com
On Mon, Mar 26, 2012 at 5:27 PM, Matt Wynne <ma...@mattwynne.net> wrote:
>
> On 26 Mar 2012, at 15:28, bc-pt wrote:
>
> Doing it by line isn't really an option, because the feature files will be
> done by more than one person, a single slip and the lines could get messed
> up.
>
>
> This is the problem that the scenario ID (used in the gherkin json
> formatter) is meant to solve.
>
> e.g.
> https://github.com/cucumber/gherkin/blob/master/features/json_formatter.feature#L41
>

That will output unique ids in the JSON format, but those ids can't
(yet) be used to specify a scenario to run.

Aslak

> cheers,
> Matt
>
> --
> Freelance programmer & coach
> Author, http://pragprog.com/book/hwcuc/the-cucumber-book
> Founder, http://www.relishapp.com/
> Twitter, https://twitter.com/mattwynne
>
>

> --
> 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.

bc-pt

unread,
Mar 26, 2012, 12:45:07 PM3/26/12
to cu...@googlegroups.com
Exactly, kinda wanted to get these ID's in a tag, so I could use them individually. Any ideas?

> cukes+unsubscribe@googlegroups.com.

aslak hellesoy

unread,
Mar 26, 2012, 12:51:33 PM3/26/12
to cu...@googlegroups.com
On Mon, Mar 26, 2012 at 5:45 PM, bc-pt <bscr...@gmail.com> wrote:
> Exactly, kinda wanted to get these ID's in a tag, so I could use them
> individually. Any ideas?
>

So you want cucumber to modify the gherkin source for you and insert a
unique tag everywhere?

Please respond interleaved, don't top post:
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style

Aslak

>> > cukes+un...@googlegroups.com.


>> > For more options, visit this group at
>> > http://groups.google.com/group/cukes?hl=en.
>

> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.

> To view this discussion on the web visit

> https://groups.google.com/d/msg/cukes/-/eDQx0_JGcyoJ.


>
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to

> cukes+un...@googlegroups.com.

bc-pt

unread,
Mar 26, 2012, 12:59:15 PM3/26/12
to cu...@googlegroups.com
Sorry, still getting the hang of this, first time I'm using google groups.

Yes, I'd like Gherkin to insert a unique ID in every cenario it finds in the feature files. Is that possible?


>> > For more options, visit this group at
>> > http://groups.google.com/group/cukes?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cukes/-/eDQx0_JGcyoJ.
>
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to

Aslak Hellesøy

unread,
Mar 26, 2012, 1:03:27 PM3/26/12
to cu...@googlegroups.com


On Monday, March 26, 2012 5:59:15 PM UTC+1, bc-pt wrote:
Sorry, still getting the hang of this, first time I'm using google groups.

Yes, I'd like Gherkin to insert a unique ID in every cenario it finds in the feature files. Is that possible?


No, that's currently not possible I'm afraid.

bc-pt

unread,
Mar 26, 2012, 1:08:39 PM3/26/12
to cu...@googlegroups.com
Not even when the parser is reading the feature files? Can't I get the an ID somehow in there, writing to the file?

Niklas Delißen

unread,
Mar 26, 2012, 1:19:53 PM3/26/12
to cu...@googlegroups.com
On Mon, 2012-03-26 at 08:46 -0700, bc-pt wrote:
> Yeah, but with different people creating different feature files with
> multiple scenarios, things can get a little bit tricky. Having
> something done automatically to single each scenario out if needed,
> would be nice.
>
>
> Could you tell me more about your approach please Snow?

Sure, basically i just run the tests by maven - surefire plugin and let
it create the usual junit xml report.

The TestLink Plugin does the rest. You can find a tutorial here:
https://wiki.jenkins-ci.org/display/JENKINS/TestLink+Plugin
(It explains everything from Testlink, Jenkins installation and
configuration)

The strategy is to match the case class name, the pattern is /TEST-*.xml
and the xml is found in target/surefire-reports/.

Every scenario can be linked to a testcase in testlink. I am looking at
a huge amount of old testcases i cant throwaway and there will always be
some manual tests anyways. So i thought to combine the reporting in
testlink.

I dont believe that writing the same testcase twice happens often. And
analogously i dont think ppl title their scenarios the same besides that
they shouldnt :)

Most examples concentrate on a few scenarios, so they end up with really
short and basic titles. In reality we write 100s and 1000s of scenarios
and the scenario title should already give us a great idea about whats
going on. Otherwise we will have to read all scenarios to a feature and
even if so we could make sure there is no duplication of titles.

I also thought alot about dont ending up with duplications of stepdefs,
but i think its just unrealistic to happen. If the existing scenarios
are not read, there shouldnt be new ones added.

> https://groups.google.com/d/msg/cukes/-/9aF1_Ai8RX4J.

bc-pt

unread,
Mar 26, 2012, 1:29:18 PM3/26/12
to cu...@googlegroups.com
Thanks for the info mate. I'm going to study it for a little, maybe I can use the same approach in my case. Will talk to you if I have any problem, if you don't mind, of course

Aslak Hellesøy

unread,
Mar 26, 2012, 1:49:45 PM3/26/12
to cu...@googlegroups.com




On Mar 26, 2012, at 18:08, bc-pt <bscr...@gmail.com> wrote:

Not even when the parser is reading the feature files? 

How would people know what id to use if it's computed during parse time?


>> > For more options, visit this group at
>> > http://groups.google.com/group/cukes?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cukes/-/eDQx0_JGcyoJ.
>
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to


> For more options, visit this group at
> http://groups.google.com/group/cukes?hl=en.

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/bwmI9dYBHyIJ.

To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.

Niklas Delißen

unread,
Mar 26, 2012, 2:14:55 PM3/26/12
to cu...@googlegroups.com
On Mon, 2012-03-26 at 10:29 -0700, bc-pt wrote:
> Thanks for the info mate. I'm going to study it for a little, maybe I
> can use the same approach in my case. Will talk to you if I have any
> problem, if you don't mind, of course
>

Wouldnt mind at all.

I hope to find time to look at Jira integration, would be nicer for
plain bugreports.

> https://groups.google.com/d/msg/cukes/-/PfpsHbgFZMAJ.

bc-pt

unread,
Mar 26, 2012, 2:17:48 PM3/26/12
to cu...@googlegroups.com
Well, if the scenario fails, it generates an issue. In that issue, you'll find the ID. So you're able to run individual tests on it, for example.


>> > For more options, visit this group at
>> > http://groups.google.com/group/cukes?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Cukes" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/cukes/-/eDQx0_JGcyoJ.
>
> To post to this group, send email to cu...@googlegroups.com.
> To unsubscribe from this group, send email to


> For more options, visit this group at
> http://groups.google.com/group/cukes?hl=en.

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To view this discussion on the web visit https://groups.google.com/d/msg/cukes/-/bwmI9dYBHyIJ.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages