Questions tagged [rest-assured]

1

votes
0

answer
282

Views

How to set session attributes using RestAssured for Integration Tests

I have a AbstractClass and this class has following code: protected long getStudentIdFromSession() { Object obj = this.httpSession.getAttribute('studentId'); Long formId = (obj instanceof Long ? (Long) obj : null); LOGGER.info('getStudentIdFromSession studentId {}', studentId); return formId; } I am...
dvanga
1

votes
3

answer
186

Views

Parsing XML converted Json using Java

Below is the JSON, in which I need to parse the value of: 'primaryInvolvedParty': { } The response is XML, hence it is converted into JSON, so that I can parse it easily. Converting XML to JSON using: String messageBody = actualResult.get('StatusMessage'); JSONObject xmlconvertedjson=XML.toJSONObje...
Nithin
1

votes
1

answer
1.5k

Views

How to pass content type “application/x-www-form-urlencoded” with rest assured

I am trying to hit API using Rest assured which is a POST request with form param client id, user and password. and multiple header . I am getting 415, unsupportted media type error. My code is: Response res = given(). .header('Accept', 'application/json') .header('Content-Type', 'application/x-...
itin
1

votes
0

answer
25

Views

JSONPath : preserving contents at filtered values

Below is the JSON content on which I was trying to extract the contents of matched filters { 'results': [{ 'individualProviderId': 'P1', 'locations': [{ 'addressInfo': { 'city': 'Pembroke Pines', 'county': 'Broward', 'state': 'FL', 'zip': '33026' }, 'plans': [{ 'networkId': 'N1', 'tiering': [{...
Syed Mazreena
1

votes
0

answer
46

Views

rest assured File not Found error

When i use authorization in headers for rest assured by bassing token variable giving 'File Not Found' error. And if hardcode the token in headers then it's working successfully. Can anyone help me out what can be the issue. Below is my code, public static void getIndentId() throws IOException { if(...
Pavan
1

votes
1

answer
291

Views

Optimization of rest-assured and gson at rest test with java with cucumber

I got a rest api which returns me this nested response: 'latitude':37.8267, 'longitude':-122.4233, 'timezone':'America/Los_Angeles', 'minutely':{ 'summary':'Clear for the hour.', 'icon':'clear-day', 'data':[ { 'time':1517431560, 'precipIntensity':0, 'precipProbability':0 }, { 'time':1517431620, 'pre...
Aleksey Kiselev
1

votes
1

answer
554

Views

How to find key from value in rest assured java?

I am using rest assured java and i am using post request in order to get the response. From my code i am able to get the response and i am seeing that in response i am seeing that value which i want to store is present in the keyset. Here is the example: { 'status_code': 200, 'status_message': 'OK',...
Ashwajeet Gajre
1

votes
1

answer
581

Views

REST Assured: how to test object of type “Set” in body?

I would like to get assert the response body using REST Assured. But currently I am not able to do so. I am getting the below-mentioned error message. Implementation detail is as follows : BannerDto resultBannerDto = given() .contentType('application/json') .body(bannerAddDto) .when() .post('/api/v1...
nima pirmoradian
1

votes
0

answer
745

Views

How do I test the contents of a download in RestAssured?

I have a endpoint I want to test out. I'll call GET with it and it's supposed to download a zip file containing a csv file. I want to verify that the contents of that csv file is correct. When I hit the endpoint in Postman, the headers look something like this: content-disposition: 'attachment; file...
Vicky
1

votes
1

answer
132

Views

Getting JSESSIONID from JIRA using RestAssured throwing unknown host error

I have written a script using RestAssured to connect to Jira and get Session ID. Below is my code. public void getJIRACookieTest(){ System.setProperty('https.proxyHost', 'Host'); System.setProperty('https.proxyPort', 'PortNo'); System.setProperty('https.proxyUserName','UserName'); System.se...
Naren
1

votes
0

answer
876

Views

RestAssured vs Mockmvc for unit and integration testing

I am asked to choose one and the best from these two for unit and integration tests- 1. RestAssured 2. Mockmvc The application is in Spring and Spring Boot. I have read many blogs and no clear distinction is given or I couldn't find one. For rest assured, its neat and clean code and BDD style that m...
apun
1

votes
0

answer
282

Views

How can I delay my API Request in Rest Assured?

Making a POST call (RESTful) - which updates some record in Data Base and during this call it will lock that particular record in the DB. So, I need to delay my request and during this delay I have to verify the data base table.
sangeetha
1

votes
1

answer
44

Views

Issue in passing string in Request Body

I am facing an issue while making a request body to do an API call in Java. Required Body { 'id' : [1,2] } I have an integer array with me lets say arr, I am creating the request something like:- JSONObject jsonObject = new JSONObject(); jsonObject.put('id',Arrays.toString(arr)); String stringBody =...
nikky
1

votes
1

answer
126

Views

Katalon Studio mock services?

Can I mock/virtualize web services using Katalon Studio like WireMock or CA DevTest or Soap UI? If so, how can I do it , I didn’t find it on their site.
Pallavi Datar
1

votes
0

answer
243

Views

Is it possible to use REST Docs, REST Assured and kotlin ktor together?

Info about technologies available here: Spring REST Docs link Rest Assured link Ktor backend link Main question is: Can I generate documentation with json payloads for ktor backend like I did it for Spring backend using Spring Rest Docs Spring Rest Docs uses unit tests technique to generate json p...
nail
1

votes
0

answer
160

Views

<title>Error 403 No valid crumb was included in the request</title> getting same in Eclipse using restassured

I am getting this error while calling a rest api which is working from postman IDE : Eclipse and using rest assured Error 403 No valid crumb was included in the request HTTP ERROR 403 Problem accessing /serviceurl.postregisterurl. Reason: No valid crumb was included in the requestPowered by Jetty://...
Akanksha Jain
1

votes
2

answer
1.2k

Views

Multiple Scenario outline and Example in two different features file. How can I reuse the Java steps from one feature file to another?

Multiple Scenario outline and Example in two different features file. How can I reuse the Java steps from one feature file to another? Feature -- > ANPost.feature ** Scenario outline : Verify csv file accept When User perform the post request with localhost Then Response contains 201 and response...
sri
1

votes
0

answer
53

Views

Cucumber step repeat NullPointerException

I am trying to run the feature a and feature b which has same steps like below feature a: Scenario Outline: Verify correct entity values When Performing the get request to localhost:''/'' Then The response status should be 200 and json body containing 'Apps is running' feature b: Scenario Outlin...
sri
1

votes
1

answer
232

Views

(RestAssured) Extract nested path as given type

Let's say I have following model: @Data class Model { private String someField; private String otherField; } And following JSON response in RestAssured: { wrapperField: { someField: 'some value', otherField: 'other value' } } Is it possible to use extract().as() construction in the nested path? Some...
Maciej Treder
1

votes
0

answer
35

Views

RestAssured. StackOverflowError when assign a String to baseUri

I'm getting a StackOverflow error when i assign a String to BaseURi. baseURI = Apis.REQUEST_TOKEN; The 'Apis.REQUEST_TOKEN' is a String that comes fron another class. Can someone help me?
FranDoti
1

votes
0

answer
610

Views

How to Modify values in existing Json File?

I have json file Called 'addplace.json' whose contents are pasted below. Now I need to read above said json file and change the values for Latitude, longitutde ,name,phone,Address. So how would i do that , please advise me with sample java code. { 'location': { 'lat': -33.8669710, 'lng': 151.1958750...
Balaji Singh .Y
1

votes
1

answer
59

Views

Creating Test in Jira using Rest Assured

I am new to Rest Assured and currently trying to create a JSON message for posting an issue of type TEST in Jira using Rest Assured. However, I am not able to properly create the test steps in the message. Below are the code and the message structure that I am getting. TestStepMap teststep = new Te...
1

votes
1

answer
432

Views

In REST Assured, how do I solve UnrecognizedPropertyException when mapping response to an object?

I am new to REST Assured API testing, I have already added jackson-databind, jackson-annotations and jackson-core All 2.9.6 versions to the library. Below is my code: public class SerializeAndDeserialize { @Test public void RegistrationSuccessful() { RestAssured.baseURI ='http://restapi.demo...
Aakash Goyal
1

votes
2

answer
400

Views

How to pass data across cucumber steps (Test Automation rest assured API test)?

I have created an api test which hits an endpoint and receives a response back however I'm struggling to use this response within another cucumber step. My first step uses the following method: public Response booking(SharedStepData sharedStepData, String path, BookingType bookingType) throws IOExc...
SamP
1

votes
2

answer
388

Views

How to turn of the SSL certificate and get Login response using JSOUP/Rest Assured Api?

*When i tried turning off the ssl certificate validation in Postman,i got the response but iam not sure how to turn off the ssl certificate validation through code I have used below code (JSOUP) and i am getting 'javax.net.ssl.SSLHandshakeException:' public String Login () throws Exception { Conne...
qsg testing
1

votes
2

answer
326

Views

How to pass parameters of endpoint through excel in Rest-assured

I want to Pass the parameter 'Country' with different countries names. Is it possible to keep all the country names in excel and call those from the datafile. RestAssured.given() .pathParam('country', 'Finland') .when() .get('http://restcountries.eu/rest/v1/name/{country}') .then() .body('capital',...
Mahesh
1

votes
1

answer
212

Views

Getting SSL error in rest assured

I am working on automating the API testing using Rest assured. I have one API in which if we call that API using http then server would return response code as 302 and location as same URL but with https . I ahve written the below code: RequestSpecification httprequest= RestAssured.given().relaxedH...
user35253
1

votes
0

answer
192

Views

JSON schema validation not working in rest assured with body(matchesJsonSchemaInClasspath(“get.json”));

JSON schema validation not working in rest assured with body(matchesJsonSchemaInClasspath('get.json')) i am using https://jsonschema.net/ for generating JSON schema for my JSON schema generation.Even though i have changed the converted schema so that the test should fail but giving this error java.l...
Sandeep S
1

votes
1

answer
391

Views

Why Hamcrest's containsInAnyOrder matcher accepts array and not a list?

I'm using Hamcrest's containsInAnyOrder matcher when asserting REST response using Rest Assured. Here's an example of my assertion: assertThat( body.jsonPath().getList('zones.name'), containsInAnyOrder(values.getName().toArray())); First argument returns a List. Second argument (values.getName()) al...
Vitalii Plagov
1

votes
0

answer
29

Views

Search for RestASSURED values by sending a variable

In the following code fragment I am trying to find in my responseBody a specific number by a variable and thus save its brother value. However when I try to do it that way he answers me null and if I remove the quotes he answers me: The parameter 'n0' was used but not defined. Define parameters usin...
edwin romero
1

votes
1

answer
162

Views

How to validate a REST Assured request across multiple java methods?

I am writing REST Assured tests using Cucumber. Here is my feature file: Given I want to GET a client When I request a client Then the status code is 'theStatusCode' And the id returned is 'expectedClientId' The below method is called within the Step Definition of the 'And' in my feature file publi...
1

votes
0

answer
64

Views

Check that specific field in every element of an array in a json response has specific value

i need to assert that every field 'contentType' inside 'content' in the following json response contains 'VIDEO' as value. Right now i'm checking the existance of the field with Hamcrest, like this: assertThat(response.then().body('contents.content', everyItem(hasKey('contentType')))); So i wanted a...
Lea Chescotta
1

votes
0

answer
41

Views

How to cover/improvise percentage in SONAR CUBE Report by REST Assured Test Cases?

How to cover SONAR CUBE Report for REST Assured Test Cases? Is there any possible way to improve code coverage in SONAR Using REST Assured Test Cases. Since I am using some api's & microservices I used REST assured test case. But it is not covering in SONAR CUBE. (Note: I have already used JACOCO...
1

votes
0

answer
47

Views

Jayway JsonPath .. equivalent in Gpath

I would like to fetch all embedded json elements but I could not make it working. Let's say I would like to filter all b's here. What gpath syntax to filter all b's here? { a:{ c: { b:1 } b:45 d: { b:444 } } I can use $..b in Jayway, but, how shall I use it for Groovy Gpath. I'm working with Rest-A...
CMM
1

votes
0

answer
47

Views

Spring Cloud Contracts from RestDocs: custom matchers

I am currently having a hard time generating meaningful contracts from restdocs tests using rest-assured. The problem is that I cannot find a way to generate regex matchers, it seems only byEquality matcher are generated. The documentation does not mention rest-assured at all, so it might be its fea...
ThanksForAllTheFish
1

votes
2

answer
56

Views

how to get Http status code of an initial URL using rest assured?

Suppose we have a URL http://example1.com and we have 301 URL redirect setup on this, that redirects to http://example2.com. After reaching http://example2.com, it returns the code 200. I am using following Rest assured code to get the HTTP status: public int httpResponseCodeViaGet(String url) { Sys...
Jagjeet singh
1

votes
0

answer
67

Views

StepDefinition does not work when there are more than one object in Json

Below is my Rest Method public String OrdersSuspend(String ordersSuspendJson) { Response respOrder = ctx.post(ORDERSSUSPEND,ordersSuspendJson).then(). statusCode(200).extract().response(); return respOrder.getBody().asString(); } Below is my Step Definition orderResponse.ifPresent(o -> { orderSuspen...
Lavish Khetan
1

votes
1

answer
88

Views

how to use multi part file attachment using Rest-assured in Java?

I am trying to execute post request using rest-assured with multipart/form-data, the request contains with a url with parameters and file to be attached Below is the code which I am trying and getting handshake error how can I attach a file with url ? RequestSpecification httpRequest = RestAssured...
testerBDD
1

votes
1

answer
75

Views

Can we build RequestSpecification of io.restassured in step by step manner?

I am forming io.restassured request/response in following manner Response response = RestAssured.given().headers('Authorization', 'Bearer token).contentType(ContentType.JSON).body(tempJsonString).post(MY_ENDPOINT). andReturn(); I want to create the request in step by step manner for e.g., //Auth...
Gokul
1

votes
1

answer
49

Views

How to fix not logged in error while testing?

I'm writing a few tests for my API. The API only answers when the user is logged in. I've written a test for the login API and this works, however after i run this test the other tests does not work because the user is not logged on. Code for testing the login(works): public class FunctionalTest { @...
NielsStenden

View additional questions