formParam() in Rest Assured

Sameera De Silva
1 min readJul 5, 2023

--

What is it?

formParam() method is used to specify form parameters in an HTTP request as key-value pairs.

The formParam() method is a synchronous method, which means that it will block until the request has been sent and the response has been received.

When to use it?
The formParam() method can only be used with HTTP methods that support form data, such as POST, PUT, and PATCH.

To send multiple form parameters at once.
To send complex data structures, such as JSON objects.

When not to use it ?
The formParam() method does not support sending files. To send files, you should use the multiPart() method.

Do not us in GET requests

To send complex data structures, such as JSON objects.

given()
.baseUri("https://facebook.com")
.basePath("/api")
.formParam("username", "john")
.formParam("password", "!@#")
.when()
.post("/login")
.then()
.statusCode(200)

Another example

public class FormParmExample {

//In post request you have formparameters
@Test
public void testFormParametersWithPostRequest() {
int UserID = 333;
given().formParam("id", UserID).formParam("title", "Evil Son").formParam("author", "Teena").when()
.post("http://localhost:3000/posts/").then().statusCode(201);

}
}

--

--

No responses yet