Login to an HTML form using the Rest Assured

218 views
Skip to first unread message

Gheorghe Sacultanu

unread,
Jul 26, 2020, 2:20:14 PM7/26/20
to REST assured
Hello guys,


I'm having difficulties to fil one login form using the rest assured. 

To be more precise, I need to log in to this website  -> https://www.themoviedb.org/login

This is my code:

 public String  login() {
        StringBuilder cookiesBuilder = new StringBuilder();
        RestAssured.given().log().all()

                        .auth().form("<username>", "<password>", new FormAuthConfig("/login", "username", "password").withLoggingEnabled())
                        .filter(new ResponseLoggingFilter())
                        .filter(new RequestLoggingFilter())
                        .baseUri("https://www.themoviedb.org")
                        .relaxedHTTPSValidation()
                        .when()
                        .post("/login")
                        .then()
                        .assertThat().log().all()

        .extract().cookies().forEach((s, s2) -> {
            cookiesBuilder.append(s)
                    .append("=")
                    .append(s2)
                    .append("; ");
        });
        return cookiesBuilder.toString().trim();

Also, I tried this one :

 I tried also with .formParam and also it's not working.

public String  login() {
        StringBuilder cookiesBuilder = new StringBuilder();
        RestAssured.given().log().all()
               .contentType(ContentType.URLENC)
               .queryParam("username", "<username>")
               .queryParam("password", "<password>")
               .header("Content-Type", "application/x-www-form-urlencoded")
                .post("https://www.themoviedb.org.login)

        .extract().cookies().forEach((s, s2) -> {
            cookiesBuilder.append(s)
                    .append("=")
                    .append(s2)
                    .append("; ");
        });
        return cookiesBuilder.toString().trim();

Tanks in advance for your help.

Raj Chahal

unread,
Oct 2, 2020, 12:51:59 AM10/2/20
to REST assured
Hi,
Any particular reason you are trying to use the login URL ?
I was easily able to interact with this API using Authenticate --> Create Session Process, and then using the session_id in all the further calls.

So any particular use case that requires you to login using the URL that you have mentioned ?

Thanks,
raj

Reply all
Reply to author
Forward
0 new messages