gpt4 book ai didi

PyTest-BDD : Support for data tables without Scenario Outline

转载 作者:行者123 更新时间:2023-12-04 13:19:19 37 4
gpt4 key购买 nike

我有下图作为测试用例

user settings](https://drive.google.com/open?id=1N9w5qaqC8AYUo5Sa2lvmsvqHLCgiPE8a)[![enter image description here ] 1

在使用behave的时候,我们在写这样一个场景

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 |

我们现在正在迁移到 Pytest-BDD 而不是 Behave。但是我在 Pytest 中找不到对上述案例的支持。我浏览了 Pytest-BDD 文档,他们的支持是针对场景大纲的。

https://pytest-bdd.readthedocs.io/en/latest/

但我的案例不是场景大纲,因为我只需要运行一次这个场景,而不是迭代上面提到的字段值对

我也查看了 github,我能找到的最接近的是这个,但这似乎还没有被批准。

https://github.com/pytest-dev/pytest-bdd/pull/180

Pytest 是否支持以任何方式实现上述场景?是否有解决方法(如果不是直接的方法)来处理它?<​​/p>

最佳答案

希望这有助于...

那么响应应该有以下属性:

    |  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)

关于PyTest-BDD : Support for data tables without Scenario Outline,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55841009/

37 4 0
文章推荐: databricks - 创建 secret 范围时如何修复 Databricks 中的 'command not found' 错误
文章推荐: angularjs - AngularJS-从字符串中获取$ scope变量
文章推荐: symfony - Symfony2注销CSRF保护: csrf_provider unrecognized
文章推荐: php - html 大小以适应对象的内容