Behat: How do you use multiline values in tables? - behat

How do you use multiline values in tables?
Pystring dont work
| single | multi
| qewr | """
qewrqewr
qwerqre
"""
This doesnt either
| single | multi
| qewr | qewrqewr
| qwerqre
I want to use a scenario outline and seed a form with input multiple times, not having multilines would be a bugger.

You can use "," in your tables. For example:
| single | multi |
| one | one, two |
If you use TableNode extension, check your extension Gherkin.
It possible need upgrade.
https://github.com/Behat/Behat/issues/99
I hope that was helpful, though a bit late.

Related

Can i pass variable from Example section into table in behave scenario?

Can i do something like this:
Response contains requested data
| method | status | url |
| post | 200 | <url_variable>|
Examples:
|url_variable|
| test1 |
|test2 |
Its a simple example just to show what i want. Is it possible in behave anyhow?
Basically i should have just tried what i suggested) it is literally like that, write variable name inside a table in <> quotes. And behave will understand it.

Conditional update column B with modified value based on column A

I am facing a large table with data that got imported from a csv. However the delimiters in the csv where not sanitized, so the input data looked something like this:
alex#mail.com:Alex
dummy#mail.com;Bob
foo#bar.com:Foo
spam#yahoo.com;Spam
whatever#mail.com:Whatever
During the import : was defined as the delimiter, so each row with the delimiter ; was not imported properly. This resulted in a table structured like this:
| ID | MAIL | USER |
|-- --|---------------------|----------|
| 1 | alex#mail.com | ALEX |
| 2 | dummy#mail.com;Bob | NULL |
| 3 | foo#bar.com | Foo |
| 4 | spam#yahoo.com;Spam | NULL |
| 5 | whatever#mail.com | Whatever |
As reimporting is no option I was thinking about manually sanitizing the data in the affected rows by using SQL queries. So I tried to combine SELECT and UPDATE statements by filtering rows WHERE USER IS NULL and update both columns with the correct value where applicable.
What you need are string functions. Reading a bit, I find that Google BigQuery has STRPOS() and SUBSTR().
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#substr
https://cloud.google.com/bigquery/docs/reference/standard-sql/string_functions#strpos
An update query to fix the situation you are describing looks like this:
update table_name set mail =SUBSTR(mail,1,STRPOS(mail,';')-1), user =SUBSTR(mail,STRPOS(mail,';')+1) where user is null
The idea here is to split mail in its two parts, the part before the ; and the part after. Hope this helps.

Can i have data tables in the examples of cucumber?

I am looking for something like below . Let me know if we have a way to do it .
Scenario Outline : Verify
Examples :
| name | rollno | marks |
| raj | 110 | |science | maths | test | |
| 95 | 20 | finaltest |
| 100 | 20 | midterm |
Nested data tables are not supported in examples.
Why not move the science, maths marks up a level instead?
Or you could use a delimited string of all the subject and marks in one column - Science$95#Maths$20... Split this in your step definition to create your objects etc.
Or one column with a delimited string of subjects and another a delimited string with marks of the respective subjects. Makes things clearer than one string but you will need the splitting logic twice.

Problems with using the bootstrap-datepicker in Fitnesse Tests

In my Fitnesse Tests I want to enter dates through datepicker elements. Sometimes it works. But most of the time a different date, unlike the date that was entered, appears. Here is an example:
| ensure | do | type | on | id=field_id | with | |
| ensure | do | type | on | id=field_id | with | 05.05.1997 |
| check | is | verifyValue | on | id=field_id | [28.05.1997] expected [05.05.1997] |
(To make sure that the field isn't already filled, I pass an empty String first.)
Mostly, the 'day'-statement is different from what was entered. Do you know the reason for this behavior? How can I solve this?
Thanks in advance!
This is related to how you wrote your fixture and not FitNesse, the problem is that it returns a different value and also implies that the previous line didn't work - | ensure | do | type | on | id=field_id | with | 05.05.1997 |

Multidimensional Tables in PostgreSQL

I have been wondering whether it's possible to do multidimensional tables in PostgreSQL. Here's an example table from my project:
id | created_by | content | comments |
---+---------------+----------------------------+----------+
1 | Anonymous | does this thing work? | |
2 | James | this is the body | |
3 | Chan | this must work this time~! | |
4 | Freak | just to add something new | |
5 | Anonymous | yahoo! | |
What do I mean by multidimensional table? It would look like something like this if there's such thing.
id | created_by | content | comments |
---+---------------+----------------------------+------------------------------------------+
1 | Anonymous | does this thing work? | id | created_by | comments |
2 | James | this is the body | |created_by| comments |
3 | Chan | this must work this time~! | |
4 | Freak | just to add something new | |
5 | Anonymous | yahoo! | |
This is just an example. But the key concept is that in every comment, there's another set of columns, making comments sort of like a table by itself.
So yeah, does this exist in Postgres or is there any better way to implement this feature? :)
I would like to convince you, if possible, to not encode your data this way, (independent of how terrible an idea it is)
Lets suppose you have a really hot post, goes viral, et-cetera. That means all of your users are viewing it and many are trying to comment on it. with all of your nested discussion embedded in a single row, all updates must apply to that row. This in turn means that every update on that discussion competes with every other to update that one attribute. As you might imagine, this write contention will make your database slow way down.
A second reason is that it violates the rules of first normal form; in the sense that the comment attribute on the table you're showing contains more than one value. The motivating reasoning for this widely applied rule is that it makes a larger number of queries possible. In your design, it would be very difficult to delete from COMMENTS where USER = 'spammy-user'*, or even select * from COMMENTS where text like '%Trending Topic%'. In general, if you might ever want to look at part of a value in a column, rather than the whole thing, then you're probably looking at an opportunity for normalization.
The rule I try to use is "each 'kind of thing' gets its own table". as comments are a 'kind of thing', we'll split them out:
create table COMMENTS(
COMMENT_ID serial primary key,
POST_ID integer not null foreign key references POSTS(ID),
PARENT_COMMENT_ID integer foreign key references COMMENTS(COMMENT_ID),
CREATED_BY ...
CONTENT ...
)
with the convention that comments having a null parent_comment_id are the roots of threaded discussions.