放心代理设置问题(java.net.ConnectException:连接超时异常)
仅一个API(比如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
}
共 (0) 个答案