There are two types of data in BDD, table and text, the following is a description of the data, and finally two small examples of me.
1, Class behave.model.Table (headings, line=none, rows=none)
A table extracted from a feature file.
Table instance data is accessible using a number of methods:
Iteration
Iterating over the Table would yield the Row instances from the. Rows attribute.
Indexed access
Individual rows accessed directly by index on the Table instance; Table[0] gives the first non-heading row and Table[-1] gives the last row.
The attributes are:
Headings
The headings of the table as a list of strings.
Rows
An list of instances of Row, the body of the table in the feature file.
Tables is also comparable, for what's that ' s worth. Headings and row data is compared.
2. Class Behave.model.Row (headings, cells, line=none, comments=none)
One row of a table parsed from a feature file.
Row data is accessible using a number of methods:
Iteration
Iterating over the Row would yield the individual cells as strings.
Named access
Individual cells accessed by heading name; row[' name '] would give the cell value for the column with heading "name".
Indexed access
Individual cells accessed directly by index on the Row instance; Row[0] gives the first cell and Row[-1] gives the last cell.
The attributes are:
Cells
The list of strings that form the cells of this row.
Headings
The headings of the table as a list of strings.
Rows is also comparable, for what is that ' s worth. Only the cells is compared.
And Text May is associated with Steps:
3. Class Behave.model.Text
Store multiline text from a Step definition.
The attributes are:
Value
The actual text parsed from the feature file.
Content_Type
Currently only ' Text/plain '.
Example:
1. Table
Json_data = []
For row in context.table:
Adict = {}
If Hasattr (row, ' name '):
adict[' name '] = row[' name ']
Json_data.append (adict)
2. Text
Expected_datas = Json.loads (Context.text)
Types of data in BDD and how to handle it (python)