RestAssured-TestNG-天气API测试-连接超时错误

时间:2019-09-26 16:08:33

标签: rest-assured

我正在使用RestAssured 4.1.1版本测试Weather Rest服务。 当我发送城市名称作为参数时,我得到了正确的连接超时。

我正在使用RestAssured 4.1.1版本测试Weather Rest服务。 当我发送城市名称作为参数时,我得到了正确的连接超时。

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

public class RestApi_Weather_GET {

@BeforeMethod
 public void beforeMethod() {
    System.out.println("before method");

}

@Test
void GetWeatherDetails(){       
    System.out.println("in Test method before calling baseURI");
    //specify the base uri      
    RestAssured.baseURI = "http://restapi.demoqa.com/utilities/weather/city/";
    System.out.println("in Test method after calling baseURI");

    System.out.println("in Test method before calling given");
    //Request object is being created
    RequestSpecification ahttprequest = RestAssured.given();    
    System.out.println("in Test method after calling given");

    System.out.println("passing parameter alameda");
    //Response object 
    Response aresponse = ahttprequest.request(Method.GET, "Alameda");

    System.out.println("after passing parameter alameda");
    //print response in console     
    String aresponseBody = aresponse.getBody().asString();      
    System.out.println("Response body is : "+aresponseBody);
}

}

这是错误:

before method
in Test method before calling baseURI
in Test method after calling baseURI
 in Test method before calling given
 in Test method after calling given 
  passing parameter alameda
 log4j:WARN No appenders could be found for logger 
 (org.apache.http.impl.conn.BasicClientConnectionManager).
 log4j:WARN Please initialize the log4j system properly.
     log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
 FAILED: GetWeatherDetails
    java.net.ConnectException: Connection timed out: connect
    at java.net.DualStackPlainSocketImpl.connect0(Native Method)
     at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
      at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
    at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
   at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)

0 个答案:

没有答案