The execute
command has special behaviour when placed on
a <table>
element. Instead of executing once, it
executes every detail row in the table and transfers the commands
from the header row to each detail row.
Note that if you add the attribute "concordion:example" to one of the header columns, then each row will be executed as an example. The example name for the row is set to the value of that column.
<table concordion:execute="#username = generateUsername(#fullName)"> <tr> <th concordion:set="#fullName">Full Name</th> <th concordion:assertEquals="#username">Username</th> </tr> <tr> <td>Fred Bloggs</td> <td>fredbloggs</td> </tr> <tr> <td>John Doe</td> <td>johndoe</td> </tr> <tr> <td>Winston Churchill</td> <td>winston</td> </tr> </table>
If the method generateUsername()
returns the
full name in lowercase with spaces removed, when we run
the test we expect:
2 successes and
1 failure and
0 exceptions
to be reported.
The failure will have an expected value of
"winston
"
and an actual value of
"winstonchurchill
".
On occasions where the whole table row is required, for example logging the row,
the special variable #ROW
contains a Map<String, String>
with the key being the column header value and the value being the column cell value
for each column in the table row.
<table concordion:execute="#username = processRow(#ROW)"> <tr> <th>First Name</th> <th>Last Name</th> <th concordion:assertEquals="#username">Username</th> </tr> <tr> <td>Jacinda</td> <td>Ardern</td> <td>jacindaardern</td> </tr> <tr> <td>Judith</td> <td>Collins</td> <td>judithcollins</td> </tr> </table>
The processRow(#ROW)
method is called once for each row, being passed a Map
with the entries:
First Name | Last Name | Username |
---|---|---|
Jacinda | Ardern | jacindaardern |
Judith | Collins | judithcollins |
If there are multiple columns with the same header text, the map will contain one entry for the last column with that header (that is, the last entry with that header will overwrite all previous entries).
<table concordion:execute="#username = processRow(#ROW)"> <tr> <th>First Name</th> <th>First Name</th> </tr> <tr> <td>Noel</td> <td>Nicky</td> </tr> </table>
The #ROW
map contains a single entry with data from the last First Name
column:
First Name |
---|
Nicky |
The key for a column with an empty header is an empty string ""
.
<table concordion:execute="#username = processRow(#ROW)"> <tr> <th></th> </tr> <tr> <td>Tūī</td> </tr> </table>
The #ROW
map contains a single entry with the empty string ""
as its key:
Tūī |
HTML entities in column headers are decoded into their corresponding characters.
<table concordion:execute="#username = processRow(#ROW)"> <tr> <th>> β</th> </tr> <tr> <td>X & Y</td> </tr> </table>
The #ROW
map contains the single entry:
> β |
---|
X & Y |