【问题标题】:How to write BDD test case to validate the column names in UI displayed?如何编写 BDD 测试用例来验证 UI 中显示的列名?
【发布时间】:2021-03-06 22:21:28
【问题描述】:

我有一个以表格格式显示数据的 UI。该表有 9 列。我需要编写 BDD 场景来验证所有这些列的名称。我不确定以下哪种方法是正确的。(仅包括导航到所需 UI 后的最后一个“Then”语句)

方法一:

Then UI should include bill details in tabular format with "Bill ID" "Payment Type" "Facility Name" "BillAccount/Master Account" "Supplier Name" "Statement Date" "Due Date" "Total Amount Due" and "Bill Image" columns

步骤定义:

[Then(@"UI should include bill details in tabular format with ""(.*)"" ""(.*)"" ""(.*)"" ""(.*)"" ""(.*)"" ""(.*)"" ""(.*)"" ""(.*)"" and ""(.*)"" columns")]
public void ThenUIShouldIncludeBillDetailsInTabularFormatWithAndColumns(string p0, string p1, string p2, string p3, string p4, string p5, string p6, string p7, string p8)

这里我可以使用字符串 p0 值直接获取期望的列名,并与实际值进行比较。我可以对所有 9 个列名做同样的事情

方法二:

Then UI should include bill details with below columns
    | col1         | col2         |  | col3          | col4                       |  | col5          | col6           |  | col7     | col8             | col9       |
    | Bill ID      | Payment Type |  | Facility Name | BillAccount/Master Account |  | Supplier Name | Statement Date |  | Due Date | Total Amount Due | Bill Image |

在这种方法中,我需要知道读取作为参数值提到的列名的最佳方法。一种选择是创建一个包含 9 个字符串字段的自定义类,并在 table.createInstance() 方法中使用相应的类。

请给我建议最好的方法。

【问题讨论】:

    标签: cucumber bdd specflow gherkin


    【解决方案1】:

    “最佳”方式是主观的,但有利于 BDD 测试的可读性。

    您的第二种方法是最好的,因为该场景最容易阅读。此外,table.CompareToSet(...) 扩展方法便于比较。

    无论是使用 Selenium 还是其他一些 UI 自动化框架,您都需要从屏幕上抓取表格值并将它们分配给一个集合:

    IEnumerable<BillDetailRow> billDetails = somePageModel.GetBillDetails();
    
    table.CompareToSet(billDetails);
    

    如果项目的顺序很重要,请使用table.CompareToSet(billDetails, true); 重载。

    【讨论】:

      猜你喜欢
      • 2021-08-24
      • 1970-01-01
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多