[JVM] Is there a way to run a scenario multiple times without using Outline?

1,407 views
Skip to first unread message

Gangel Dávid

unread,
Jul 21, 2014, 10:10:49 AM7/21/14
to cu...@googlegroups.com

Hi,

I have the following example:

Scenario: Clicking through the language filters and checking the results and removing the language filter by the x
Given I keep the number of books on the search result page
When I click one by one through the list of the "LANGUAGE" filter
Then I should see less books then the original number that I kept
And I should see the item of the "LANGUAGE" filter as "ACTIVATED"
But I do not see anymore the other items of the "LANGUAGE" filter
And when I click on random book
Then I should see the "LANGUAGE" property has the selected item on the Book details page
When I am navigating back with the browsers back button
Then I should see the same amount of books as previous
And I should see the item of the "LANGUAGE" filter as "ACTIVATED"
But I do not see anymore the other items of the "LANGUAGE" filter
Then I refresh the page with the browsers button
Then I should see the same amount of books as previous
And I should see the item of the "LANGUAGE" filter as "ACTIVATED"
But I do not see anymore the other items of the "LANGUAGE" filter
Then I remove the item of the "LANGUAGE" filter from the activated filters
Then I should see the same amount of books as the first time without any filter

Are there any way that I could force cucumber to execute this scenario in multiple times?

The main reason for this is that the data what the scenario is using is a dynamic one.

Andrew Premdas

unread,
Jul 21, 2014, 10:51:13 AM7/21/14
to cu...@googlegroups.com
On 21 July 2014 15:10, Gangel Dávid <gan...@gmail.com> wrote:

Hi,

I have the following example:

Scenario: Clicking through the language filters and checking the results and removing the language filter by the x
Given I keep the number of books on the search result page
When I click one by one through the list of the "LANGUAGE" filter
Then I should see less books then the original number that I kept
And I should see the item of the "LANGUAGE" filter as "ACTIVATED"
But I do not see anymore the other items of the "LANGUAGE" filter
And when I click on random book
Then I should see the "LANGUAGE" property has the selected item on the Book details page
When I am navigating back with the browsers back button
Then I should see the same amount of books as previous
And I should see the item of the "LANGUAGE" filter as "ACTIVATED"
But I do not see anymore the other items of the "LANGUAGE" filter
Then I refresh the page with the browsers button
Then I should see the same amount of books as previous
And I should see the item of the "LANGUAGE" filter as "ACTIVATED"
But I do not see anymore the other items of the "LANGUAGE" filter
Then I remove the item of the "LANGUAGE" filter from the activated filters
Then I should see the same amount of books as the first time without any filter


First of all this is a really bad scenario. You can tell that by the following

1. Mutliple And, But and Then
2. Multiple When
3. Try reading it, its really hard to tell what you are trying to do. You have to study it, to get any idea of what is going on
4. All those block capitals

So before we even think about making things worse by tring to run this multiple times, why not refactor and simplify first, so we can get a clearer picture of what you are trying to do.

Feature: Filter books by my language
  As a single language speaker
  I want to see only books in my language
  So I only see books I can read

Scenario: Books of different languages
  Given there are some French books
  And there are some English books
  When I view the books
  Then I should see French and English books

Scenerio: View only English books
  Given there are some French books
  And there are some English books
  When I view the books
  And I choose to see only English books
  Then I should see English books
  And I should not see French books


If we refactor the above we get the super simple

Feature: Filter books by my language
  I want to see only books in my language
  So I only see books I can read

Background:
  Given there are some French books
  And there are some English books

Scenario: Books of different languages - view all
  When I view the books
  Then I should see French and English books

Scenario: Books of different languages - view only English books
  When I view the books
  And I choose to see only English books
  Then I should see English books
  And I should not see French books

If you break up your original feature using this approach you will:

1. Get a number of smaller simpler scenarios
2. Have tests which are much better at telling you whats wrong when they fail
3. Explain what you are doing with much greater clarity, then perhaps we can see why you might want to run a particular scenario more than once


HTH

All best

Andrew


 

Are there any way that I could force cucumber to execute this scenario in multiple times?

The main reason for this is that the data what the scenario is using is a dynamic one.

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

Gangel Dávid

unread,
Jul 22, 2014, 6:59:16 AM7/22/14
to cu...@googlegroups.com
And how do you walk through with your approach a list of langauges.
A list of languages that it's not a fixed list, nor the length nor the content...

Andrew Premdas

unread,
Jul 22, 2014, 5:44:01 PM7/22/14
to cu...@googlegroups.com
On 22 July 2014 11:59, Gangel Dávid <gan...@gmail.com> wrote:
And how do you walk through with your approach a list of langauges.
A list of languages that it's not a fixed list, nor the length nor the content...

First you give the list of languages a name, so you can talk about them. Then you write your scenario. But before we do that can I confirm that you want to do

When I choose to see English books

When I choose to see French books

When I choose to see German books

...

If this is the case you probably shouldn't do this. Doing exhaustive testing at this level e.g testing every validation, every language choice etc. is very expensive and gives very little additional benefit for the cost. The expense is mostly about run time of tests. If you have 200 languages your language tests will take 200 times longer to run. With a unit test this 'might' be acceptable. However acceptance tests run much slower. The cost of having a slow running suite of acceptance tests generally far exceeds the benefits of doing semi-exhuastive testing.


Having put that to one side, lets give our lanuages a name e.g. selectable languages

Given books in selectable langauges
When I view books
And for all selectable languages I filter on a selectable language
Then for all selectable languages I should see only books for the selected langauage

The key is the steps

When "for all selectable languages I filter on a selectable language" do
  @results = {}  # @results is global
  selectable_langauges.each do | lang |
     filter_on lang
     results[lang] = visible_books.collect{|book| book.lang != lang}
   end
 end

Then for all selectable languages I should see only books for the selected langauage
   @results.each do | res |
       res.value.should == nil
   end
end

The above is ruby'ish code. The key idea is that once you have named your collection of languages you can perform multiple 'when' operations (one for each language) in a single step, collecting the results in a hash. Then you use the hash to report on the results of the operations in a 'then' step.

So instead of trying to do our programming (iterating over a collection ) in our feature, we 'push it down' into our steps.

If you make selectable_languages a method, you can even do clever stuff, like make it return a small subset of languages most of the time, and all of the languages once in a while (perhaps based on an environment variable)

All best

Andrew

Gangel Dávid

unread,
Jul 23, 2014, 4:38:25 AM7/23/14
to cu...@googlegroups.com
I see the benefit of this approach but from the other hand you are hiding the testing details inside the feature file, so if you want to get more information about what and how is going to be tested you have to go to the step-definition.

Roberto Lo Giacco

unread,
Jul 23, 2014, 4:51:31 AM7/23/14
to cu...@googlegroups.com


Il giorno mercoledì 23 luglio 2014 10:38:25 UTC+2, Gangel Dávid ha scritto:
I see the benefit of this approach but from the other hand you are hiding the testing details inside the feature file, so if you want to get more information about what and how is going to be tested you have to go to the step-definition.

Which is one of the purposes of using Gherkin/Cucumber.

If your tests are short and not cluttered with programmer's mindset it's more probable your product owner/business representative will read, review and contribute to them.

If the feature files are written by programmers for programmers with no intervention from business then what benefit are you getting from Gherkin/Cucumber compared to JUnit/UnitNG? 
Reply all
Reply to author
Forward
0 new messages