当我的测试代码包含请求或响应规范时,HTTP 请求流量不会流经 Fiddler
HTTP request traffic is not flowing through Fiddler when my test code contains Request or Response Specification
class 下方是一个超级 class,它具有 RequestSpecification 和 RequestSpecification,还包含对代理的调用(端口 8888 上的 Fiddler 列表)。
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);
}
}
下面class包含一个测试方法。
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);
}
}
在 运行 上,联合测试请求流量未流经 Fiddler。尝试从我的代码中删除请求和响应规范并尝试使用如下所示的简单行,流量流经 Fiddler,我也可以看到请求和响应。不太确定使用请求和响应规范时发生了什么。
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);
}
}
任何人都可以建议在使用 Request/Response 规范时我应该遵循哪些步骤让流量流经 Fiddler。
您需要在构建请求规范时配置代理。您的 VideoGameDB_MultipleRequestRespSpecificatoin
class 看起来像这样:
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;
}
}
class 下方是一个超级 class,它具有 RequestSpecification 和 RequestSpecification,还包含对代理的调用(端口 8888 上的 Fiddler 列表)。
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);
}
}
下面class包含一个测试方法。
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);
}
}
在 运行 上,联合测试请求流量未流经 Fiddler。尝试从我的代码中删除请求和响应规范并尝试使用如下所示的简单行,流量流经 Fiddler,我也可以看到请求和响应。不太确定使用请求和响应规范时发生了什么。
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);
}
}
任何人都可以建议在使用 Request/Response 规范时我应该遵循哪些步骤让流量流经 Fiddler。
您需要在构建请求规范时配置代理。您的 VideoGameDB_MultipleRequestRespSpecificatoin
class 看起来像这样:
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;
}
}