In my feature file, using the same scenario I am checking more than one requirements. I have written the scenario like below:
Scenario: My first requirement ID
My second requirement ID
My third requirement ID
Etc
After execution, the extend report shows only the result as
Scenario: My first requirement ID
How can I get all the three I D,s in extent report.
NOTE:Each of my scenario title is lengthy.
Can you explain your scenario text a little bit more? According to the documentation, the scenario should describe in human terms what we expect the software to do. It is quite unusual to include expected data in that scenario text. Are you using the ID from an enum? If that is the case, it would be better to spell out the enum in human readable terms. Scenario: UserType is Administrator for example. Another option would be to use a Scenario Outline, something like
Scenario Outline: My generic requirement statement
Given Id <whateverId> is provided
When I do <activity>
Then I expect to see <result>
Examples:
| whateverId | activity | result |
| 12 | firstMethod | MyResult |
| 20 | secondActivity | anotherResult |
| 42 | thirdExample | thirdResult |
The variable names provided in the outline in angle brackets become the column headers in the examples grid. Just be sure to indent the grid below the Examples: line and also include the pipe | on both the left and right boundaries of the grid. Hopefully that helps.
Related
Lets say that my app works with some books with real titles "The Old Man and the Sea", "War and Peace", etc., when creating scenarios, should I use real title like:
Given I have a book "War and Peace" persisted
When ...
or should I do something like:
Given I have a book "Book1" persisted
When ...
Option 2 is more generic, but artificial example. And If I use first option, person who is reading the test has to have domain knowledge, and he will also have some presumptions about the scenario as soon as he reads the title of the book.
Also, is there some simpler way for me to create data table without repeating data (in this case page where I have always to repeat 1,1,2,2,2,2...)? example:
When we receive book with following content:
| Page | Line | Text |
| 1 | 1 | a |
| 1 | 2 | b |
| 2 | 1 | a |
| 2 | 2 | b |
is this standard way to do it:
When we receive a book
And page 1 has content
| Line | Text |
| 1 | a |
| 2 | b |
And page 2 has content
| Line | Text |
| 1 | a |
| 2 | b |
First of all start with the name of the scenario, this name should be meaningful and should be like a summary about what is about the test.
Once you have the name then the other steps should describe a business flow that of course should contain domain language, because for example if i don't know nothing about healthcare, banking etc then why would I understand a test about a specific domain subject?, the scenarios are for a specific group of people (the ones that are working in the specific domain).
One of the BDD role is to help in understanding better the specifications and the application on all levels (technical to non-technical, but on the same business domain), to improve communication.
Now for your specific issue.
Given I have a book "War and Peace" persisted does not offer to much info since the title of the book says nothing about the test data; is a new book that just was added/created?, is a type of book technical/poetry or just some book?
What was useful for me is use a name for the the data that says something about the data used in the test.
If you don't have different types of books you can use any name, else a more complete name would be more useful.
As for the table, that represents a data set and you need to tell what to check and where; depending by case you could group some checks, if you can read all data at once or not, or if you need to specify the texts/pages.
One option would be to hide the data set and say something like:
Given I have a book "War and Peace" persisted
Then the book contains the expected content for "War and Peace"
in the first step "War and Peace" - gets/creates a specific book that is identified by this title
in the second step "War and Peace" - identifies a set of data for the expected result using the same name since is the expected for that specific data set, this set of data can be list/array/map ... depending of what programming language you are using.
Don't think to much to the details, just define the scenario in human readable language using outside-in approach, then see if you can refine it and after start the implementation.
Always use a description for the feature and a meaningful title for each scenario
I am using an outline examples in my test,
something like :
Feature: feature name
Scenario Outline: outline scenario
Given I go to
When I click on button
Then I should have
Examples:
| website | title |
| google | google welcome|
| yahoo | yahoo welcome |
| Astalavista | altalavista hello I m dead |
so far it is great !!! but if the first one is doing okay and the second one is having an issue the third is not played ...
do you know how to continue all the test in case of outline scenario ?
thanks a lot for your help !
There is something called failFast in the cucumberOpts.
If the value is true then it means fail at the first failure and do not proceed.
If the value is false then the execution will continue for all the scenario in the feature file even if one scenario fails.
So try by making it as false.
Thanks,
Naveen
Feature: showing off behave style
Scenario Outline: wow
Given I put "<brand_one/brand_two>" in a blender
When we implement a test
Examples: Brand
| brand_one|brand_two|
| first Frog | second Frog|
I want to select brand_one or brand_two at run time.
On executing feature file i just want to execute method taking value of brand_one (i.e first Frog) or brand_two (i.e seconf Frog) at run time. But only execute one desired brand and not the other one. Please help me out to select this on run time. Thanks
You could use tags for this:
Feature: showing off behave style
Scenario Outline: wow
Given I put "<brand>" in a blender
When we implement a test
#FrogOne
Examples: Brand
| brand|
| first Frog |
#FrogTwo
Examples: Brand
| brand|
| second Frog|
Then choose it at run time like so
behave -t FrogOne
or
behave --tags FrogOne
How do I write a scenario outline to test a calculation based on one variable which outputs 10 different variables?
I've tried various options and getting various errors including:
Unable to find option "<frequency>" (Capybara::ElementNotFound)
and
(Cucumber::ArityMismatchError)
The code below gives the Capybara::ElementNotFound error
Scenario Outline:
When I select "<frequency>" frequency
And I press recalculate
Then I should see total amount and percentages recalculated by <frequency> frequency on the results page
Examples:
| frequency |
| weekly |
| daily |
Examples:
| tax | sub-total | total |
| 38.25 | 114.74 | 191.24 |
| 3.19 | 9.56 | 15.94 |
Step definitions
When(/^I select "([^"]*)" frequency$/) do |frequency|
select "<frequency>", from: "frequency"
end
Then(/^I should see total amount and percentages recalculated by <frequency> frequency on the results page$/) do |table|
expect(results_page).to have_content("<tax>")
expect(results_page).to have_content("<sub_total>")
expect(results_page).to have_content("<total>")
end
form markup
<form action="change_result_frequency" method="post">
<label for="frequency">Frequency</label>
<select name="frequency" id="frequency">
<option value="yearly">yearly</option>
<option value="monthly">monthly</option>
<option selected="selected" value="weekly">weekly</option>
<option value="daily">daily</option>
</select>
<input type="submit" name="commit" value="Recalculate">
</form>
I am new to cucumber and capybara so I'm unsure how to write scenario outlines with data tables. What am I doing wrong?
What you are doing wrong is trying to write the detail about how your calculation works in your feature. Instead what you should be trying to do is use your feature to explain what you are doing (it has something to do with frequency, but otherwise I have no idea). When you take this approach you don't bother to specify the actual results in your scenarios for a number of reasons
The values of the results aren't that relevant to this sort of test.
Putting the results in the scenario is difficult, error prone (typos) and vastly increases maintenance costs
I'll explain point 1 a bit more.
What you should be doing in this scenario is driving the development of the change frequency functionality that you are working. This comprises of two parts
i) that you have a UI for the user to change the frequency, and that in response to this action your UI shows the results of the frequency change.
ii) that when you change the frequency the correct results are calculated
The first part, should be driven by a scenario in cucumber, so you can write something like
Given ...
When I change the frequency
Then I should see a new set of results
The second part SHOULD NOT be tested by writing scenarios in Cucumber. Instead you should be writing unit tests for the thing that does the frequency calculations. Writing unit tests allows you to
write much faster tests
write more tests so you can deal with edge cases
write your tests in a programming language so you can easily generate and use values of any type
The biggest mistake I see new users to Cucumber make nowadays is to use scenario outlines and example tables. I'd recommend you stay away from them. Every time you want to use one stop and have a think. Ask the questions
What am I testing here and why is it important
Am I trying to prove that something works? If so shouldn't I be using unit tests for the proof.
Good luck :)
You should only have one examples table with your Scenario Outline and you need to access the "variables" in the steps in your outline. So something like the following (with your step definitions updated accordingly)
Scenario Outline:
When I select "<frequency>" frequency
And I press recalculate
Then I should see <tax>, <sub-total>, and <total> recalculated on the results page
Examples:
| frequency | tax | sub-total | total |
| weekly | 38.25 | 114.74 | 191.24 |
| daily | 3.19 | 9.56 | 15.94 |
Is it possible to somehow construct a Scenario which uses two different Example tables in different steps? Something like this:
Given I log in
When I view a page
Then I should see <goodText>
Examples:
|goodText|
|abc|
And I should not see <badText>
Examples:
|badText|
|xyz|
The scenario above doesn't work, also in reality there would be more rows to each table.
It looks like you're confusing tables with scenario examples. You can mix them, but from your example I'm not sure what you're trying to achieve. Why not just write:
Given I log in
When I view a page
Then I should see "abc"
But I should not see "xyz"
or if you wanted to check for multiple strings:
Given I log in
When I view a page
Then I should see the following text:
| abc |
| def |
But I should not see the following text:
| xyz |
| uvw |
You say that in reality there would be many more rows to the table; but of course a table can also have many columns.
Would this not work for you?
Given I log in
When I view a page
Then I should see <goodText>
But I should not see <badText>
Examples:
|goodText| badText |
|abc | xyz |