Below class is a super class that has RequestSpecification and RequestSpecification and also contains the call to proxy (Fiddler listing on port 8888).
import org.junit.BeforeClass;
import io.restassured.RestAssured;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
public class VideoGameDB_MultipleRequestRespSpecificatoin {
public static RequestSpecification videoGameDB_requestSpecification;
public static ResponseSpecification videoGameDB_responseSpecification;
@BeforeClass
public static void setup() {
videoGameDB_requestSpecification = new RequestSpecBuilder().
setBaseUri("http://localhost"). setPort(8080). setBasePath("/app").
addHeader("Control-Type", "application/json"). addHeader("Accept",
"application/json"). build();
RestAssured.requestSpecification = videoGameDB_requestSpecification;
videoGameDB_responseSpecification = new ResponseSpecBuilder().
expectStatusCode(200).
build();
RestAssured.responseSpecification = videoGameDB_responseSpecification;
RestAssured.proxy("localhost", 8888);
}
}
Below class containing a test method.
import org.junit.Test;
import static io.restassured.RestAssured.given;
import com.videoGameDB.config.VideoGameDB_MultipleRequestRespSpecificatoin;
public class TestVideoGameDB_MultipleRequestRespSpecificatoin extends VideoGameDB_MultipleRequestRespSpecificatoin {
@Test
public void testCase() {
given().
spec(videoGameDB_requestSpecification).
when().
get("videogames/2").
then().
spec(videoGameDB_responseSpecification);
}
}
Upon on running the juint test request traffic is not flowing through Fiddler. Tried removing Request and Response Specification from my code and tried out with simple lines like below and the traffic flows through Fiddler and I can see the request and response as well. Not really sure what is happening when Request and Response Specfication were used.
import org.junit.BeforeClass;
import io.restassured.RestAssured;
public class VG_TestConfig {
@BeforeClass
public static void vg_Setup() {
RestAssured.baseURI = "http://localhost";
RestAssured.port = 8080;
RestAssured.basePath = "/app";
RestAssured.proxy("localhost", 8888);
}
}
import org.junit.Test;
import com.videoGameDB.config.VG_TestConfig;
import static io.restassured.RestAssured.given;
public class VG_FirstTestCase extends VG_TestConfig{
@Test
public void vgTestCase() {
given().
when().
get("videogames/2").
then().
statusCode(200);
}
}
Can anyone please suggest what steps should I follow to have the traffic flows through Fiddler when Request/Response specification was used.
You need to configure proxy while building request specification. Your VideoGameDB_MultipleRequestRespSpecificatoin
class will look this way:
public class VideoGameDB_MultipleRequestRespSpecificatoin {
public static RequestSpecification videoGameDB_requestSpecification;
public static ResponseSpecification videoGameDB_responseSpecification;
@BeforeClass
public static void setup() {
videoGameDB_requestSpecification = new RequestSpecBuilder()
.setProxy("localhost", 8888) //Configure your proxy here
.setBaseUri("http://localhost")
.setPort(8080)
.setBasePath("/app")
.addHeader("Control-Type", "application/json")
.addHeader("Accept", "application/json")
.build();
RestAssured.requestSpecification = videoGameDB_requestSpecification;
videoGameDB_responseSpecification = new ResponseSpecBuilder().
expectStatusCode(200).
build();
RestAssured.responseSpecification = videoGameDB_responseSpecification;
}
}