1

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);
lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20
Wilson
  • 73
  • 8

1 Answers1

1

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.

lucas-nguyen-17
  • 5,516
  • 2
  • 9
  • 20