CamillaROccasional ContributorJoined 4 years ago10 Posts2 LikesLikes received1 SolutionView All Badges
ContributionsMost RecentMost LikesSolutionsRe: Get test step property dynamically, without using the teststep name You are absolutely right! I've never used that before but looked into it and managed to create my test pretty easy. Thank you :) Get test step property dynamically, without using the teststep name Hi, I have a test step called TestStepName with a property land, which is used in the request's json. I have used the Get Data functionality to point out the property. This works fine. I have to multiply this request a lot of times, one request for each country. That's why I have the country code in the land property, so it would be easy to change it. Now the problem: When I clone the test step, the new test step's name is TestStepName2. But in the json part the reference is still "${TestStepName#land}", so it takes the property value from the original test step. How can I write this in an other way so that the property from the actual test step is used? I don't want to update all references manually, there must be a way to make the property reference dynamic. I have tried to replace TestStepName with testRunner.runContext.currentStep.name but that doesn't work. I have googled for hours but can't find a solution, so I hope someone here has a smart way to solve this. Regards, Camilla SolvedRe: Showing json response as xml, wrong value in xmlns Yes, my response is json (Content-type application/json) so I suspected that I could ignore this. Thank's for the confirmation richie. Showing json response as xml, wrong value in xmlns Hi, I test a REST-service that respond with a json. My request: GET https://develop-sys.test.abc.se/mom/19820224/201907 The json response looks fine, both i tab "JSON" and tab "Raw": { "period" : "201907", "error" : false } Since I use ReadyApi I can select to show the response in xml format in the "XML" tab. The data that was in the json is correct also in the xml view. But I get a different path in the xmlns-element than the one I sent the request to. A colleague even got another environment in the path. <Response xmlns="https://develop-sys.test.abc.se/mom/19710518/202101"> <period>201907</period> <error>false</error> </Response> Where does ReadyApi get the value for the xmlns element? I recognize the values because I have tested with those values also but not in my latest test. Has anyone else seen this behavior when showing a json response as xml? Kind regards, Camilla SolvedRe: How to get request body using a groovy script in ReadyAPI Hi Todd, My problem was not to process the json, I have used the JsonSlurper before, but how to get the contents of the request. I googled for several hours with no luck... I will try to be more clear next time I ask a question. Thank you for pointing me in the right direction, your suggested search made me find the scripting samples that I had missed 🙂 https://support.smartbear.com/readyapi/docs/testing/scripts/samples/index.html Kind regards Camilla Re: How to get request body using a groovy script in ReadyAPI Hi Rao, Thank you very much! The context variable was new to me. I have previously used messageExchange.response.responseContent to get the response and could not find the corresponding way to access the request. But now I will use context for both request and response 😊 Also thank you for the other code, I had no idea that json.drafts.period would generate an array of the periods in the response, very useful. (as you understand I'm not a developer 🙂) Kind regards Camilla How to get request body using a groovy script in ReadyAPI Hi, The request (getDrafts) I'm testing takes a list of periods and reply with a list of data for those periods. Request body: { "periods" : ["202101","202102"] } Response body: { "drafts" : [ { "period" : "202101", "data" : { "name" : "Kalle Kula", "epost" : "kalle@kula.se" } }, { "period" : "202102", "data" : { "name" : "Krille Krokodil", "phone" : "9876543210" } } ] } I would like to create a script that reads the requested periods from the request body, and for each value verifies that there is an item for that period in the response body. I also want to verify the content of the data-part for each item but first things first 🙂 The problem is I cannot figure out how to get the contents of the request body from my groovy script. Kind regards, CamillaR SolvedRe: How can I use a property in the header for a request in ReadyAPI Aha, I would love to do that too! It's OAuth. Re: How can I use a property in the header for a request in ReadyAPI Hi nmrao, You were on to something here. The problem was in my token. 1. I run a curl command in bash to generate the token and save the result to a textfile. This is done by adding " > c:/mytokenfile.txt" after the curl command 2. In SoapUI/ReadyAPI, my groovy script reads the textfile and stores the contents in the project property. The problem was this: When storing the token value into a textfile cr+lf is added at the end. And this was also read into the property. When viewing property value the cr+lf looks like a blank space in the end (in the property window). I have now fixed my groovyscript so it does not store the cr+lf in the property. Thanks for the help, /Camilla How can I use a property in the header for a request in ReadyAPI Hi, I have a SoapUI project where I use a project property "token" that is used in the header of the requests, I reference it as ${#Project#token}, see attachment for more details. I do this since I have many requests and the token needs to be renewed every hour. I load the token value into the property using a groovy script test step. This works fine when I run my requests using SoapUI 5.6.0. Now I have installed ReadyAPI 3.1.0 and imported my SoapUI project. When I run my requests in ReadyAPI I get error 503 Service Unavailable. It works OK if I use the real value in the header, e.g "Bearer eyJ0eXAiOiJKV...." but not when I use ${#Project#token} in the header. Why does it work in SoapUI but not in ReadyAPI? And how can I use the project property in the header? Kind Regards, Camilla Solved