Reputation: 293
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?
Upvotes: 5
Views: 8352
Reputation: 1
Also you try this:
Create your JSON file with xyzjson name and keep your post payload data in that file and use below code.
Response rep = given()
.headers
.(headers)
.accept(contentType.json)
.body (xyzjson)
.when()
.post(someURL);
Assert.assertTrue(rep.StatusCode() == HttpStatus.SC_Ok);
Upvotes: 0
Reputation: 256
Does your login api call result in some sort of authentication token that is reused in subsequent requests? If so, I see these as separate rest assured calls to test it fully.
(Login Focus)
(Logout Focus)
Upvotes: 0
Reputation: 1851
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/");
}
Upvotes: 4
Reputation: 741
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
Upvotes: 1