标签: rest-assured

如何放心发布x-www-urlencode请求

我有一个发布请求,我需要发送 x-www-form-urlencoded keyValue 对参数,内容类型应该是 x-www-form-urlencoded。

\n\n

在编码之前,我已经在邮递员中成功尝试过,只需添加 Header"Content-Type=application/x-www-form-urlencoded" 和 x-www-form-urlencoded body 。

\n\n

这是我的代码:`

\n\n
 RestAssured.baseURI="****"\n        RequestSpecification request = RestAssured.given().config(RestAssured.config()\n                .encoderConfig(EncoderConfig.encoderConfig()\n                .encodeContentTypeAs("x-www-form-urlencoded",\n                 ContentType.URLENC)))\n                .contentType(ContentType.URLENC.withCharset("UTF-8"))\n                .formParam("grant_type", *)\n                .formParam("code", *)\n                .formParam("client_id",*)\n                .when().log().all()\n                .then().log().all().request()\n        request.post("/oauth2/token")`\n
Run Code Online (Sandbox Code Playgroud)\n\n

我想放心发布为 formParam 而不是“x-www-form-urlencoded”?\n这是放心日志:`

\n\n
Request method: POST\nRequest URI:    ***\nProxy:          <none>\nRequest params: <none>\nQuery params:   <none>\nForm params:    grant_type=***\n                code=***\n                client_id=***\nPath params:    <none>\nHeaders:        Accept=image/gif, image/jpeg, image/pjpeg, application/x-ms-application, application/xaml+xml, application/x-ms-xbap\n                Content-Type=application/x-www-form-urlencoded; charset=UTF-8\nCookies:        <none>\nMultiparts:     <none>\nBody:           <none>\nHTTP/1.1 405 Method Not Allowed\nContent-Length: 61\nDate: Tue, 30 Jan 2018 06:59:20 GMT\nX-Correlationid: 5d155b6f-0d85-4775-5f50-82c397e5b44b\nX-Smp-Log-Correlation-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b\nX-Vcap-Request-Id: 5d155b6f-0d85-4775-5f50-82c397e5b44b\nOnly support Content-Type\xef\xbc\x9aapplication/x-www-form-urlencoded\n …
Run Code Online (Sandbox Code Playgroud)

rest-assured postman

9
推荐指数
2
解决办法
2万
查看次数

如何使用嵌套值发送JsonObject作为REST保证的Post请求

我放心使用 - https://code.google.com/p/rest-assured/wiki/Usage 我的JsonObject看起来像这样

{
"id": "12",
"employeeInfo": null,
"employerInfo": null,
"checkDate": 1395093997218,
"netAmount": {
"amount": 70,
"currency": "USD"
},
"moneyDistributionLineItems": [
{
"mAmount": 100,
"employeeBankAccountId": "BankAccount 1"
}
],
}
Run Code Online (Sandbox Code Playgroud)

如何使用REST保证的POST将其作为参数的一部分发送?我试过了

given().param("key1", "value1").param("key2", "value2").when().post("/somewhere").then().
        body(containsString("OK")); 
Run Code Online (Sandbox Code Playgroud)

但对于具有嵌套值的HUGE对象,这是不可扩展的.有更好的方法吗?

http-post rest-assured jsonobject

8
推荐指数
1
解决办法
1万
查看次数

如何使用java搜索/查找JSON

我从下面有一个下面的JSON字符串我想在JSON字符串中查找/搜索条件.

1).查找存在的键数.2).获取给定键的值(如果我们有数组)

{
"store": {
    "book": [
        {
            "category": "reference",
            "author": "Nigel Rees",
            "title": "Sayings of the Century",
            "price": 8.95
        },
        {
            "category": "fiction",
            "author": "Evelyn Waugh",
            "title": "Sword of Honour",
            "price": 12.99
        },
        {
            "category": "fiction",
            "author": "Herman Melville",
            "title": "Moby Dick",
            "isbn": "0-553-21311-3",
            "price": 8.99
        },
        {
            "category": "fiction",
            "author": "J. R. R. Tolkien",
            "title": "The Lord of the Rings",
            "isbn": "0-395-19395-8",
            "price": 22.99
        }
    ],
    "bicycle": {
        "color": "red",
        "price": 19.95
    }
},
 "expensive": 10
}
Run Code Online (Sandbox Code Playgroud)

我正在寻找像Groovy …

java simplejson rest-assured rest-assured-jsonpath

8
推荐指数
1
解决办法
2万
查看次数

io.rest-assured和jayway有什么区别?

io.rest-assured和jayway有什么区别?我应该使用哪个框架进行restfull webservice测试?

java rest-assured

8
推荐指数
1
解决办法
4340
查看次数

Json与RestAssured的完整比赛

我正在使用REST-Assured测试一些API。我的API显然会使用JSON响应,并根据文档做出响应(如果这是响应):

{
    "id": "390",
    "data": {
        "leagueId": 35,
        "homeTeam": "Norway",
        "visitingTeam": "England",
    },
    "odds": [{
        "price": "1.30",
        "name": "1"
    },
    {
        "price": "5.25",
        "name": "X"
    }]
}
Run Code Online (Sandbox Code Playgroud)

我可以这样测试:

@Test
public void givenUrl_whenSuccessOnGetsResponseAndJsonHasRequiredKV_thenCorrect() {
   get("/events?id=390")
      .then()
         .statusCode(200)
         .assertThat()
            .body("data.leagueId", equalTo(35)); 
}
Run Code Online (Sandbox Code Playgroud)

当然这是可读的,但我将对JSON进行全面比较(即:这是JSON响应;这是固定的JSON-资源文件将是完美的-这些JSON等于吗?)。REST-Assured是否提供类似的功能,或者我需要手动进行设置。

rest json rest-assured

8
推荐指数
3
解决办法
6667
查看次数

如何验证数组包含对象并放心?

例如,我有JSON作为响应:

[{"id":1,"name":"text"},{"id":2,"name":"text"}]}
Run Code Online (Sandbox Code Playgroud)

我想验证响应是否包含自定义对象。例如:

Person(id=1, name=text)
Run Code Online (Sandbox Code Playgroud)

我找到了解决方案:

Person[] persons = response.as(Person[].class);
assertThat(person, IsArrayContaining.hasItemInArray(expectedPerson));
Run Code Online (Sandbox Code Playgroud)

我想要这样的东西:

response.then().assertThat().body(IsArrayContaining.hasItemInArray(object));
Run Code Online (Sandbox Code Playgroud)

有什么解决办法吗?
在此先感谢您的帮助!

java arrays hamcrest rest-assured

8
推荐指数
2
解决办法
3354
查看次数

模块版本冲突。模块 [groovy-xml 已在版本 4.xx 中加载,而您正在尝试加载版本 3.xx

我正在努力为 springboot Rest api 设置wiremock,并使用 spring cloud 中的放心和 spring-cloud-starter-contract-stub-runner 。当我运行示例集成测试时,我遇到模块冲突错误

rest-assured wiremock spring-cloud

8
推荐指数
1
解决办法
1万
查看次数

如何测试Rest API需要身份验证的Rest API

我想在获取Json响应之前测试需要身份验证的Rest API.对于exa.如果我想访问rest API: http://192.168.xx.xx:9000/dashboards/all/list/m1/p1/sch1

然后

如果我还没有登录,那么这会将我重定向到Login HTML页面,登录后,这将显示Json输出.

现在我想在java中编写一个放心的代码:我不知道,这是否可以使用此方法进行登录.

所以我写了一个简单的代码::

public class TestNGSimpleTest1 {

    @Test
    public void testAdd() {
            //expect().
            //statusCode(400).
            //body("Status", equalTo("Success")).
            //when().
            //get("http://localhost:9000/dashboards/all/list/m1/p1/sch1");
            //System.out.println("Response received is ::" +res);   
            Response res = get("http://localhost:9000/dashboards/all/list/m1/p1/sch1");
            assertEquals(200,res.getStatusCode());
            String json = res.asString();
            System.out.println("Response received is :: " +json);
    }
Run Code Online (Sandbox Code Playgroud)

所以这里得到的是HTML源页面响应,而不是获得Json响应.

所以,我的问题是如果可能的话,如何登录并获得Json响应.

提前致谢.

java rest testng json rest-assured

7
推荐指数
3
解决办法
4万
查看次数

如何禁用 REST-Assured 调试打印到控制台?

默认情况下,Rest-Assured 会向控制台打印过多的调试数据。

谁能告诉我如何禁用它?

java rest-assured

7
推荐指数
1
解决办法
1987
查看次数

无效的XML路径密钥仍在Rest Assured中评估

我的示例Web服务正在返回XML.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<errorResponse>
<errorCode>Wrong ID</errorCode>
<errorId>2</errorId>
</errorResponse>
Run Code Online (Sandbox Code Playgroud)

以下测试通过.

response.then().body("errorResponse.errorId", Matchers.is("2"));
response.then().body("errorResponse.errorCode", Matchers.is("Wrong ID"));

response.then().body("errorResponse1.errorCode", Matchers.is("Wrong ID"));
response.then().body("errorResponse2.errorCode", Matchers.is("Wrong ID"));
Run Code Online (Sandbox Code Playgroud)

我知道前两个测试都很好,我没有得到的是为什么最后两个测试通过了?

rest-assured

7
推荐指数
1
解决办法
208
查看次数