Can you use parameter/variables/placeholders for values for future use in a Specflow scenario? - specflow

In previous job I have used DBFit and used parameters (variables/placeholders) for values
example:
|Key? |
|>>Key|
!|Query|SELECT Status FROM Confirm WHERE Name='xyz' |
| Status | Key |
| Confirmed | <<Key |
I am now using SpecFlow and wondered if it has similar functionality
example: ( I have used << and >> here just for explanation )
Given I get Initial for
And the 1st response should contain
| Name | string | "xyz" |
| Key | string | >>{Key} |
When I get Confirm for
Then the 1st response should contain
| Name | string | "xyz" |
| Key | string | <<{Key} |

I think you are looking for Scenario Outlines.
With them, you can specify a table with your parameters. So in your case, it is looking something like this:
Scenario Outline: Title for your Scenario Outline
Given I get Initial for And the 1st response should contain
| field | type | assertion |
| Name | string | "xyz" |
| Key | string | <Key> |
When I get Confirm for
Then the 1st response should contain
| field | type | assertion |
| Name | string | "xyz" |
| Key | string | <Key> |
Examples:
| Key |
| example1 |
| example2 |
| example3 |
Be aware that you have here two different types of tables. The table at your steps is an argument for the step.
The Examples table at the end are the concrete examples. So the Scenario is executed once per each entry in this table.
You can use the parameters from the example table with a simple <COLUMN_NAME> placeholder.
Docs: https://docs.specflow.org/projects/specflow/en/latest/Gherkin/Gherkin-Reference.html#scenario-outline

Related

How to select all columns from a join table in vapor 4?

It seems that vapor add a new feature eagerLoad and remove alsoDecode. It is convenient for those which possessing parent-child or sibling relationships. But not for those without relationship.
I want to implement a tree structure whose nodes cannot be (or I don't know how to) involved in a relationship. Nodes have a parent and many children which are nodes too.
So I have three tables for this structure.
Tree:
| Field | Type |
| ----------- | --------------- |
| id | UUID? |
| name | String |
| nodes | [Node] |
| paths | [Path] |
Nodes:
| Field | Type |
| ------------- | -------------------------- |
| id | UUID? |
| type | NodeType(root, leaf, node) |
| tree | Tree |
Path:
| Field | Type |
| ------------ | --------- |
| id | UUID? |
| distance | Int |
| ancestorID | UUID |
| descendantID | UUID |
| tree | Tree |
The question is
if I want to do
SELECT Nodes.id, Nodes.type, Path.ancestorID from Nodes
INNER JOIN Path
ON Nodes.id = Path.descendantID
How to write the codes.
You could also choose to cast to SQLDatabase.
Make sure to import SQLKit too, a Fluent database can always be casted as SQLDatabase.
For example: let sqlDb = req.db as? SQLDatabase would give you the power to use custom queries like: sqlDb?.select().from("Nodes").join("Path", on: "Nodes.id = Path.descendantId").all()
For more info on SQLKit see: https://github.com/vapor/sql-kit
Reference: https://docs.vapor.codes/4.0/fluent/advanced/ (Any Fluent Database can be cast to a SQLDatabase. This includes req.db, app.db, the database passed to Migration, etc.)

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 |

Extract UUID from a mixed string in mariadb

I have a mariadb table as follows:
This is an example of how a row looks like
| 4 | test/1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd/kuva.jpeg | {"Records":
The content in Records have been omitted to keep it short and simple. When I issue SQL select like this select key_name from minio_images where id=4;, it returns me a normal output like this
+-----------------------------------------------------+
| key_name |
+-----------------------------------------------------+
| test/1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd/kuva.jpeg |
+-----------------------------------------------------+
1 row in set (0.09 sec)
My question is how can I use select so that it just returns me the UUID in key_name instead of the whole string. For example, 1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd and not test/1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd/kuva.jpeg? I'd really appreciate any sort of help with this.
Luckily, I found a similar post # extract substring from mysql column using regex and I tried a solution suggested there, by issuing a SELECT statement which I guess, returns the value from a column based on the regular expression. In my case, the regular expression to extract UUID is '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}' and the statement was like
SELECT REGEXP_SUBSTR(key_name, '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}')
FROM minio_images;
Which gave me an output, just like I needed
+--------------------------------------------------------------------------------------------------------+
| REGEXP_SUBSTR(key_name, '[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}') |
+--------------------------------------------------------------------------------------------------------+
| 1ecb5e71-9105-4a0c-8fa1-7fc8d5e970bd |
| 1edd460e-b19a-4b16-a460-d433eac60833 |
| 281a890f-0b8b-4693-9227-fc8c57d6045e |
| 37a14ddb-eeda-41f2-a2b6-ec0bad34aaed |
| 37d4f3d2-2282-4b9f-8e1e-f8a26570c5b4 |
| 387da0c1-1caf-4394-a023-92e7eec19b66 |
| 49a29478-4799-4a8b-8757-42060020fc99 |
| 9214e1f0-77e3-435a-a329-d1829a973903 |
| ae67c69a-a2cf-4c21-88ca-bd17e254bc4c |
| b6491e64-34a6-4aa3-a54e-200b1cd946fe |
| c0f6864b-2ab8-41fa-a1c2-6b974a1895c1 |
| cfd61927-557e-47d2-aeb9-229ec1aba5b4 |
| df566110-c2a0-4d9c-8389-fcbaf6c8bb30 |
+------------------------------------------------------------------------------------- -------------------+
16 rows in set (0.03 sec)

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

SpecFlow - Repeat test X times with list?

Scenario: Change a member to ABC 60 days before anniversary date
Given Repeat When+Then for each of the following IDs:
| ID |
| 0047619101 |
| 0080762602 |
| 0186741901 |
| 0311285102 |
| 0570130101 |
| 0725968201 |
| 0780265749 |
| 0780265750 |
| 0780951340 |
| 0780962551 |
#-----------------------------------------------------------------------
When these events occur:
| WorkflowEventType | WorkflowEntryPoint |
| ABC | Status Change |
Then these commands are executed:
| command name |
| TerminateWorkflow |
And For Member, the following documents were queued:
| Name |
| ABC Packet |
In the above scenario I would like to:
GIVEN - Lookup 10 members from the DB
WHEN + THEN - Do these steps 10 times, once for each record.
Is this possible with SpecFlow?
If so, how would you set it up?
TIA
This is actually quite easy to do, although the documentation takes a bit of searching.
What you want is a scenario outline, like so:
Scenario Outline: Change a member to ABC 60 days before anniversary date
Given I have <memberId>
When these events occur:
| WorkflowEventType | WorkflowEntryPoint |
| ABC | Status Change |
Then these commands are executed:
| command name |
| TerminateWorkflow |
And For <memberId>, the following documents were queued:
| Name |
| ABC Packet |
Examples:
| memberId |
| 0047619101 |
| 0080762602 |
| 0186741901 |
| ...etc... |
This will execute your scenario once for each id in the examples table. You can extend the table to have multiple columns, if needed.
Or, more simply (if you really only have one row in each of your example tables above)
Scenario Outline: Change a member to ABC 60 days before anniversary date
Given I have <memberId>
When A 'ABC' Event Occurs with EntryPoint 'Status Change'
Then a TerminateWorkflow command is executed
And For <memberId>, the 'ABC Packet' document was queued
Examples:
| memberId |
| ...etc... |
For more information see the specflow-wiki on github and the cucumber language syntax for scenario outlines

Resources