rest-assured

Hamcrest check if value is null or empty array

半世苍凉 提交于 2021-02-11 15:41:43
问题 I have a code, which returns JSON, where one field might be null or empty array. I have this code to check: import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.blankOrNullString; // io.restassured.response getResponse.then() .assertThat() .body("entity.fields", anyOf(nullValue(), emptyArray())) But output is unclear java.lang.AssertionError: 1 expectation failed. JSON path entity.fields doesn't match. Expected:

Hamcrest check if value is null or empty array

こ雲淡風輕ζ 提交于 2021-02-11 15:36:38
问题 I have a code, which returns JSON, where one field might be null or empty array. I have this code to check: import static org.hamcrest.core.AnyOf.anyOf; import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.Matchers.blankOrNullString; // io.restassured.response getResponse.then() .assertThat() .body("entity.fields", anyOf(nullValue(), emptyArray())) But output is unclear java.lang.AssertionError: 1 expectation failed. JSON path entity.fields doesn't match. Expected:

Rest Api load tesing Zerocode tdd giving error message

前提是你 提交于 2021-02-10 16:44:10
问题 I'm automating my rest api and searching for a performance testing framework to use with my junit5. I came across zerocode tdd but it is not helping it's giving error and all the tests are falling under failure. My test method is proper and works when it invoked normally by junit jupiter. When I use zerocodeLoadRunner for the same thing it is not working. import org.jsmart.zerocode.core.domain.LoadWith; import org.jsmart.zerocode.core.domain.TestMapping; import org.jsmart.zerocode.core.runner

Uploading file to S3 using Rest Assured multipart

会有一股神秘感。 提交于 2021-02-08 10:18:29
问题 I am trying to do a PUT request to S3 in order to upload a file. Below the Rest Assured code that I have so far, String putURL = "A lengthy URL that is generated dynmaically"; String fileId = "A random 40 digit key generated by our server"; String cKey = "some key given by amazon"; String cMD5 = "some md5 hash value"; Response r = given().contentType("multipart/mixed"). headers("x-amz-header1",cKey, "x-amz-header2",cMD5, "x-amz-header7",accountId, "x-amz-header6",fileId, "x-amz-header5","abc"

How to ensure that a cookie is NOT present

自作多情 提交于 2021-02-08 04:36:16
问题 What would be a good way in REST Assured to ensure that a cookie is absent ? I checked that there are many .cookie and .cookies methods, but none support checking the absence of a cookie. 回答1: I'm not finding anything OOTB, but this works: assertThat(response.getCookie("foo"), is(nullValue())); 回答2: Would fetching all cookies, iterating over it and asserting over that the expected cookie is not present solve your problem? Am i missing something here? 回答3: You need to extract the response to

Hamcrest matcher with slashes is interpreted as a part of validation

陌路散爱 提交于 2021-02-07 13:01:25
问题 I have the following validation where I have to check if returned body has a string containing "id": 6354 , but it interprets slashes of special characters. How I can validate strings which contain double quotation marks ? Code import static org.hamcrest.Matchers.containsString; import com.jayway.restassured.response.Response; response.then() .body(containsString("\"id\": 6354")); Error Response body doesn't match expectation. Expected: a string containing "\"id\": 6354" Actual: {...,"id":

How to send form-data in api using Rest-assured

感情迁移 提交于 2021-02-07 12:31:46
问题 I want to send below as a form-data in API Body for a PUT request: Upload a file(KEY) with "Error.png"(VALUE) Send text, "MyName"(KEY) with false(VALUE) How to do this using REST-Assured Attached is the screenshot Form-Data Image 回答1: You need to set desired content type i.e "multipart/form-data" and add the multipart request specs to the request. Eg. given() .contentType("multipart/form-data") .multiPart("file", "filename") .multiPart("key", "value") .when() .put(endpoint); 回答2: Be sure to

Make multiple API calls and return combined response in minimum time

ε祈祈猫儿з 提交于 2021-01-29 17:07:23
问题 I have 10 health check URLs which are simply get service I am hitting them in a loop like below for(int i=0;i<10;i++){ Response response = given().when().relaxedHttpsValidation().get(url[i]); list.add(response); } return list; Now the problem is it hits API in series and waiting for a response for all, I just want to hit all API in parallel but combine the result, I tried using threads but unable to get an idea on how to combine the response in case of multi-threading 回答1: If I am reading

Is there any way to display all the APIs called for a scenario in Cucumber Report?

天涯浪子 提交于 2021-01-29 10:15:49
问题 I am developing a Test Automation using Rest-Assured Cucumber and generating the report using net.masterthought report plugin. Everything works fine, but now I want to display all the GET/POST/PUT/DELETE resource called during the test in any place/page of the report. Can anyone give any idea how can I accomplish this? Thanks, Surodip 来源: https://stackoverflow.com/questions/61344107/is-there-any-way-to-display-all-the-apis-called-for-a-scenario-in-cucumber-repor

The import io.restassured.RestAssured cannot be resolved

筅森魡賤 提交于 2021-01-27 14:42:11
问题 Hi I am not able to resolve the error while using rest assured 4.1.1. library in my Eclipse IDE. I have added the rest assured library in my pom.xml file still the error is not resolved. I tried re-importing the rest assured library from https://mvnrepository.com/artifact/io.rest-assured/rest-assured/4.1.1 But still doesn't work <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http:/