我正在从我的黄瓜特征文件发送2行数据:
Scenario: Verify the data in the summary
Then the 'Summary' section contains the following data:
| Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC |
| Tabs: 47def , tr1 , e998 |
我正在尝试检查从页面中提取的实际文本中是否找到了功能文件每一行中的数据:
public void sectionContainsTheFollowingData(String section, List<String> expected) {
// text data pulled from the page is stored in 'actual'
List<String> actual = SUMMARY.getSummaryData(section);
for (String cell : expected) {
assertThat(String.format("Did not find %s in data %s", cell, actual), actual.contains(cell));
}
执行此命令时出现以下错误:
java.lang.AssertionError: Did not find Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC in data [Time Frame: 06/22/2016 20:47:22 UTC to 09/18/2016 17:00:53 UTC Tabs: 47def , tr1 , e998]
我不确定为什么会收到此错误。我可以看到“时间范围:UTC时间06/22/2016 20:47:22至2016年9月18日17:00:53 UTC”既是实际值,也是预期值。我猜我的主张正在寻找完全匹配,但我不希望完全匹配。我只需要功能文件中数据表的每一行中的文本在从页面中提取的实际文本中的某个位置即可。
使用流:
for (String cell : expected) {
assertThat(String.format("Did not find %s in data %s", cell, actual), actual.stream().anyMatch(string -> string.contains(cell));
}