Java “我们如何才能建立”;“参数”;restapi自动化中的动态
在API自动化中,让我们考虑下面的代码来命中API并获得响应。Java “我们如何才能建立”;“参数”;restapi自动化中的动态,java,rest,api,automation,rest-assured,Java,Rest,Api,Automation,Rest Assured,在API自动化中,让我们考虑下面的代码来命中API并获得响应。 Response res= given(). formParam("email", "value"). formParam("password", "value"). formParam("action", "login"). header("token","value"). when
Response res= given().
formParam("email", "value").
formParam("password", "value").
formParam("action", "login").
header("token","value").
when().post("MyResource").then().assertThat().statusCode(200).extract().response();
实际上,在上面的代码中,我们只是用formParams、header和resource构建了一个api,请求正确
因此,我们已经手动创建了3formParm,并传递了值,对吗?现在,我想根据excel工作表中的任何参数自动添加这些参数
问题是这些参数将来可以被删除或添加新的参数,所以这就是为什么我想从excel工作表数据中动态添加这些参数
我怎么能做到?有什么建议吗?如果我没听错,您希望电子表格中的参数能够在运行时动态使用 为此,您需要:
地图
)中包含的参数,其中键为字段,值为。。。值:P
final RequestSpecification gived=gived();
对于(最终Map.Entry:Map.entrySet()){
给定.formParam(entry.getKey(),entry.getValue());
}
最终响应res=给定。其他内容()。。。
我希望这会有帮助,但请记住,使用地图是没有必要的。选择更适合您的情况的数据结构 如果我没弄错,您希望在电子表格上有参数,以便在运行时动态使用 为此,您需要:
地图
)中包含的参数,其中键为字段,值为。。。值:P
final RequestSpecification gived=gived();
对于(最终Map.Entry:Map.entrySet()){
给定.formParam(entry.getKey(),entry.getValue());
}
最终响应res=给定。其他内容()。。。