Is it possible to generate example table for scenario in specflow? - bdd

The main problem is that example table is too long (below the example is a mock short, my real test would be ~300 lines). Is it possible to generate these table? I have mypage30.. it would be hard to maintain it
Scenario Outline: Check categories
Given I visit '<mypage>'
When I select '<category>'
Then the selected category is shown
Examples:
| mypage | category |
| page1 | mouse |
| page1 | cat |
| page1 | horse |
| page1 | do |
| page1 | duck |
| page2 | mouse |
| page2 | cat |
| page2 | horse |
| page2 | do |
| page2 | duck |

It's impossible to generate a content of .feature file automatically.
Yet I guess in your case you can make it other way.
One way is to store your table in .xlsx file and to use this file as a data source.
If you choose this option, it's very simply implemented in SpecFlow: https://specflow.org/plus/documentation/Prepare-feature-files-for-external-examples/
All you need is to specify the path to your source file:
#source:CalculatorExamples.xlsx
Examples:
| case | a | b | result |
Another way is to generate all the data within your test scenario. I don't know how you wanted to generate this table so I assume that the first way is better.

Related

BDD how can i write a table if I have more than one variable in Given conditions

Below id my scenario that I am trying to automate:
Scenario Outline: create an invoice selecting
Given following <payment_term> is selected
And following <delivery_terms> is selected
And following <verzenderijnr> is selected
Examples:
| payment_term | delivery_terms | verzenderijnr |
| 1 | 1 | 1 |
| 2 | 2 | 2 |
When i transition the document to "final_invoice"
Then i expect the following transaction in my administration:
Examples:
| journal.id | account.id | document_date | due_date |
| VRK1 | 10016 | "2018-12-17" | 2019-01-24 |
You should use example with "scenario outline" and not only with scenario.
also, Example table should come at end after all "Given When Then" statement.
I'm not 100% sure what you're trying to accomplish exactly, but wouldn't your scenario be more easier to read if done like this?
Scenario Outline: Determine due date for sales invoices
Given I am creating a sales invoice on <Invoice date>
When I should <Pay within days>
Then the <Due date> should be correct
Examples:
| Invoice date | Pay within days | Due date |
| 2018-12-18 | 5 | 2018-12-23 |
| 2018-12-29 | 5 | 2019-01-02 |

Behave - Common features between applications, avoiding duplication

I have many applications which I want to test, which have a largely overlapping set of features. Here is an oversimplified example of a scenario I might have:
Given <name> is playing a game,
When they shoot at a <color> target
Then they should <event>
Examples:
| name | color | event |
| Alice | red | hit |
| Alice | blue | miss |
| Bob | red | miss |
| Bob | blue | hit |
| Bob | green | hit |
It's a silly example, but suppose really I have a lot of players with different hit/miss conditions, and I want to run just the scenarios for a given name? Say, I only want to run the tests for Alice. There's still advantage to having all the hit/miss tests in a single Scenario Outline (since, after all, they're all closely related).
One approach would be to just duplicate the test for every name and tag them, so something like:
#Alice
Given Alice is playing a game
When she shoots at a <color> target
Then she should <event>
Examples:
| color | event |
| red | hit |
| blue | miss |
This way I can run behave --tags #Alice, But then I'm repeated the same scenario for every user, and that's a lot of duplication. Is there a good way to still compress all the examples into one scenario - but only selectively run some of them? What's the right approach here?
Version 1.2.5 introduced better ways to distinguish scenario outlines. It is now possible to uniquely distinguish them and thus select a unique scenario generated from an outline with --name= at the command line. For instance, suppose the following feature file:
Feature: test
Scenario Outline: test
Given <name> is playing a game,
When they shoot at a <color> target
Then they should <event>
Examples:
| name | color | event |
| Alice | red | hit |
| Alice | blue | miss |
| Bob | red | miss |
| Bob | blue | hit |
| Bob | green | hit |
Let's say I want to run only the test for Bob, red, miss. It is in the first table, 3rd row. So:
behave --name="#1.3"
will select this test. In version 1.2.5 and subsequent versions. A generated scenario gets a name which includes "#<table number>.<row number>" where <table number> is the number of the table (starting from 1) and <row number> is the number of the row.
This won't easily allow you to select all scenarios that pertain to a single user. However, you can achieve it in another way. You can split your examples in two:
Examples: Alice
| name | color | event |
| Alice | red | hit |
| Alice | blue | miss |
Examples: Bob
| name | color | event |
| Bob | red | miss |
| Bob | blue | hit |
| Bob | green | hit |
The table names will appear in the generated scenario names and you could ask behave to run all the tests associated with one table:
behave --name="Alice"
I do not know of a way to access the example name in steps and thus get rid of the first column.
The full set of details is in the release notes for 1.2.5.

Can I have a cucumber example with several values in a single column x row position

Hi here is what I what I have:
Scenario Outline: Seatching for stuff
Given that the following simple things exists:
| id | title | description | temp |
| 1 | First title | First description | low |
| 2 | Second title | Second description with öl | Medium |
| 3 | Third title | Third description | High |
| 11 | A title with number 2 | can searching numbers find this 2 | Exreme |
When I search for <criteria>
Then I should get <result>
And I should not get <excluded>
Examples
|criteria|results | excluded |
| 1 | 1 | 2,3,11 |
| 11 | 11 | 1,2,3 |
| title | 1,2,3 | 11 |
| öl | 2 | 1,3,11 |
| Fir* | 1 | 2,3,11 |
| third | 3 | 1,2,11 |
| High | 3 | 1,2,11 |
As you can see I'm trying to test a search field for a web-application using cucumber and the scenario outline structure in order to test several search criteria.
I'm not sure how to handle the input I would get as result and excluded in my steps.
Maybe this doesn't work at all?
Is there a workaround?
There's nothing wrong with what you're doing. Cucumber will just take that as a single string. The fact that it's actually comma-separated values means nothing to Cucumber.
Your step definition would still look like this:
Then /^I should not get ([^"]*)$/ do |excluded|
# excluded will be a string, "2,3,11"
values = excluded.split(",")
# Do whatever you want with the values
end

Rails - Create form fields dynamically and save them

I'm building an ad-system where users can dynamically create 'fields' for each ad type.
My models and example values:
AdType:
| id | name
|----|-----
| 1 | Hotel
| 2 | Apartment
AdOption:
| id | ad_type_id | name
|----|------------|-----
| 1 | 1 | Star rating
| 2 | 1 | Breakfast included?
| 3 | 2 | Number of rooms
AdValue: (Example after saving)
| id | ad_id | ad_option_id | value
|----|-------|---------------|------
| 1 | 1 | 1 (stars) | 5
| 2 | 1 | 2 (breakfast) | true
Ad: (Example after saving)
| id | description | etc....
|----|-----------------|--------
| 1 | very nice hotel | .......
So let's say I want to create a new ad, and I choose Hotel as the ad type.
Then I need my view to dynamically create fields like this: (I'm guessing?)
[Label] Star rating:
[hidden_field :ad_id] [hidden_field :ad_option_id] [text_field :value]
[Label] Breakfast included?
[hidden_field :ad_id] [hidden_field :ad_option_id] [text_field :value]
And also, how to save the values when the ad record is saved
I hope this is understandable. If not just ask and I'll try to clarify.
Start with the initial field in your form (AdType), then use javascript event listeners to check which option has been selected, and populate the field with the appropriate html.
jQuery probably has plugins that would do this for you, but coding it in plain JavaScript shouldn't be too difficult.

Is it possible to link to a bookmark within a PDF using URL parameters?

When providing a link to a PDF file on a website, is it possible to include information in the URL (request parameters) which will make the PDF browser plugin (if used) jump to a particular bookmark instead of just opening at the beginning?
Something like: http://www.somehost.com/user-guide.pdf?bookmark=chapter3 ?
If not a bookmark, would it be possible to go to a particular page?
I'm assuming that if there is an answer it may be specific to Adobe's PDF reader plugin or something, and may have version limitations, but I'm mostly interested in whether the technique exists at all.
Yes, you can link to specific pages by number or named locations and that will always work if the user's browser uses Adobe Reader as plugin for viewing PDF files.
For a specific page by number:
Link text
For a named location (destination):
Link text
To create destinations within a PDF with Acrobat:
Manually navigate through the PDF for the desired location
Go to View > Navigation Tabs > Destinations
Under Options, choose Scan Document
Once this is completed, select New Destination from the Options menu and enter an appropriate name
RFC 3778 section 3 specifies "Fragment Identifiers" that can be used with PDF files, which include nameddest and page.
There are multiple query parameters that can be handled.
Full list below:
Source
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| Syntax | Description | Example |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| nameddest=destination | Specifies a named destination in the PDF document | http://example.org/doc.pdf#Chapter6 |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| page=pagenum | Specifies a numbered page in the document, using an integer | http://example.org/doc.pdf#page=3 |
| | value. The document’s first page has a pagenum value of 1. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| comment=commentID | Specifies a comment on a given page in the PDF document. Use | #page=1&comment=452fde0e-fd22-457c-84aa- |
| | the page command before this command. | 2cf5bed5a349 |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| collab=setting | Sets the comment repository to be used to supply and store | #collab=DAVFDF#http://review_server/Collab |
| | comments for the document. This overrides the default comment | /user1 |
| | server for the review or the default preference. The setting is of the | |
| | form store_type#location, where valid values for store_type are: | |
| | ● DAVFDF (WebDAV) | |
| | ● FSFDF (Network folder) | |
| | ● DB (ADBC) | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| zoom=scale | Sets the zoom and scroll factors, using float or integer values. For | http://example.org/doc.pdf#page=3&zoom=200,250,100 |
| zoom=scale,left,top | example, a scale value of 100 indicates a zoom value of 100%. | |
| | Scroll values left and top are in a coordinate system where 0,0 | |
| | represents the top left corner of the visible page, regardless of | |
| | document rotation | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| view=Fit | Set the view of the displayed page, using the keyword values | http://example.org/doc.pdf#page=72&view=fitH,100 |
| view=FitH | defined in the PDF language specification. For more information, | |
| view=FitH,top | see the PDF Reference. | |
| view=FitV | Scroll values left and top are floats or integers in a coordinate | |
| view=FitV,left | system where 0,0 represents the top left corner of the visible | |
| view=FitB | page, regardless of document rotation. | |
| view=FitBH | Use the page command before this command. | |
| view=FitBH,top | | |
| view=FitBV | | |
| view=FitBV,left | | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| viewrect=left,top,wd,ht | Sets the view rectangle using float or integer values in a | |
| | coordinate system where 0,0 represents the top left corner of the | |
| | visible page, regardless of document rotation. | |
| | Use the page command before this command. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| pagemode=bookmarks | Displays bookmarks or thumbnails. | http://example.org/doc.pdf#pagemode=bookmarks&page=2 |
| pagemode=thumbs | | |
| pagemode=none | | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| scrollbar=1|0 | Turns scrollbars on or off | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| search=wordList | Opens the Search panel and performs a search for any of thewords in the specified word list. | #search="word1 word2" |
| | The first matching word ishighlighted in the document. | |
| | The words must be enclosed in quotation marks and separated byspaces. | |
| | You can search only for single words. You cannot search for a string of words. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| toolbar=1|0 | Turns the toolbar on or off. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| statusbar=1|0 | Turns the status bar on or off. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| messages=1|0 | Turns the document message bar on or off. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| navpanes=1|0 | Turns the navigation panes and tabs on or off. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| highlight=lt,rt,top,btm | Highlights a specified rectangle on the displayed page. Use the | |
| | page command before this command. | |
| | The rectangle values are integers in a coordinate system where | |
| | 0,0 represents the top left corner of the visible page, regardless of | |
| | document rotation | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| fdf=URL | Specifies an FDF file to populate form fields in the PDF file beingopened. | #fdf=http://example.org/doc.fdf |
| | Note: The fdf parameter should be specified last in a URL. | |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
It's worth adding that Wayne's solution also works in:
Chrome (since v. 14 from 2011, see this issue for details) (tested on v. 87 and v. 44),
Firefox (tested on v. 84.0.1 and v. 40),
Opera (tested on v. 73 and v. 31),
Safari (tested on v. 14.0.2, it didn't work on v. 8),
(Updated with the current versions as of January 2021.)
PDF Open Parameters documents the available URL fragments you can use.

Resources