I'm trying to use REST assured to test my login/logout feature. Is it possible to have a REST assured test that posts to login then posts to logout? If not, how can I test it properly?
Just send two post() with one assert()/expect() :
import org.junit.Assert;
import org.junit.Test;
import static org.hamcrest.Matchers.*;
import static com.jayway.restassured.RestAssured.*;
@Test
public void loginAndLogout(){
final String login = randomLogin();
// First post to login()
given()
.queryParam("login", login)
.queryParam("password", randomPassword())
.when().post("/login/");
// Second post to logout() with an assert
expect().statusCode(200)
.given()
.when().post("/logout/");
}
You can try
expect().statusCode(HttpStatus.SC_OK)
.given()
.parameters("user", user, "password", URL)
.cookie("cookie_name", "cookie_value")
.post("/someURL");
Also there is a rest-assured auth call.
See the documentation or the examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With