Discussion:
[Cucumber] [JVM] Help with Gherkin steps and data flow
(too old to reply)
Andrii Dzynia
2012-10-17 17:05:41 UTC
Permalink
I have an example:

Feature: Someting

Scenario Outline: If something

Given I opening main panel as administrator
When I choose <filterName> with <filterValue>
Then I should have table filtered with <filterValue>

Examples: data example
| filterName | filterValue |
| Country | Ukraine |
| Product | IceCream |

In Java I would like to get List<Entity> in both step definitions, but
cannot because it takes just String parameters. I'm afraid the cases with
many String arguments, more than 10. What is better to do in that way?

Regards,
Andrii
--
-- 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
2012-10-17 17:40:26 UTC
Permalink
Post by Andrii Dzynia
Feature: Someting
Scenario Outline: If something
Given I opening main panel as administrator
When I choose <filterName> with <filterValue>
Then I should have table filtered with <filterValue>
Examples: data example
| filterName | filterValue |
| Country | Ukraine |
| Product | IceCream |
In Java I would like to get List<Entity> in both step definitions,
There are 3 steps here. By "both step definitions" - do you mean
stepdefs for the the last two steps in your outline?
I don't quite understand what you're trying to do. What does the Java
code look like that you'd like to write?

Aslak
Post by Andrii Dzynia
but
cannot because it takes just String parameters. I'm afraid the cases with
many String arguments, more than 10. What is better to do in that way?
Regards,
Andrii
--
-- 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
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
Andrii Dzynia
2012-10-18 07:40:59 UTC
Permalink
Hi Aslak,

Yes, I'm talking about last two step defs.

In java I will have

@When(("^I choose <filterName> with <filterValue>$")
public void chooseFilter(String filterName, String filterValue) {

}

@Then("^I should have table filtered with <filterValue>$")
public void tableShouldBeFiltered(String filterValue) {

}

I'm afraid the situation when I will have many parameters, like
public void chooseFilter(String filterName, String filterValue, String
value2, String value3, String value4, String value5) {}

Rather than string parameters I would like to use List of Entities
public void chooseFilter(List<Entity> list) {}

But I cannot do so with Scenario Outline, because it allow to use just
String parameters.

Regards,
Andrii
Post by aslak hellesoy
Post by Andrii Dzynia
Feature: Someting
Scenario Outline: If something
Given I opening main panel as administrator
When I choose <filterName> with <filterValue>
Then I should have table filtered with <filterValue>
Examples: data example
| filterName | filterValue |
| Country | Ukraine |
| Product | IceCream |
In Java I would like to get List<Entity> in both step definitions,
There are 3 steps here. By "both step definitions" - do you mean
stepdefs for the the last two steps in your outline?
I don't quite understand what you're trying to do. What does the Java
code look like that you'd like to write?
Aslak
Post by Andrii Dzynia
but
cannot because it takes just String parameters. I'm afraid the cases
with
Post by Andrii Dzynia
many String arguments, more than 10. What is better to do in that way?
Regards,
Andrii
--
-- 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
Post by Andrii Dzynia
topic instead.
You received this message because you are subscribed to the Google
Groups
To
Post by Andrii Dzynia
unsubscribe from this group, send email to
this group at
Post by Andrii Dzynia
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
Javix
2012-10-18 08:56:18 UTC
Permalink
May be do like in a cucumber-jvm example, - create an internal class Entity
with all the instance variables corresponding to your headers in examples
table. Then in the steps definition class tale the List<Entity> as
parameter. See more details in
https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/cucumber/examples/java/calculator/RpnCalculatorStepdefs.java
Post by Andrii Dzynia
Hi Aslak,
Yes, I'm talking about last two step defs.
In java I will have
@When(("^I choose <filterName> with <filterValue>$")
public void chooseFilter(String filterName, String filterValue) {
}
@Then("^I should have table filtered with <filterValue>$")
public void tableShouldBeFiltered(String filterValue) {
}
I'm afraid the situation when I will have many parameters, like
public void chooseFilter(String filterName, String filterValue, String
value2, String value3, String value4, String value5) {}
Rather than string parameters I would like to use List of Entities
public void chooseFilter(List<Entity> list) {}
But I cannot do so with Scenario Outline, because it allow to use just
String parameters.
Regards,
Andrii
Post by aslak hellesoy
Post by Andrii Dzynia
Feature: Someting
Scenario Outline: If something
Given I opening main panel as administrator
When I choose <filterName> with <filterValue>
Then I should have table filtered with <filterValue>
Examples: data example
| filterName | filterValue |
| Country | Ukraine |
| Product | IceCream |
In Java I would like to get List<Entity> in both step definitions,
There are 3 steps here. By "both step definitions" - do you mean
stepdefs for the the last two steps in your outline?
I don't quite understand what you're trying to do. What does the Java
code look like that you'd like to write?
Aslak
Post by Andrii Dzynia
but
cannot because it takes just String parameters. I'm afraid the cases
with
Post by Andrii Dzynia
many String arguments, more than 10. What is better to do in that way?
Regards,
Andrii
--
-- 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
Post by Andrii Dzynia
topic instead.
You received this message because you are subscribed to the Google
Groups
Post by Andrii Dzynia
Cukes group. To post to this group, send email 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
Andrii Dzynia
2012-10-18 09:22:50 UTC
Permalink
Hi Javix,

List<Entities> is working if I specify table under each step, but if I
specify table in the Examples: section it's not working

Regards,
Andrii
Post by Javix
May be do like in a cucumber-jvm example, - create an internal class
Entity with all the instance variables corresponding to your headers in
examples table. Then in the steps definition class tale the List<Entity> as
parameter. See more details in
https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/cucumber/examples/java/calculator/RpnCalculatorStepdefs.java
Post by Andrii Dzynia
Hi Aslak,
Yes, I'm talking about last two step defs.
In java I will have
@When(("^I choose <filterName> with <filterValue>$")
public void chooseFilter(String filterName, String filterValue) {
}
@Then("^I should have table filtered with <filterValue>$")
public void tableShouldBeFiltered(String filterValue) {
}
I'm afraid the situation when I will have many parameters, like
public void chooseFilter(String filterName, String filterValue, String
value2, String value3, String value4, String value5) {}
Rather than string parameters I would like to use List of Entities
public void chooseFilter(List<Entity> list) {}
But I cannot do so with Scenario Outline, because it allow to use just
String parameters.
Regards,
Andrii
Post by aslak hellesoy
Post by Andrii Dzynia
Feature: Someting
Scenario Outline: If something
Given I opening main panel as administrator
When I choose <filterName> with <filterValue>
Then I should have table filtered with <filterValue>
Examples: data example
| filterName | filterValue |
| Country | Ukraine |
| Product | IceCream |
In Java I would like to get List<Entity> in both step definitions,
There are 3 steps here. By "both step definitions" - do you mean
stepdefs for the the last two steps in your outline?
I don't quite understand what you're trying to do. What does the Java
code look like that you'd like to write?
Aslak
Post by Andrii Dzynia
but
cannot because it takes just String parameters. I'm afraid the cases
with
Post by Andrii Dzynia
many String arguments, more than 10. What is better to do in that way?
Regards,
Andrii
--
-- 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
Post by Andrii Dzynia
topic instead.
You received this message because you are subscribed to the Google
Groups
Post by Andrii Dzynia
Cukes group. To post to this group, send email 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
Aslak Hellesøy
2012-10-18 10:26:40 UTC
Permalink
Post by Andrii Dzynia
Hi Aslak,
Yes, I'm talking about last two step defs.
In java I will have
@When(("^I choose <filterName> with <filterValue>$")
public void chooseFilter(String filterName, String filterValue) {
}
Needs to be:

@When(("^I choose (.*) with (.*)$")
public void chooseFilter(String filterName, String filterValue) {
}
Post by Andrii Dzynia
@Then("^I should have table filtered with <filterValue>$")
public void tableShouldBeFiltered(String filterValue) {
}
I'm afraid the situation when I will have many parameters, like
public void chooseFilter(String filterName, String filterValue, String
value2, String value3, String value4, String value5) {}
Rather than string parameters I would like to use List of Entities
public void chooseFilter(List<Entity> list) {}
But I cannot do so with Scenario Outline, because it allow to use just
String parameters.
This should work:

Feature: Someting

Scenario Outline: If something
Given I opening main panel as administrator
When I choose the following filter:
| filterName | filterValue |
| <filterName> | <filterValue> |
Then I should have table filtered with <filterValue>


Examples: data example
| filterName | filterValue |
| Country | Ukraine |
| Product | IceCream |


However, it's not very readable. I wouldn't write my features like that.

Aslak
Post by Andrii Dzynia
Regards,
Andrii
Post by aslak hellesoy
Post by Andrii Dzynia
Feature: Someting
Scenario Outline: If something
Given I opening main panel as administrator
When I choose <filterName> with <filterValue>
Then I should have table filtered with <filterValue>
Examples: data example
| filterName | filterValue |
| Country | Ukraine |
| Product | IceCream |
In Java I would like to get List<Entity> in both step definitions,
There are 3 steps here. By "both step definitions" - do you mean
stepdefs for the the last two steps in your outline?
I don't quite understand what you're trying to do. What does the Java
code look like that you'd like to write?
Aslak
Post by Andrii Dzynia
but
cannot because it takes just String parameters. I'm afraid the cases
with
Post by Andrii Dzynia
many String arguments, more than 10. What is better to do in that way?
Regards,
Andrii
--
-- 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
Post by Andrii Dzynia
topic instead.
You received this message because you are subscribed to the Google
Groups
Post by Andrii Dzynia
Cukes group. To post to this group, send email 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
Roberto Lo Giacco
2012-10-19 16:32:27 UTC
Permalink
Hi Andrii,
I think you are getting confused between examples for scenario outlines and
tables: they look quite similar but they represent two completely different
concepts. What makes me think so is the following statement:

I'm afraid the situation when I will have many parameters, like
Post by Andrii Dzynia
public void chooseFilter(String filterName, String filterValue, String
value2, String value3, String value4, String value5) {}
Rather than string parameters I would like to use List of Entities
public void chooseFilter(List<Entity> list) {}
But I cannot do so with Scenario Outline, because it allow to use just
String parameters.
I would have understood if you were willing to use something like
public void chooseFilter(Entity entity) {...}

In other words one single object representing one row in that table, but if
you are thinking of using a list of such objects then I think you are
getting confused: a scenario outline is executed once per each row in the
scenario outline examples table, each time with values pulled from a
different row.

If you think you will end up with a long list of parameters (or columns if
you prefer) then you can use something like
public void chooseFilter(String... args) {...} //Never tried but it should
work

In this case I would consider the real value of such scenario because I
think a business person will not be able to really understand it: may be
you should try to adopt a divide and conquer strategy.

The list of entities approach works nicely within scenario steps because
the entire table is provided to the step as a parameter: the same doesn't
apply to scenario outlines as per previous description.

Regards,
Roberto
--
-- 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
Andrii Dzynia
2012-10-20 08:35:26 UTC
Permalink
Hi Roberto,

Thank you for the answer.

I hope to find right balance with using outline, because I do not like too
much String parameters as input to my step definitions

Regards,
Andrii
Post by Roberto Lo Giacco
Hi Andrii,
I think you are getting confused between examples for scenario outlines
and tables: they look quite similar but they represent two completely
I'm afraid the situation when I will have many parameters, like
Post by Andrii Dzynia
public void chooseFilter(String filterName, String filterValue, String
value2, String value3, String value4, String value5) {}
Rather than string parameters I would like to use List of Entities
public void chooseFilter(List<Entity> list) {}
But I cannot do so with Scenario Outline, because it allow to use just
String parameters.
I would have understood if you were willing to use something like
public void chooseFilter(Entity entity) {...}
In other words one single object representing one row in that table, but
if you are thinking of using a list of such objects then I think you are
getting confused: a scenario outline is executed once per each row in the
scenario outline examples table, each time with values pulled from a
different row.
If you think you will end up with a long list of parameters (or columns if
you prefer) then you can use something like
public void chooseFilter(String... args) {...} //Never tried but it should
work
In this case I would consider the real value of such scenario because I
think a business person will not be able to really understand it: may be
you should try to adopt a divide and conquer strategy.
The list of entities approach works nicely within scenario steps because
the entire table is provided to the step as a parameter: the same doesn't
apply to scenario outlines as per previous description.
Regards,
Roberto
--
-- 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
Loading...