[英]AssertionError on assertThat on a list
我正在從我的黃瓜特征文件發送 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]
我不確定為什么會收到此錯誤。 我可以看到“時間框架:06/22/2016 20:47:22 UTC 到 09/18/2016 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));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.