[Cucumber-Java] Conditional Statement glue implementation

1,299 views
Skip to first unread message

Samar Mukherjee

unread,
Feb 12, 2016, 6:46:16 AM2/12/16
to Cukes
Hi ,
  I want to implement a cucumber grammar which will take decision about the next one/more step execution. Is that possible using cucumber. Requirement is similar to the if condition check in any programming language

Step1: Given the next step will execute if (5>6)
Step2: When I send .....
Step3: Then I receive....
Step4: Given I end If
Step5: When I send ....
Step6: Then I receive....



in the above condition step #2 and #3 will be ignored as the condition of Step1 is failing.


Regards,
Samar

Paolo Ambrosio

unread,
Feb 13, 2016, 3:27:28 AM2/13/16
to cu...@googlegroups.com
There is no easy way to do it, but this is BT DESIGN. Scenarios should
be deterministic. In your case you should write two separate
scenarios.

Considering that you have implemented loops in Gherkin (from another
thread) why on Earth don't you just use JUnit? It looks like in your
company someone decided that you have to use Cucumber and you are
trying to break every single best practice around it. One solution for
that could be...

Feature: My company hates me

Scenario: Use Cucumber
Given I wrote my tests in JUnit
When I run them
Then they should succeed

You can easily execute Gradle (or whatever build tool you are using)
in the second step and check the exit code in the second.


Paolo

Samar Mukherjee

unread,
Feb 15, 2016, 2:02:25 AM2/15/16
to Cukes
Thanks Paolo for your suggestion. Actually we are using cucumber for one test automation project and all the testers are giving this king of requirements :( . I know that I am breaking the best practices of cucumber but I do not have any other choice to give them these supports.
Btw, By applying the similar Spring AOP concept if condition grammar is also working now.

Thanks again.

Regards,
Samar

Roberto Lo Giacco

unread,
Feb 15, 2016, 4:01:06 AM2/15/16
to Cukes


Il giorno lunedì 15 febbraio 2016 08:02:25 UTC+1, Samar Mukherjee ha scritto:
Thanks Paolo for your suggestion. Actually we are using cucumber for one test automation project and all the testers are giving this king of requirements :( . I know that I am breaking the best practices of cucumber but I do not have any other choice to give them these supports.
Btw, By applying the similar Spring AOP concept if condition grammar is also working now.


While I am happy you have solved your problem I beg anybody stumbling into this thread not to follow this approach. This is not just breaking best practices, but using the framework in the wrong way and for the wrong purpose. It's not different from using a kettle to warm up milk: you can do it by using a series of tricks, but you do it at your own risk and probably the effort is going to be much higher than just using a milk pan!

Even the initial concept to use Cucumber as an automation test tool is, in principle, deeply wrong and I don't understand why you would do it, other than it sounds cool.

Kuntal Bhattacharya

unread,
Feb 16, 2016, 5:29:10 PM2/16/16
to Cukes
Hi Roberto,

I am a colleague of Samar and work with him on the same project.

Well we are not "just" using Cucumber to create the Automation Framework. We have actually built a Java, Junit, Spring, Maven based framework where Cucumber is the used to define the Test Cases. The QA creates the Feature files, or the Test Cases, then the Automation Framework picks it up, initially uses the Cucumber layer to get to the glue code and then from the Glue code it actually goes into the real drivers which are noting but Java.

We are trying to leverage the power of the BDD and Gherkin in order to derive the Test Cases / Use Cases of the System. The framework starts with the Cucumber-JVM to take those test cases as input and delegates it to the corresponding driver underneath.

While creating complex Test Cases / Use Cases we stumbled upon the requirement where the users of the framework are asking for control structures within the DSL grammars. I understand that Cucumber is actually not made for it, but, what do you do when you stumble upon such use cases where you need the support of control structures?

Please provide your thoughts.

Thanks,
Kuntal Bhattacharya.

Roberto Lo Giacco

unread,
Feb 16, 2016, 8:31:12 PM2/16/16
to cu...@googlegroups.com
On Tue, Feb 16, 2016 at 11:44 AM, Kuntal Bhattacharya <kbhatt...@gmail.com> wrote:
Hi Roberto,

I am a colleague of Samar and work with him on the same project.

Well we are not "just" using Cucumber to create the Automation Framework. We have actually built a Java, Junit, Spring, Maven based framework where Cucumber is the used to define the Test Cases. The QA creates the Feature files, or the Test Cases, then the Automation Framework picks it up, initially uses the Cucumber layer to get to the glue code and then from the Glue code it actually goes into the real drivers which are noting but Java.

We are trying to leverage the power of the BDD and Gherkin in order to derive the Test Cases / Use Cases of the System. The framework starts with the Cucumber-JVM to take those test cases as input and delegates it to the corresponding driver underneath.

While creating complex Test Cases / Use Cases we stumbled upon the requirement where the users of the framework are asking for control structures within the DSL grammars. I understand that Cucumber is actually not made for it, but, what do you do when you stumble upon such use cases where you need the support of control structures?

Please provide your thoughts.

Thanks,
Kuntal Bhattacharya.

​:-D

​First of all I want to apologize to Cucumber main contributors because I know I'm being impolite to their users, but there are none so deaf than those who will not hear, and you guys in Rebaca Technologies seem incapable to understand what I' repeating over and over. Above all the funniest thing is you advertise yourselves as "Test and Test Automation experts" on your home page, but still incapable to understand the difference between testing and specification.

1. What you are doing is not even close to BDD, the initial B stands for behavior and what you are describing is not the system behavior but it's implementation, as test and test automation experts you should be well aware of this
2. Gherkin is INCAPABLE to describe test cases, and test cases are definitely, and by all means, not use cases
3. Cucumber can't accept test cases as input, it rather accept features, there should be a reason why they have different names, right?
4. Having complex gherkin files is the worst usage you could have ever done of Cucumber, may be even worse than trying to use it as a test framework: even correctly describing the system behavior through complex gherkin files would smell of failure
5. Control structures in DSLs are fine, control structures in Gherkin are simply not supported by design, once again there should be a reason for this, right?
6. Create your own, test oriented, DSL, then share it with the world to use: looking at how many of you in Rebaca try to use Cucumber for testing you might be greatly successful​

Now, if you guys want any other additional consulting specifically from me my hourly rate is $400 and I accept PayPal and Bitcoin.

Regards,
    Roberto

 



On Monday, 15 February 2016 14:31:06 UTC+5:30, Roberto Lo Giacco wrote:


Il giorno lunedì 15 febbraio 2016 08:02:25 UTC+1, Samar Mukherjee ha scritto:
Thanks Paolo for your suggestion. Actually we are using cucumber for one test automation project and all the testers are giving this king of requirements :( . I know that I am breaking the best practices of cucumber but I do not have any other choice to give them these supports.
Btw, By applying the similar Spring AOP concept if condition grammar is also working now.


While I am happy you have solved your problem I beg anybody stumbling into this thread not to follow this approach. This is not just breaking best practices, but using the framework in the wrong way and for the wrong purpose. It's not different from using a kettle to warm up milk: you can do it by using a series of tricks, but you do it at your own risk and probably the effort is going to be much higher than just using a milk pan!

Even the initial concept to use Cucumber as an automation test tool is, in principle, deeply wrong and I don't understand why you would do it, other than it sounds cool.

--
Posting rules: http://cukes.info/posting-rules.html
---
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/0H8C1fAK1Zc/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/d/optout.

Tim Walker

unread,
Feb 16, 2016, 9:01:17 PM2/16/16
to cu...@googlegroups.com


On Feb 16, 2016 16:29, "Kuntal Bhattacharya" <kbhatt...@gmail.com> wrote:
>
> Hi Roberto,
>
> I am a colleague of Samar and work with him on the same project.
>
> Well we are not "just" using Cucumber to create the Automation Framework. We have actually built a Java, Junit, Spring, Maven based framework where Cucumber is the used to define the Test Cases. The QA creates the Feature files, or the Test Cases, then the Automation Framework picks it up, initially uses the Cucumber layer to get to the glue code and then from the Glue code it actually goes into the real drivers which are noting but Java.
>
> We are trying to leverage the power of the BDD and Gherkin in order to derive the Test Cases / Use Cases of the System. The framework starts with the Cucumber-JVM to take those test cases as input and delegates it to the corresponding driver underneath.
>
> While creating complex Test Cases / Use Cases we stumbled upon the requirement where the users of the framework are asking for control structures within the DSL grammars. I understand that Cucumber is actually not made for it, but, what do you do when you stumble upon such use cases where you need the support of control structures?
>
> Please provide your thoughts.

Cucumber is not a test automation tool, it is a requirements/collaboration tool. As such it is designed specifically to be customer facing, natural language. If there were looking/branching constructs people would use them but we'd lose the business people. Tim


> Thanks,
> Kuntal Bhattacharya.
>
>
>
> On Monday, 15 February 2016 14:31:06 UTC+5:30, Roberto Lo Giacco wrote:
>>
>>
>>
>> Il giorno lunedì 15 febbraio 2016 08:02:25 UTC+1, Samar Mukherjee ha scritto:
>>>
>>> Thanks Paolo for your suggestion. Actually we are using cucumber for one test automation project and all the testers are giving this king of requirements :( . I know that I am breaking the best practices of cucumber but I do not have any other choice to give them these supports.
>>> Btw, By applying the similar Spring AOP concept if condition grammar is also working now.
>>>>
>>>>
>>
>> While I am happy you have solved your problem I beg anybody stumbling into this thread not to follow this approach. This is not just breaking best practices, but using the framework in the wrong way and for the wrong purpose. It's not different from using a kettle to warm up milk: you can do it by using a series of tricks, but you do it at your own risk and probably the effort is going to be much higher than just using a milk pan!
>>
>> Even the initial concept to use Cucumber as an automation test tool is, in principle, deeply wrong and I don't understand why you would do it, other than it sounds cool.
>

> --
> 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+un...@googlegroups.com.

Andrew Premdas

unread,
Feb 17, 2016, 7:47:21 AM2/17/16
to cu...@googlegroups.com
On 16 February 2016 at 10:44, Kuntal Bhattacharya <kbhatt...@gmail.com> wrote:
Hi Roberto,

I am a colleague of Samar and work with him on the same project.

Well we are not "just" using Cucumber to create the Automation Framework. We have actually built a Java, Junit, Spring, Maven based framework where Cucumber is the used to define the Test Cases. The QA creates the Feature files, or the Test Cases, then the Automation Framework picks it up, initially uses the Cucumber layer to get to the glue code and then from the Glue code it actually goes into the real drivers which are noting but Java.

We are trying to leverage the power of the BDD and Gherkin in order to derive the Test Cases / Use Cases of the System. The framework starts with the Cucumber-JVM to take those test cases as input and delegates it to the corresponding driver underneath.

While creating complex Test Cases / Use Cases we stumbled upon the requirement where the users of the framework are asking for control structures within the DSL grammars. I understand that Cucumber is actually not made for it, but, what do you do when you stumble upon such use cases where you need the support of control structures?

You consult with experts in your field and examine your assumptions and your approach. You've done the first bit, I'm not convinced you are doing the second

Cucumber will not support what you are trying to do. So you can either

1. Stop using Cucumber and find/write something that is more appropriate to your needs
2. Adjust your approach and use Cucumber as its intended. This means that QA's do not write feature files (at least not by themselves), and all this looping programming stuff you want to do, has to be done further down the stack, not in the features.

Let me make it crystal clear, you have not discovered some unknown use case that the Cucumber community needs to address by adding programming structures to feature files. We have seen this all before (so many times ... sigh), there is nothing new here, except maybe your exceptionally high level of misunderstanding.

All best

Andrew




On Monday, 15 February 2016 14:31:06 UTC+5:30, Roberto Lo Giacco wrote:


Il giorno lunedì 15 febbraio 2016 08:02:25 UTC+1, Samar Mukherjee ha scritto:
Thanks Paolo for your suggestion. Actually we are using cucumber for one test automation project and all the testers are giving this king of requirements :( . I know that I am breaking the best practices of cucumber but I do not have any other choice to give them these supports.
Btw, By applying the similar Spring AOP concept if condition grammar is also working now.


While I am happy you have solved your problem I beg anybody stumbling into this thread not to follow this approach. This is not just breaking best practices, but using the framework in the wrong way and for the wrong purpose. It's not different from using a kettle to warm up milk: you can do it by using a series of tricks, but you do it at your own risk and probably the effort is going to be much higher than just using a milk pan!

Even the initial concept to use Cucumber as an automation test tool is, in principle, deeply wrong and I don't understand why you would do it, other than it sounds cool.

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



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

80Vikram

unread,
Feb 17, 2016, 10:29:08 AM2/17/16
to Cukes
I'm new comer to Cucumber and BDD world from faster waterfall / agile world and obviously going in wrong direction like most of users here.

Would like to share post again https://rlogiacco.wordpress.com/2016/01/18/cucumber-is-not-a-testing-framework/ for new comers who want to know what exactly is Cucumber

Regards,
Vikram

80Vikram

unread,
Feb 17, 2016, 11:56:16 AM2/17/16
to Cukes
Hi,

Is there any open source github repos which a newcomer can refer to learning writing good feature files ?

Thanks in advance.

Regards,
Vikram

Roberto Lo Giacco

unread,
Feb 17, 2016, 12:04:30 PM2/17/16
to cu...@googlegroups.com
On Wed, Feb 17, 2016 at 5:56 PM, 80Vikram <vikra...@gmail.com> wrote:
Hi,

Is there any open source github repos which a newcomer can refer to learning writing good feature files ?

Thanks in advance.

Regards,
Vikram

Vikram
​, for future reference please don't hijack unrelated or ancient threads
. If needed I'll give you a long answer in your new thread, short answer is "there are good books, like Cucumber for Java, which try to teach you how to write good feature files, no repos for what I know"

aslak hellesoy

unread,
Feb 17, 2016, 2:45:24 PM2/17/16
to cu...@googlegroups.com
There is also https://cucumber.io/school videos.
Disclaimer: I'm one of tje authors of those videos.

Aslak 

80Vikram

unread,
Feb 18, 2016, 4:21:06 AM2/18/16
to Cukes
Thanks Roberto and Aslak for clarifications.

Regards,
Vikram
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.

80Vikram

unread,
Feb 22, 2016, 12:12:29 PM2/22/16
to Cukes
Hi Sameer , Kuntal ,

Couple of nice videos from Matt Waynne

http://leanagile.scot/matt-wynne-beyond-bdd/

https://skillsmatter.com/skillscasts/2446-bdd-as-its-meant-to-be-done

I have also started learning BDD and trouble to write migrate tons of test cases to feature files and how to write good scenarios.

From the talk what I understand is

1> Feature files has "simple english" language explaining user scenarios only

2> Implementation of Gherkin language statements should be hidden below feature file

3> Try to follow Test Pyramid , don't automate all the scenarios at UI level. Try to push some down to unit , api level as well.

Anyone else started BDD recently , please share leanings / pain areas / good practices.

Regards,
Vikram
Reply all
Reply to author
Forward
0 new messages