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 |
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
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.
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
I have some documents to upload it. For that, I wrote a scenario. I need to run the same feature file multiple times. How can I run the feature file Multiple times?
Instead of using multiple feature file use scenario outline which will execute the same scenario multiple time as per the example table you will provide to it
Example:
Scenario Outline: Create ABC
Given I open the application
When I enter username as <username>
And I enter password as <password>
Then I enter title as <title>
And press submit
Examples:
| username | password | title |
| Rob | xyz1 | title1 |
| Bob | xyz1 | title2 |
So here the same scenario will run 2 times as example table have 2 data, you can add as many data table and cucumber will execute that number of times
I'm having sphinx index to search users by names.
I'm using soundex morphology to show more relevant results for case searcher doesn't exactly know how the name spells. Consider following table:
+----+--------------------+
| id | name |
+----+--------------------+
| 1 | Maciej Makuszewski |
| 2 | Dane Massey |
| 3 | Lionel Messi |
| 4 | Mr. No Matches |
+----+--------------------+
With soundex enabled sphinx suggests 1, 2, 3 rows as a relevant result for query messi. Anyway I'd like to show the exact matching first. I mean that if user types messi he wants to see Lionel Messi the first with great probability.
My problem is I don't know how to do that. I tried to set different rankers but it gives nothing.
I also tried to add
index_exact_words = 1
to index but it gives nothing.
I'm using sphinx API with node.js sphinxapi module if it matters.
What is the common way of solving such issue?
You want, index_exact_words, but should also add expand_keywords
This will cause sphinx to search for the fuzzy (via morphology) AND the exact word (via index_exact_words) automatically. So an exact match, matches both, and ranks higher.
Can do the same manually by searching for say
messi | =messi
(which is similar to what expand_keywords does internally)