我在Cucumber中进行了一项测试,该测试用于测试搜索功能的措辞。场景如下:
Scenario Outline: Search from the main page
Given user is on Home Page
When user enters <search_string> as search_string in the search field and clicks enter
Then <search_results> search results are loaded
Examples:
|search_string |search_results |
|blouse |1 result has been found. |
|dress |2 results have been found.|
步骤定义:
@Then("^(.*) search results are loaded$")
public void search_results_are_loaded(String search_result) {
SearchPage searchPage = new SearchPage( driver );
String pageTitle = searchPage.getPageTitle();
Assert.assertTrue( pageTitle.contains( search_result ) );
}
现在可以使用,但仅适用于1件上衣和2件礼服。如果站点将更改,并且会有更多衣服,我的代码将失败。我可以使用正则表达式或其他技巧来使搜索“ dress”的结果匹配不同数量的结果吗?
"(\d+) (result|results) have been found."