I have the following image as a test case
]1
When using behave, we were writing a scenario like this
Given When user is logged in to the platform
When user opens the settings window
Then user should see the following values
| Field | Value |
| Currency | Reported currency |
| Conversion Method | MI recommended |
| Magnitude | Millions (6) |
| Display Null Value As | SOA_Null |
| Function Options | Excluded from export |
| Dynamic Field Labels | Excluded from export |
We are now migrating to Pytest-BDD instead of Behave. But I couldn't find support for the above case in Pytest. I went through the Pytest-BDD documentation and the support they have is for Scenario Outline.
https://pytest-bdd.readthedocs.io/en/latest/
But my case is not a Scenario Outline since I have to run this scenario only once and not iterate over the Field-Value pairs mentioned above
I also looked into github and the closest I could find was this, but this doesn't seem to be approved yet.
https://github.com/pytest-dev/pytest-bdd/pull/180
Does Pytest support implementation of the above scenario in any way? Is there a workaround, if not a direct way, to handle it?
Hope this helps...
Then response should have below attributes:
| attr |
| id |
| activityId |
| activityName |
| activityType |
| processDefinitionId |
| processDefinitionUrl |
| processInstanceId |
| processInstanceUrl |
| executionId |
| taskId |
| calledProcessInstanceId |
| assignee |
| startTime |
| endTime |
| durationInMillis |
| tenantId |
Then verify response attribute values:
|attr | attr_value | path |
|activityId | endProcessSubmit | data[0].activityId |
|activityType | endEvent | data[0].activityType |
@then(parsers.parse ('response should have below attributes:\n{attr_table}'))
def verify_response_attributes(datatable,attr_table,query_historic_activity_instances):
query_data = query_historic_activity_instances.json()['data']
BaseTest.verify_tbl_attr(attr_table,query_data)
@then(parsers.parse('verify response attribute values:\n{attr_value_table}'))
def verify_response_attribute_values(datatable,attr_value_table,query_historic_activity_instances):
query_data = query_historic_activity_instances.json()
BaseTest.verify_tbl_attr_values(attr_value_table, query_data)
@staticmethod
def verify_tbl_attr_values(table_with_header,query_data):
# datatable = parse_str_table(attr_value_table)
list_attr=BaseTest.get_tbl_attr_values(table_with_header)
# for row in range(len(datatable.rows)):
# attr = list(datatable.rows[row].values())[0]
# attr_val = list(datatable.rows[row].values())[1]
# path = list(datatable.rows[row].values())[2]
for i in range(len(list_attr)):
attr = list_attr[i][0]
attr_val = list_attr[i][1]
path = list_attr[i][2]
for match in parse(path).find(query_data):
assert attr_val == match.value, "The expected %s and Actual %s for %s Dint match" % (
attr_val, match.value, attr)
@staticmethod
def get_tbl_attr_values(table_with_header):
datatable = parse_str_table(table_with_header)
list_attr_val = []
for row in range(len(datatable.rows)):
list_attr_val.append(list(datatable.rows[row].values()))
return list_attr_val
@staticmethod
def verify_tbl_attr(table_with_header,query_data):
list_attr = BaseTest.get_tbl_attr(table_with_header)
for i in range(len(query_data)):
for j in range(len(list_attr)):
assert list_attr[j] in query_data[i],"Response don't have %s" % list_attr[j]
@staticmethod
def get_tbl_attr(table_with_header):
datatable = parse_str_table(table_with_header)
list_attr = []
for row in datatable.rows:
for item in row:
list_attr.append(row[item])
return (list_attr)
@staticmethod
def verify_tbl_attr_by_column(table_with_header):
datatable = parse_str_table(table_with_header)
list_attr = []
for column in datatable.columns.values():
list_attr.append(column)
return (list_attr)
In addition to the answer given above, the following method will be helpful to convert the string into a data-table in step definition:
def parse_str_table(self, table_with_headers):
list_table_rows = table_with_headers.split("\n")
list_headers = str(list_table_rows[0]).strip("|").split("|")
dict_table = {}
for header in list_headers:
header_text = header.strip()
lst_row = []
for i in range(1, list_table_rows.__len__()):
list_temp = list_table_rows[i].strip("|").split("|")
lst_row.append(list_temp[list_headers.index(header)].strip())
dict_table[header_text] = lst_row
return dict_table
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With