Hot answers tagged

5

For example you have the following response: And you need to extract John from it. Add JSON Extractor Post Processor Configure it as follows: Reference Name: anything meaningful, i.e. name JSON Path Expressions: $.name That's it, you now have ${name} JMeter Variable with the value of John If now you want to validate its value you can add a Response ...


5

If you would love to test REST API then I would recommend you to use Rest Assured which is a Java Library. It’s better to create Page Object Model and use Testing Framework like TestNG to write tests. Along with the main library ( REST ASSURED) that you can use for testing REST API. Below is the official guide for the same: rest-assured/rest-assured OR ...


3

Unit tests, by the book, are meant to exercise the code you write, isolating it from dependencies (SO calls, external libraries and even language built-in libraries if important for your code) through mocking. What you may need is integration tests, which means checks that will evaluate if two components can communicate. They are different than integrated ...


3

ReSharper is just an IDE for C# by JetBrains. This won't help you much unless you want to write everything from scratch. Postman has the ability to generate code snippets for various languages and frameworks, including C# (using RestSharp as REST/HTTP client). Consequently, you should be able to simply "convert" your requests to C#. (Haven't tried this ...


3

Hi you can use multiline argument (docstring) for this: https://cucumber.io/docs/gherkin/reference/#doc-strings https://github.com/intuit/karate/blob/master/README.md#multi-line-expressions Your step definition: Here you pass the json between """ and """ Given a blog post named "Random" with Markdown body """ { "benefitPlanIDs": [ { "...


3

Json won't support multiline string, so you have to stringify free text before sending, (meaning convert space, tab etc to equivalent escape characters like \n, \t etc) You can use the below site to stringify text to JSON string: https://onlinetexttools.com/json-stringify-text You can use below online website for character count: https://charactercounttool....


3

You just get Response object from your call and do: public class Test { public static void main(String[] args) { Response response = RestAssured .get("https://mocki.io/v1/22617277-2eca-4fcf-b7e2-8c80851ef45d"); if(response.path("shop.type") == null){ System.out.println("key does not ...


2

Not knowing the details of JDBC and JSON response it is hard to provide exact configuration, from the high level perspective it should be something like: Add JSON Extractor and store "interesting" part(s) of the response into JMeter Variable(s) Add JDBC PostProcessor and store values from the DB into JMeter Variable(s). See Debugging JDBC Sampler Results ...


2

Use HTTP Request sampler to perform initial call to the web service endpoint. You may also need to have HTTP Header Manager to send the relevant Content-Type header Use JSON Extractor to extract the above URLs and convert them into JMeter Variables Use JMeter Variables in the following HTTP Request samplers to check the URLs. Response code can be verified ...


2

Nothing to do with selenium for log parsing. you need to use java/perl/python which ever language your are using for writing selenium test scripts. But i implemented this kind of funtionality to check application logs. While implementing this you need to check following: 1. whether your application logs are generated with proper delimiters to indicate each ...


2

Okay, so $..[?(@.name=='${RNAME}')].id actually works and the debug sampler was showing a match with RID_matchNr=1 but I was getting an empty match because I hadn't set my Match No. under the JSON path expression to 1 which says the first match.


2

You can do this using JSON Extractor Add JSON Extractor as a child of the request which returns the above JSON Configure it as follows: That's it, now you have all serviceItemId values extracted into the following JMeter Variables: serviceItemId_1=SGR40400002 serviceItemId_2=SGR40400003 serviceItemId_3=SGR40400002 serviceItemId_matchNr=3 You can now ...


2

You need to apply the below areas to your framework: The body for the POST call should be coming from a model file. Use a java serialization/de-serialization library like jackson or Gson to achieve this, although RestAssured has this feature. Creating complex json becomes easier. Create a RequestSpecBuilder to create the POST call, so that you can reuse ...


2

Karate is a relatively new project that is specialized for testing JSON web-services and it runs on the JVM. Disclaimer: am dev. There are a set of demos and examples that will get you started very easily. One of the highlights of Karate is the "native" support for JSON and being able to perform a "deep equals" on two payloads.


2

This is something you can do by marshalling POJO's to JSON. For example with a framework such as Jackson. As described in this tutorial you can use a Jackson ObjectMapper: import com.brunozambiazi.model.User; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.Calendar; import java.util.HashSet; public class SerializationTest { ...


2

Your data is not a valid JSON, you can check it yourself using i.e. online JSON formatter and validator You syntax of combination of __eval() and __FileToString() functions is incorrect, you should wrap the __FileToString() function into the __eval() and you're doing the opposite thing: ${__eval(${__FileToString(${Json_request.txt},,)})} More information: ...


2

Your JSON is not valid: 1 { 2 "User ID": 204120, 3 "name": "New User", 4 "Description": [{ 5 "name": "john", 6 "id": 204110, 7 "type": "robotics" 8 }], 9 "Status": "Post request Successfully" 10 } You need to add a name to the value on lines 5,6,7 Or you need to remove the {} brackets to make it valid "Description": [ "john", ...


2

I'm assuming you are using Java in your testing framework. You have two ways of achieving it. Option 1: Try using Karate framework. If you use Java and want to do easy API testing. Option 2: Table is an object with fields named accordingly to table header. Basically you need to serialize them to json in a way that is suitable. You can use gson library ...


2

Welcome. You need to read the documentation in detail, it shows an example of a request body for PUT method: { "name":"test1", "salary":"1123", "age":"23" } There is no employee_ in the names of the attributes. So an example flow could look like this: 1) create an employee with POST ...


2

JMeter's built-in CSV Data Set Config is reading lines from the CSV file sequentially so each user will get the next line on each iteration. If you need to read a random line (however I don't think it's a good idea as I believe tests need to be repeatable) you will need to go for some plugins like: Random CSV Data Set Config or HTTP Simple Table Server ...


2

Example json: { "priceOne": 1034, "priceTwo": {"new":2}, "priceThree": 7282 } Checking the value of "new" Response response =RestAssured.get("https://newnnnnnnn.free.beeceptor.com"). then().extract().response(); JSONObject jsonObj = ...


1

1 - Read data from JSON Google has a very good Java library to parse JSON in a structured way: GSON The types you would use the most are JSONObject and JSONElement. 2 - Use the data in a test I would suggest having in your dataprovide only the name of the JSON file. In the test, you can call a factory that would read the JSON file and generate a POJO ...


1

I think you have the logic wrong JSON.dump creates a string while JSON.loads creates an object so you are creating a string from json object and then converting it back to json object and also you are calling resp['unavailableQty'], but if the resp is the json that you have given, then it does not have a direct property field 'unavailableQty'. To get it ...


1

To start with, your expected addition to the template is incorrect and would error out as invalid JSON. Unless the system allows multiple itemLines objects, you really want to be adding a second itemLine to the to the itemLines array. Some basic JSON terminology: An element is in the form "something" - think of this as the string equivalent in other ...


1

Both your JSON entities are invalid therefore I'm afraid no one will be able to help. To give you some direction you can use Json Path to filter out "interesting" parts of the source JSON and JsonBuilder to produce the new one. Add JSR223 PostProcessor as a child of the request which returns the "bigger" JSON Put the following code into "Script" area: def ...


1

Use the following jsonpath query: serviceLines[0].customerProducts.findAll{product -> product.highLevelProduct == 'HSI'}.customerProductIdentifier Test: System.out.println(js.get("serviceLines[0].customerProducts.findAll{product -> product.highLevelProduct == 'HSI'}.customerProductIdentifier").toString()); Note, that it will return list of ...


1

The most convenient way would be using a specialised framework for API testing, you can consider RestAssured if you don't have any better alternatives. Extracting response header would be as simple as: Response response = get("/your/url"); String rcAuthToken = response.getHeader("rcAuthToken"); More information: RestAssured: Headers, cookies, status ...


1

To get token values:: u need to pass parameters like username, password, grant_type, client_id n client_secret...which will be shared by respective developer of the API...


1

Add a header manager - try with Content-Type and if it didnt work then try with Accept; remember these for the future - 400 series error - Check the Header file 500 series error - check the data


1

As it has never been added, the answer has been given here: https://stackoverflow.com/questions/43035806/how-do-i-save-jmeter-variables-created-at-runtime-specifically-a-snippet-of-js/43037917#43037917 And see manual on Sample variable


Only top voted, non community-wiki answers of a minimum length are eligible