Home > Back-end >  In Java Rest Assured framework is there any way to use x-www-form-urlencoded form params using POJO
In Java Rest Assured framework is there any way to use x-www-form-urlencoded form params using POJO

Time:04-05

In Rest Assured framework we use POJO classes concept when there is a JSON payload. But right now I am having x-www-form-urlencoded form params. Is there any way we can use POJO classes for x-www-form-urlencoded form params? Please let me know the better way to handle x-www-form-urlencoded form params?

Currently I am handling in the below way.

.header("Content-Type", "application/x-www-form-urlencoded");
.formParam("i_username",username);
.formParam("i_password",password);

CodePudding user response:

You can use Map<String, ?> to provide values for formParams.

RequestSpecification formParams(Map<String, ?> parametersMap);

For example:

Map<String, Object> body = new HashMap<>();
body.put("i_username",username);
body.put("i_password",password);

given().header("Content-Type", "application/x-www-form-urlencoded")
       .formParams(body);

And if you still want to use POJO, you can write a small method to convert POJO to Map, then do it as the same above instruction.

  • Related