Should all fields that are visible on a screen be validated in Gherkin? - cucumber

We are creating Gherkin feature files for our application to create executable specifications. Currently we have files that look like this:
Given product <type> is found
When the product is clicked
Then detailed information on the product appears
And the field text has a value
And the field price has a value
And the field buy is available
We are wondering if this whole list of and keywords that validate if fields are visible on the screen is the way to go, or if we should shorten that to something like 'validate input'.

We have a similar case in that our service can return a lot of 10's of elements for each case that we could validate. We do not validate every element for each interaction, we only test the elements that are relevant to the test case.
To make it easier to maintain and switch which elements we are using, we use scenario outlines and tables of examples.
Scenario Outline: PO Boxes correctly located
When we search in the USA for "<Input>"
Then the address contains
| Label | Text |
| PO Box | <PoBox> |
| City name | <CityName> |
| State code | <StateCode> |
| ZIP Code | <ZipCode> |
| +4 code | <ZipPlus4> |
Examples:
| ID | Input | PoBox | CityName | StateCode | ZipCode |
| 01 | PO Box 123, 12345 | PO Box 123 | Boston | MA | 12345 |
| 02 | PO Box 321, Whitefish | PO Box 123 | Whitefish | MN | 54321 |
By doing it this way, we have a generic step "the address contains" that uses the 'Label' and 'Text' to test the individual elements. It is a neat and tidy way to test a lot of potential combinations - but it probably depends on your individual use case - how important all of the fields are.

You only need to validate the ones that provide business value, which is probably all of them. I would avoid using tech terms like "field" because it isn't related to a behavior. Al Mills is right on for using the tables.
I'd word it like this:
Scenario Outline: Review product details
Given I find the product <Type>
When I select the product
Then detailed information on the product appears including
| Description | <Description> |
| Price | <Price> |
And I can buy the product
Examples:
| Type | Description | Price |
| Hose | Rubber Hose | 31.99 |
| Sprinkler | Rotating Sprinker | 12.99 |
The words I chose are behaviors or whats, not technical implementations or hows.

Related

pyexcel - is there a way to get the column width?

I have an excel sheet that I can display via pyexcel.get_book like this:
+------------------------+-------+---------------+--------------+-----------------------------------------------------------------+------------------------+----------+
| Rec No. | Title | Forenames | Surname | Address | Plaintiff Name | Amount |
+------------------------+-------+---------------+--------------+-----------------------------------------------------------------+------------------------+----------+
| 01 | MR | GUY PERSON | FITZGERALD | 69 BLAZEIT TERRACE, BAGEL ROAD, ST SAVIOUR, GERBILTONG, JE2 7TR | BANANA COMPANY LIMITED | 69420.69 |
+------------------------+-------+---------------+--------------+-----------------------------------------------------------------+------------------------+----------+
Is there a way to determine the width of the column that pyexcel calculates to display the table above (address is longer than the rest for example)? Like a col.width?
I want to convert this table to an image that takes up the full width of a page. The columns are of different widths, which I would like to use.

SpecFlow - Is it possible to reuse test data within feature file?

Is there any way to reuse data in SpecFlow feature files?
E.g. I have two scenarios, which both uses the same data table:
Scenario: Some scenario 1
Given I have a data table
| Field Name | Value |
| Name | "Tom" |
| Age | 16 |
When ...
Scenario: Some scenario 2
Given I have a data table
| Field Name | Value |
| Name | "Tom" |
| Age | 16 |
And I have another data table
| Field Name | Value |
| Brand | "Volvo" |
| City | "London" |
When ...
In these simple examples the tables are small and there not a big problem, however in my case, the tables have 20+ rows and will be used in at least 5 tests each.
I'd imagine something like this:
Having data table "Employee"
| Field Name | Value |
| Name | "Tom" |
| Age | 16 |
Scenario: Some scenario 1
Given I have a data table "Employee"
When ...
Scenario: Some scenario 2
Given I have a data table "Employee"
And I have another data table
| Field Name | Value |
| Brand | "Volvo" |
| City | "London" |
When ...
I couldn't find anything like this in SpecFlow documentation. The only suggestion for sharing data was to put it into *.cs files. However, I can't do that because the Feature Files will be used by non-technical people.
The Background is the place for common data like this until the data gets too large and your Background section ends up spanning several pages. It sounds like that might be the case for you.
You mention the tables having 20+ rows each and having several data tables like this. That would be a lot of Background for readers to wade through before the get to the Scenarios. Is there another way you could describe the data? When I had tables of data like this in the past I put the details into a fixtures class in the automation code and then described just the important aspects in the Feature file.
Assuming for the sake of an example that "Tom" is a potential car buyer and you're running some sort of car showroom then his data table might include:
| Field | Value |
| Name | Tom |
| Age | 16 |
| Address | .... |
| Phone Number | .... |
| Fav Colour | Red |
| Country | UK |
Your Scenario 2 might be "Under 18s shouldn't be able to buy a car" (in the UK at least). Given that scenario we don't care about Tom's address phone number, only his age. We could write that scenario as:
Scenario: Under 18s shouldnt be able to buy a car
Given there is a customer "Tom" who is under 16
When he tries to buy a car
Then I should politely refuse
Instead of keeping that table of Tom's details in the Feature file we just reference the significant parts. When the Given step runs the automation can lookup "Tom" from our fixtures. The step references his age so that a) it's clear to the reader of the Feature file who Tom is and b) to make sure the fixture data is still valid.
A reader of that scenario will immediately understand what's important about Tom (he's 16), and they don't have to continuously reference between the Scenario and Background. Other Scenarios can also use Tom and if they are interested in other aspects of his information (e.g. Address) then they can specify the relevant information Given there is a customer "Tom" who lives at 10 Downing Street.
Which approach is best depends how much of this data you've got. If it's a small number of fields across a couple of tables then put it in the Background, but once it gets to be 10+ fields or large numbers of tables (presumably we have many potential customers) then I'd suggest moving it outside the Feature file and just describing the relevant information in each Scenario.
Yes, you use a background, i.e. from https://github.com/cucumber/cucumber/wiki/Background
Background:
Given I have a data table "Employee"
| Field Name | Value |
| Name | "Tom" |
| Age | 16 |
Scenario: Some scenario 1
When ...
Scenario: Some scenario 2
Given I have another data table
| Field Name | Value |
| Brand | "Volvo" |
| City | "London" |
If ever you aren't sure I find http://www.specflow.org/documentation/Using-Gherkin-Language-in-SpecFlow/ a great resource

CSV file always picks the lowest price

Hi I am using Magento and an extension called matrix rates, they use .CSV files to store the data for the post codes saying what post code has what delivery charge. The problem I have got is that it only picks the smallest delivery charge for every single postcode when it should look at the rate for the post code first and then if there isn't one pick the flat rate. I was just wondering if anybody has any ideas.
My excel sheet is like this>>
Country | Region/State | City | Zip/Postal Code From |Zip/Postal Code To | Weight From | Weight To | Shipping Price | Delivery Type
GBR | * | - | - | 0 | 9999 | 9999 | Websales Shipping (WS01)
GBR | * | - | - | AB37% | 0 | 9999 | 65 | Websales Shipping (WS01)
Without more details, your pseudo-code (or, pseudo-formula) could look like this:
=if(
vlookup([postCode], [PostCodeShipRateTable], [rateColumn]) >0,
[postcodeRate],
[flatRate]
)
[flatRate] could also be a vlookup to another rate table if nec.

How to present/organize repetitive data contained in cells in excel?

Would there be a better way to present/organize repetitive data contained in cells in excel? I've provided a set of sample data below (I can't show my actual records for confidentiality reasons) just so that you guys could visualize the data.
Country | Type | Company | Department | Project | Currency | Amount
USA | Restaurant | Bob's Barbeque | Sanitation | Monthly Sanitation | Records Database | USD | 100
USA | Restaurant | Bob's Barbeque | Human Resources | Staff Timesheet USD | 203
USA | Restaurant | Bob's Barbeque | Human Resources | Email Portal for Employees | USD | 259
USA | Manufacturing | Duff Autos | Research and Development | Inventory System| USD | 234
USA | Manufacturing | Duff Autos | Sales | Inventory System | USD | 654
China | Manufacturing | Weihua Electronics | Research and Development | Inventory System | RMB | 102
China | Government | Department of Tourism | Advertisement | Billboard Design and Deployment Web Portal | RMB | 2044
As you can see, it contains a lot of repetitive data like the "Country" and the "Type". It may look organized as it is but it looks cluttered as the data multiplies. I've thought this thoroughly over the past few days but I still can't figure out a way to do organize it such that it would look pretty.
I've tried Excel's filter functionality, sorting, and others but I still think it looks cluttered. Any suggestions? Thanks!
Pivot the data, then you can open and close the sections as you please. I just did it on your sample, then in the resulting pivot tick all the fields, drag the amount one from row labels to values then click on the little down arrow and choose value field settings.
Select Sum and press OK.
the + and - on the data in the pivot allows you to fold open and close the fields to make it look however you like.

How should I name my steps in a scenario outline

I've got a handful of specflow tests that look something like this:
Scenario: Person is new and needs an email
Given a person
And the person does not exist in the repository
When I run the new user batch job
Then the person should be sent an email
Scenario: Person is not new and needs an email
Given a person
And the person does exist in the repository
When I run the new user batch job
Then the person should not be sent an email
Except instead of just 2 scenarios, I've got 10 very similar scenarios, all with the type of steps so I want to use a "Scenario Outline". Unfortunately, I'm having a really hard time coming up with a readable way to re-write my steps.
Currently, I've come up with this but looks clunky:
Scenario: Email batch job is run
Given a person
And the person '<personDoes/NotExist>' exist in the repository
When I run the new user batch job
Then the person '<personShould/NotGetEmail>' be sent an email
Examples:
| !notes | personDoes/NotExist | personShould/NotGetEmail |
| Exists | does not | should |
| No Exist | does | should not |
I also considered this, and while it is cleaner it doesn't convey meaning nearly as well
Scenario: Email batch job is run
Given a person
And the person does exist in the repository (is '<personExist>')
When I run the new user batch job
Then the person should be sent an email (is '<sendEmail>')
Examples:
| !notes | personExist | sendEmail |
| Exists | false | true |
| No Exist | does | false |
Does anybody have a better way of parameterizing concepts like "does", "does not", "should", "should not", "has", "has not"? At this point, I'm thinking about leaving the everything as a different scenario because it is more readable.
Here is what I've done in the past:
Given these people exist in the external system
| Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following people exist in the account repository
| Id | External Id | First Name | Last Name |
| 45 | 1 | John | Galt |
When I run the new user batch job
Then the following people should exist in the account repository
| External Id | First Name | Last Name | Email |
| 1 | John | Galt | x |
| 2 | Howard | Roark | y |
And the following accounts should have been sent an email
| External Id | Email |
| 2 | y |
You can use the table.CreateSet() and table.CreateSet() helper methods in SpecFlow to quickly turn the tables into data for your fake external system repository and your account table in the database.
Then you can use table.CompareToSet(accountRepository.GetAccounts() to compare the table in your "Then" clause to the records in your database.
The neat thing is, all of the steps you wrote are reusable for multiple situations. All you do is change the data in the tables, and SpecFlow writes the tests for you.
Hope that helps!
Maybe you should split them into two scenarios
Scenario Outline: User exists in the repository
Given a person
| Field | Value |
| First | <first> |
| Last | <last> |
And the person exists in the repository
When the user attempts to register
Then the person should be sent an email
Examples:
| first | last |
| Bob | Smith |
| Sarah | Jane |
And then another scenario for the opposite. This keeps the scenario meaning very clear. If your common steps are worded genericly you can reuse them. I also try to come from the approach of the user

Resources