Use a variable (from example) within a datatable

31 views
Skip to first unread message

Jurn van Mieghem

unread,
Dec 21, 2016, 9:44:05 AM12/21/16
to Cukes
For my project we use datatables to insert some required data on trains (the examples are more basic than the real ones but the cover the issue at hand).

Given a train
 
| action | time   | track   |
 
| V      | 10:00  | Ut.1    |
 
| A      | 10:20  | Asd.1   |


However I would like to be able to make for instance the time a variable like we can do in a Scenario Outline with <mytime_1>;

Given a train
 
| action | time        | track    |
 
| V      | <mytime_1>  | Ut.1     |
 
| A      | <mytime_2>  | Asd.1    |

Examples:
 
| mytime_1 | mytime_2 |
 
| 10:00    | 10:20    |


Unfortunately this is passed into my datatable as a string <mytime_1> instead of the example value.
How can I fix this or is this simply not possible?

Andrew Premdas

unread,
Dec 21, 2016, 9:55:56 AM12/21/16
to cu...@googlegroups.com
I don't think you can do this. More importantly I don't think you should want to do this. You already have quite complex examples using example tables. Now you are adding to that complexity by using scenario outlines. Together these make your scenarios

1. Error prone: its easy for typos to break scenarios
2. Difficult to understand, you are relying on the example data to explain 'implicitely' what should be happening

Instead (IMO) what you should be doing is trying to get rid of as much example data is possible by making clear using natural language what you are trying to do with these scenarios and why its important. This is quite hard, as you have to examine how your are using your example data, then find names for the things your are trying to achieve, and find the language and structure to express this stuff clearly and succinctly. But if you do this you end up with a much clearer specification that communicates the really important things. This is particularly beneficial to developers and the long term maintainers of your code.

Anyhow I hope thats of some use

All best

Andrew

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Jurn van Mieghem

unread,
Dec 23, 2016, 3:41:16 AM12/23/16
to Cukes
Thanks Andrew

From a cucumber perspective I wasn't to keen on the DataTables with data, however this made life easier for us as providing the same data (as all fields are crucial for the test) in text will make less readable sentences or a lot more sentences.
But I might rethink our structure.

If there is however a solution to this issue I would be very keen to hear it ;)

Andrew Premdas

unread,
Dec 23, 2016, 3:50:49 PM12/23/16
to cu...@googlegroups.com
On 23 December 2016 at 08:41, Jurn van Mieghem <jvmi...@gmail.com> wrote:
Thanks Andrew

From a cucumber perspective I wasn't to keen on the DataTables with data, however this made life easier for us as providing the same data (as all fields are crucial for the test) in text will make less readable sentences or a lot more sentences.
But I might rethink our structure.


Whether the fields are crucial to your test or not is totally irrelevant to whether they should appear in the text describing your test, i.e. the GWT of your scenario. GWT is about communicating what you are doing and why you are doing it, not how things are being done. Its a higher level of abstraction and delegates the checking of fields and data to the implementation (it pushes the how down!!)

The best place to define what fields are important and ensure they are correct is in the code itself. Example data in scenarios prove nothing at all. The only reason for having them is to communicate.


If there is however a solution to this issue I would be very keen to hear it ;)

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nguye...@yahoo.com

unread,
Jan 6, 2017, 8:44:33 AM1/6/17
to Cukes
Jurn,
  At the code level when you parse the table you can set the time stamps for V and A from a set of variables that you saved from the previous steps.
  Now, when you specify you train table you can say :
Given a train
 
| action | time         | track   |

 
| V      | V_timeStamp  | Ut.1    | 
 
| A      | A_timeStamp  | Asd.1   |

  Where the value of the V_timeStamp and A_timeStamp are the values that you saved from the previous steps.
  Hope this help!

jordan rivera

unread,
Jan 23, 2017, 12:26:01 PM1/23/17
to Cukes
This is basically what we do at work.  When we parse through the data table we check for keywords like what you have listed; V_timeStampe and A_timeStamp.  If the data field contains the keyword, then do whatever it is you need done...like get current time and pass that data to where ever you're using it.
Reply all
Reply to author
Forward
0 new messages