[Scala] Customise report

32 views
Skip to first unread message

lauri...@gmail.com

unread,
Oct 26, 2016, 8:07:42 AM10/26/16
to Cukes

Hi everyone,

I am using Cucumber with Scala 2.10.5 .

One of my steps is "When I generate a random number".

I would like to add the generated number to the report e.g. "When I generate a random number (6)"if 6 is the generated number


Is there a easy way to add this type of info in the report ?


Thanks,

lm

Andrew Premdas

unread,
Oct 27, 2016, 7:13:18 AM10/27/16
to cu...@googlegroups.com
Speaking from complete ignorance of the Scala implementation of Cucumber, I would suspect that this would be really difficult. You would have to write a custom report generator that had specialist knowledge about this kind of step.

A better solution would be rewrite you scenario so that it does not need to do this. If you would supply more of your scenario, I  might be able to help with that.

I can't imagine a scenario that would 'need' to have this step, so I look forward to seeing how you are using it.

All best

Andrew

--
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@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Paolo Ambrosio

unread,
Oct 27, 2016, 11:04:49 AM10/27/16
to cu...@googlegroups.com
Short answer: I don't think there is.

Long answer...

In my projetcs I generate random values using the Test Data Builder
pattern when those values do not matter (e.g. creating a new user with
a random username because it's unique and I don't care what that value
is).

Cucumber features should be deterministic. IMO what you are describing
is better achieved by property-based testing with tools like
ScalaCheck at the unit level.

Some of the core Cucumber maintainers had a brainstorming session a
few months ago about introducing property-based testing to Cucumber,
but that AFAIK is not yet a reality.

> Thanks,
>
> lm

lauri...@gmail.com

unread,
Nov 3, 2016, 1:19:40 PM11/3/16
to Cukes

Hi, thanks for your help.

Indeed, I am generating one business object with random identifier (not only one number). It is exactly what you describe : creating a new user with
a random username because it's unique and I don't care what that value is.
 
But, when my scenario fails, it is really helpful to know the random number.

We will probably build a custom report or a clear log file.
Thanks again,
lm

Paolo Ambrosio

unread,
Nov 3, 2016, 5:42:04 PM11/3/16
to cu...@googlegroups.com
I would try and stay away from custom reports if possible.

You could write a scenario hook that adds to the report details about
the created objects (e.g. that unique ID) perhaps only if the scenario
failed.

The scenario object passed to the hook contains a "write" method that
should do that (but I've never used it!) and an "isFailed" to check if
the scenario failed:
https://cucumber.github.io/api/cucumber/jvm/javadoc/cucumber/api/Scenario.html


> Thanks again,
> lm

Andrew Premdas

unread,
Nov 4, 2016, 5:36:19 AM11/4/16
to cu...@googlegroups.com
On 3 November 2016 at 17:19, <lauri...@gmail.com> wrote:
Le mercredi 26 octobre 2016 14:07:42 UTC+2, lauri...@gmail.com a écrit :

Hi everyone,

I am using Cucumber with Scala 2.10.5 .

One of my steps is "When I generate a random number".

I would like to add the generated number to the report e.g. "When I generate a random number (6)"if 6 is the generated number


Is there a easy way to add this type of info in the report ?


Thanks,

lm


Hi, thanks for your help.

Indeed, I am generating one business object with random identifier (not only one number). It is exactly what you describe : creating a new user with
a random username because it's unique and I don't care what that value is.
 
But, when my scenario fails, it is really helpful to know the random number.

We will probably build a custom report or a clear log file.
Thanks again,
lm

What you are doing here is putting 'How' you are doing something in your scenarios. This is not a good idea. Scenarios should be about 'What' you are doing and 'Why' you are doing it. In this particular case what you are doing is creating a user. The other question is why do you need this user. You can answer this somewhat obliquely by how you use the user in the rest of the scenario.

Generally with roles and users I do one of three thing

1. Refer to the user in the first person e.g.

   Given I am a user
   When I do
   Then I should see my ...

2. Refer to the user by their first name (in test worlds first names can be unique)

    Given there is a user Mary
    When Mary

3. Use 1 or 2 in combination with a role

    Given I am an admin user
    Given Ann is an admin

All of these will assign to variables in their implementation e.g. @i @mary @ann, will generate unique GUID based email addresses, and will do lots of other stuff needed for users. None of which belongs in any scenarios (except perhaps the ones that describe user creation).

You should always care about the identification of you users in your scenarios because it makes scenarios easier to write and understand.

If you provide a real scenario that is using this random number step, I'm sure we can provide you with an improved version which is simpler, clearer and more concise.

All best

Andrew


 

--
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@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages