Rest assured API测试-重启-循环
我正在为学校做一项作业: 要求:Rest assured API测试-重启-循环,rest-assured,rest-assured-jsonpath,Rest Assured,Rest Assured Jsonpath,我正在为学校做一项作业: 要求: 为包含“Fantabulous”的项目创建搜索 验证id为“tt7713068”的电影是否在列表中 使用json路径生成电影ID列表并循环到 搜索具有正确ID的电影 这就是我所拥有的: //@Test public void search_for_movies_on_string_and_validate_one_of_the_results() { Response response = given(). param("ap
- 为包含“Fantabulous”的项目创建搜索
- 验证id为“tt7713068”的电影是否在列表中
- 使用json路径生成电影ID列表并循环到 搜索具有正确ID的电影
//@Test
public void search_for_movies_on_string_and_validate_one_of_the_results() {
Response response = given().
param("apikey", apiKey).
param("s", "Fantabulous").
when().get(baseURI).
then().extract().response();
JsonPath jsonPath = response.jsonPath();
List<String> idList = jsonPath.getList("Search.imdbID");
Assert.assertTrue(idList.contains("tt7713068"));
}
/@测试
公共无效搜索\u电影\u在\u字符串上\u和\u验证\u其中一个\u结果(){
响应=给定()。
参数(“apikey”,apikey)。
param(“s”,“Fantabulous”)。
when().get(baseURI)。
然后().extract().response();
JsonPath=response.JsonPath();
List idList=jsonPath.getList(“Search.imdbID”);
Assert.assertTrue(idList.contains(“tt7713068”);
}
如何循环列表以搜索具有正确ID的电影
apiKey=“7548cb76”
baseURI=”- 计算返回的列表的大小
- 从0开始循环,直到大小结束
- 搜索整个响应中的所有ID
如果符合您的要求“tt7713068”,则打印
输出
restasured.baseURI=”http://www.omdbapi.com"; Response Response=given().param(“apikey”,“7548cb76”).param(“s”,“Fantabulous”).when().get(baseURI).then().extract().Response(); JsonPath=response.JsonPath(); int count=jsonPath.getInt(“Search.size()”); 字符串id=“tt1634278”; 对于(int i=0;i
RestAssured.baseURI = "http://www.omdbapi.com"; Response response = given().param("apikey", "7548cb76").param("s", "Fantabulous").when().get(baseURI).then().extract().response(); JsonPath jsonPath = response.jsonPath(); int count = jsonPath.getInt("Search.size()"); String id = "tt1634278"; for(int i=0;i<count;i++) { String search = jsonPath.getString("Search["+i+"].imdbID"); if(search.equalsIgnoreCase(id)) { String output = jsonPath.getString("Search["+i+"].Title"); System.out.println("The ID "+id+" is present in the list and the name of the movie is "+output+""); } }