单独一个API(Say XYZ API)调用需要设置代理,当我运行套件时,在套件中的每个测试脚本之前和之后调用此API时, java.net.ConnectException
随机看见。
仅对于XYZ API,我使用以下行设置和重置代理:
RestAssured.proxy(String, int)
和
RestAssured.reset()
请帮我解决这个问题。这可能是个错误吗?
注意:此API调用会失败,只是说它本来会传递的前10次可能是第11次失败,异常休息所有脚本都会被跳过执行。
代码快照:
public void GetAuthenticationToken(String userid, String password)
{
RestAssured.proxy(config.getProperty("ProxyHost"),Integer.parseInt(config.getProperty("ProxyPort"))); //Authentication API is outside network and requires proxy
String APIUrl_Aut = config.getProperty("APIUrl_Aut");
String APIBody_Aut = "grant_type=password&username="+userid+"&password="+password;
//Making post request with authentication
Response response = RestAssured.given().log().all().headers("Accept", "application/json","Content-Type","application/x-www-form-urlencoded").body(APIBody_Aut).
when().post(APIUrl_Aut).then().contentType(ContentType.JSON).extract().response();
if (response.getStatusCode() == 200)
{
WritePropertyToTemp("AUTH_TOKEN", "Bearer "+response.body().jsonPath().get("access_token").toString());
WritePropertyToTemp("AUTH_TOKEN_OnlyToken",response.body().jsonPath().get("access_token").toString());
log.info("Authentication token generated successfully");
}
else
log.info("Authentication token failed to generate");
RestAssured.reset(); //Resetting proxy
}