authorjapps / zerocode

A community-developed, free, opensource, automated testing framework for microservices APIs, Kafka(Data Streams) and Load testing. Zerocode Open Source enables you to create, change and maintain your automated test scenarios via simple JSON or YAML files. Visit documentation below:
https://zerocode-tdd.tddfy.com
Apache License 2.0
910 stars 399 forks source link

Unable to pass array to body of request from previous API response. #531

Open vinayak5044 opened 2 years ago

vinayak5044 commented 2 years ago

API response of previous POST request: "dtcIds" : [ "#37:1498", "#37:1499", "#37:1502", "#37:1503" ]

Need to pass this whole array to body of request - But After running getting in logs like: "request": { "headers": { "locale": "${locale}" }, "body": { "dtcIds": "${$.previousRequest.response.body.dtcIds[?(@.*)]}" }

In logs it seems like, zerocode_backSlash

I don't want backword slash there ....Please help me to do it. Please refer attached screenshot.

vinayak5044 commented 2 years ago

It should be pass to body(payload) like this only - "dtcIds" : [ "#37:1498", "#37:1499", "#37:1502", "#37:1503" ]

and not like - zerocode_backSlash1

vinayak5044 commented 2 years ago

@sparrowV Could you please look into it ?

ayushdubey755 commented 2 years ago

Hi @vinayak5044 i have recently work on such type of issue in which i have created instance of JSONObject and passed the string(in your case "dtcIds") in the arguments and then with the help of JSONObject reference i have invoked jsonObject.optString("dtcIds").replace("\", ""); , used sprinboot in my project.

vinayak5044 commented 2 years ago

Hi @ayushdubey755 Thanks for reply.

But In my case, Can you please help to understand how to create jsonObject because I am taking array "dtcIds" from previous api response and chained it in required API.

For more understanding please refer below attached screenshot: I want syntax to pass in red marked square which will reflect correct dtcIds list

zerocode_sample

ayushdubey755 commented 2 years ago

//sample code @vinayak5044 private void initAuthor() { Path path = Paths.get(authorDumpLocation); try (Stream lines = Files.lines(path)) { lines.forEach(line -> { //read and parse the line String jsonString = line.substring(line.indexOf("{")); try { JSONObject jsonObject = new JSONObject(jsonString);

                //construct the author object
                Author author = new Author();
                author.setName(jsonObject.optString("name"));
                author.setPersonalName(jsonObject.optString("personal_name"));
                author.setId(jsonObject.optString("key").replace("/authors/", ""));

This is the code that i was talking about i have also new to this concept and get to know about it during handson practice Here is the link to a video hope this will give you some help https://www.youtube.com/watch?v=24NrLl8EhDM&list=PLJ5_m4Y8xLkkxfo2Z1Lb0qjXnAZqIWCCZ&index=9

vinayak5044 commented 2 years ago

Hi @ayushdubey755

I tried but unable to do it.

I am confused where I need to write this method to replace regex and how to call it from json test cases file ?