请放心,基本的获取查询会出错

时间:2019-09-27 06:14:32

标签: rest-assured

我正在尝试检查基本放心的get方法并获得以下错误。 使用以下版本:rest-assured-4.1.1-dist.zip

代码:

import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;

public class Basics {

    public static void main(String[] args) {

        System.out.println("Testing");
        RestAssured.basePath = "https://maps.googleapis.com";
        given().
        param("location", "-33.8670522,151.1957362").
        param("radius", "500").
        param("key", "AIzaSyDAyGVdrax3PwjtaJyQvlajVpgt46HBEWo").
        when().
        get("/maps/api/place/nearbysearch/json").
        then().assertThat().statusCode(200);

    }

}

输出:

测试

  

线程“ main”中的异常java.net.ConnectException:连接   拒绝:在java.net.DualStackPlainSocketImpl.connect0(Native   方法)   java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)     在   java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)     在   java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)     在   java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)     在java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)在   java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)在   java.net.Socket.connect(Socket.java:589)在   org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)     在   org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)     在   org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:326)     在   org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)     在   org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)     在   org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)     在   org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)     在   org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)     在org.apache.http.client.HttpClient $ execute $ 0.call(未知源)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135)     在   io.restassured.internal.RequestSpecificationImpl $ RestAssuredHttpBuilder.doRequest(RequestSpecificationImpl.groovy:2054)     在   io.restassured.internal.http.HTTPBuilder.doRequest(HTTPBuilder.java:494)     在   io.restassured.internal.http.HTTPBuilder.request(HTTPBuilder.java:451)     在io.restassured.internal.http.HTTPBuilder $ request $ 2.call(未知   来源)   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:151)     在   io.restassured.internal.RequestSpecificationImpl.sendHttpRequest(RequestSpecificationImpl.groovy:1450)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)     在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)处   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:821)在   io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)     在   io.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:1199)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)     在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)处   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:821)在   io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:151)     在   io.restassured.internal.filter.SendRequestFilter.filter(SendRequestFilter.groovy:30)     在io.restassured.filter.Filter $ filter $ 0.call(未知来源)   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)     在io.restassured.filter.Filter $ filter.call(未知来源)   io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)     在   io.restassured.filter.time.TimingFilter.filter(TimingFilter.java:56)     在io.restassured.filter.Filter $ filter.call(未知来源)   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:143)     在   io.restassured.internal.filter.FilterContextImpl.next(FilterContextImpl.groovy:72)     在io.restassured.filter.FilterContext $ next.call(未知来源)   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135)     在   io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1654)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)     在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)处   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:821)在   io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:184)     在   io.restassured.internal.RequestSpecificationImpl.applyPathParamsAndSendRequest(RequestSpecificationImpl.groovy:1660)     在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)在   org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101)     在groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)处   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1217)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041)在   groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:821)在   io.restassured.internal.RequestSpecificationImpl.invokeMethod(RequestSpecificationImpl.groovy)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.call(PogoInterceptableSite.java:45)     在   org.codehaus.groovy.runtime.callsite.PogoInterceptableSite.callCurrent(PogoInterceptableSite.java:55)     在   org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:156)     在   org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:184)     在   io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy:171)     在   io.restassured.internal.RequestSpecificationImpl.get(RequestSpecificationImpl.groovy)     在Basics.main(Basics.java:15)

1 个答案:

答案 0 :(得分:0)

您需要使用RestAssured.baseURI变量,而不是RestAssured.basePath。 这将起作用:

import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;

public class Basics {

    public static void main(String[] args) {

        //You need to set baseURI here, not basePath
        RestAssured.baseURI = "https://maps.googleapis.com";
        given().
        param("location", "-33.8670522,151.1957362").
        param("radius", "500").
        param("key", "value").
        when().
        get("/maps/api/place/nearbysearch/json").
        then().assertThat().statusCode(200);
    }
}