1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
Feature: Exploratory Testing with Tables and Table Annotations
As a tester
I want sometimes to explore a problem domain
And see not only the expected results
But also the actual results in a table.
. HINT: Does not work with monochrome format in pretty formatter:
. behave -f pretty --no-color ...
. behave -c ...
@setup
Scenario: Feature Setup
Given a new working directory
And a file named "features/steps/explore_with_table_steps.py" with:
"""
from behave import given, when, then, step
database = {
"Alice": { "age": 10 },
"Bob": { "age": 11 },
}
@when('I query the database with')
def step_query_database_and_update_table(context):
assert context.table, "REQUIRE: table"
context.table.require_column("Name")
age_index = context.table.ensure_column_exists("Age")
for index, row in enumerate(context.table.rows):
name = row["Name"]
person = database.get(name, None)
if person:
row.cells[age_index] = str(person["age"])
context.current_table = context.table
@when('I add {number:n} to column "{column}"')
def step_query_and_annotate_database(context, number, column):
assert context.current_table, "REQUIRE: current_table"
age_index = context.current_table.ensure_column_exists("Age")
for row in context.current_table.rows:
value = int(row.cells[age_index]) or 0
row.cells[age_index] = str(value + number)
@step('note that the "{name}" column was added to the table')
def step_note_that_column_was_added(context, name):
assert context.current_table.has_column(name)
@then('note that the "{name}" column was modified in the table')
def step_note_that_column_was_modified(context, name):
pass
@then('I inspect the table')
def step_inspect_table(context):
assert context.current_table
context.table = context.current_table
@then('the table contains')
def step_inspect_table(context):
assert context.table, "REQUIRE: table"
assert context.current_table, "REQUIRE: current_table"
assert context.table == context.current_table
"""
Scenario: Add table column with new data in a step and ensure changes are shown
Given a file named "features/table.set_column_data.feature" with:
"""
Feature:
Scenario:
When I query the database with:
| Name |
| Alice |
| Bob |
Then note that the "Age" column was added to the table
"""
When I run "behave -f plain features/table.set_column_data.feature"
Then it should pass with:
"""
1 scenario passed, 0 failed, 0 skipped
2 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
| Name | Age |
| Alice | 10 |
| Bob | 11 |
"""
But note that "the Age table column was added by the step"
Scenario: Modify table cells in a column and ensure changes are shown
Given a file named "features/table.modify_column.feature" with:
"""
Feature:
Scenario:
When I query the database with:
| Name | Age |
| Alice | 222 |
| Bob | 333 |
Then note that the "Age" column was modified in the table
Then the table contains:
| Name | Age |
| Alice | 10 |
| Bob | 11 |
"""
When I run "behave -f plain features/table.modify_column.feature"
Then it should pass with:
"""
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
| Name | Age |
| Alice | 10 |
| Bob | 11 |
"""
But note that "the Age column was modified in the table"
And the command output should not contain:
"""
| Name | Age |
| Alice | 222 |
| Bob | 333 |
"""
Scenario: Modify table cells in a column (formatter=pretty with colors)
When I run "behave -f pretty features/table.modify_column.feature"
Then it should pass with:
"""
1 scenario passed, 0 failed, 0 skipped
3 steps passed, 0 failed, 0 skipped, 0 undefined
"""
And the command output should contain:
"""
| Name | Age |
| Alice | 10 |
| Bob | 11 |
"""
But note that "the Age column was modified in the table"
|