For my comparison testcase I need to compare the results of 2 different files with each other. For the POC I'm using mock data in files. One is an excel file the other is a json file. The question/error message is about the json file.
TestSteps ==> Groovy Script for DataSource2 (to read out the json file)
DataSource2 (to point to the file, read it out and show the content for particular columns)
Property Transfer (to request)
DataSource Loop (start again at Property Transfer)
DataSink2-Save compare results (in an excel file)
In the REST Request I have a parameter with
On TestCase Level in tab 'Custom Properties' I have 2 parameters without value as it will be filled through the loop:
I've searched information about DataSource and followed the steps to insert the properties, source step, source property, row path and column paths.
The groovy script is reading the json file without problems.
Configuration of my DataSource looks like this:
I have my 2 coloms in the Data Log but when I click on the play button, nothing happens.
When I click on the green/red stripes of the Column Paths and I select the node I'm getting this error message as in title.
Can someone explain me what I'm doing wrong please?
Thanks in advance.
Solved! Go to Solution.
I've managed to get the cbe_number and denominations values with the following settings:
Does it suit you?
The expression in the Row Path field is the beginning of the full expression. It's common for properties.
The expression in the Column Paths is the end of the expression.
So, the full expressions will look like:
$['cbe_number'] - for the cbe_number property
$['denominations']['value'] - for the denomination property
I don't know if they've changed it - but I always used to have problems using the json datasource option - I always struggled with the json datasource step - I think it might be a little buggy or perhaps I was doing something wrong (I also find xpath easier to deal with and read than jsonpath) - but I found setting it up was a lot easier if I used an XML datasource instead step instead of the json datasource.
Despite the fact that the response of the request that I was using to populate my datasource was actually .json - I added the XML datasource in and specified the 'source property' dropdown on the XML datasource as 'ResponseAsXML'.
I was then able to build up a datasource of attributes successfully sourced from my response without too much trouble - so if your groovy step is all good - this might help.
Again - and I'm guilty of this myself - but if you provided the groovyscript code on your post - this will only add to the help people can provide!
Just a suggestion,
I already had read your post somewhere, but in my case the file will expand proportionally (understand up to 35GB for starters) whereas I don't think this would be a good idea to use xml. Would it? I'm just thinking about performance.
Now it's just a mock, but in the future it will be the 'real stuff' and far more bigger then now. It also could be that for the real project I need to point to a DB, I don't know, but like I said, I don't know what this would give performance wise......
Nevertheless, might I try to parse it into XML, How should I do this please?
Secondly, my groovy code is the simplicity itself (it's just fetching the file from my harddrive:
def file1 = new File('PathToMyHarddrive/DataSource2-MOCKEnterprisePDC.json'); return file1.text;
Thirdly: why 'ResponseAsXML' specified in the 'source property' dropdown on the XML datasource? Is that a name you gave to your file?
I'm noticing that the body in DataSource for JSON is almost the same as for XML, only the row and columns name are different. So yes, could be a little bug.
Thanks already for your answer. Hoping you could elaborate on the parsing. 🙂
aah - I made a mistake - I wasn't concentrating - those additional datasources can be used to inject testdata - but personally I think they rock after generating a response - and this was what I was talking about - so don't bother looking for the ResponseAsXML option because you won't find it if you're trying to source a file from your harddrive.
In regards to your use of the JSON datasource - I'm not a groovy scripter - but looking at the groovy and what youre trying to do wiht the JSON datasource - you're trying to grab specific json attributes from the 'result' variable of the groovyscript - right?
Yeah - I don't think that'll work - all your groovy is doing is pointing to a testdata file and the 'results' of your script (which you are using as the source property in your JSON datasource step) is being passed to the 'results' variable on the groovy script. The trouble is - and I'm not sure - I'm not a scripter - but I don't believe the contents of the file you are passing equates to the 'results'
Hence the reason why I don't think the jsonpath is working in your JSON Datasource.
This is just what "I think" - I'm learning groovy slowly myself.
As an aside = I understand using groovy shortcuts a lot - but is there a reason why you're not using say a file or directory datasource rather than the groovy to load in the file?
Also - is it a GET or a POST REST request?
can you confirm what you're actually passing to the REST request step? are you passing the whole .json file's content or just a couple of parameters?
If you're just passing a couple of parameters - are you talking about URI/Template, Header or Query parameters or are you talking about parameters within a payload body? (hence my question about GET or POST or whatever)
If you can provide the above details we should be able to sort you out - I'm not understanding why you're doing a couple of things - (e.g. like using groovy to load in the file, etc.) and this is confusing me
I got it working on my machine - but I was struggling with v2.5.0, there was a defect hindering it slightly - there's stiill na issue with v2.6.0 - but only if you edit the column entry.
Anyways I upgraded to v2.6.0 - and I used 2 datasources - I'm assuming you want to actually grab specific attribute values from within the .json - right?
If you have a datasource (directory) option - pointing to a directory with your .json in it and then add a fileContents property on this datasource. Then add your JSON datasource and point this the fileContents property from the first datasource.
this will allow you to grab specific attribute values from the .json
It's not pretty having 2 datasource objects adjacent in your test - but if it works?
Check out the following images below so you can see what I'm talking about
Just to clarify the images above in my json testdata file, "nhs_location":"Opposite Sainsbury's" and "nhs_code":"V0001"
Thanks for your answers! To answer to your questions:
"In regards to your use of the JSON datasource - I'm not a groovy scripter - but looking at the groovy and what youre trying to do wiht the JSON datasource - you're trying to grab specific json attributes from the 'result' variable of the groovyscript - right?"
I'm not quite sure what you mean saying "json attributes". Do you mean like nodes in the file? Then yes, I need for this testcase 2 specific nodes and its value. But my Groovy Script mearely loads the whole file to be able to read to. I thought that this could help with reading the file out as the Datasource>JSON wasn't reading the file at all, and Datasource>File is just reading the first 10 lines of the file giving me a not wanted result in json.
GroovyScript result = OK:
DataSource2 = NOK for different reasons:
I only can add 1 RowPath for 2 properties
I can't add a column expression for each column as it gives me that error message.
I even start to doubt if I need to add an expression on the Columns....
If I understood this correctly, the DataSource Row Path refers to a specific node in the file to be searched for. Here being "Denomination" with its value. But I also need to look for the cbe_number node and it's value. And that is what I'm not able to do.
The purpose is to read information from a 'golden file' that plays the role as DB(I know, that's sheeting and ugly but it's a way for the POC to work whilst we're waiting for the DB 🙂 ) Out of that information (that should actually start in DataSource) I'm asking to Property Transfer to read the first line of the file, take the properties that I've defined and put it in my request so I can send the request with those particular properties. If the request was send successfully, I want the response to be put in the Property Transfer-GetResponse with all the properties present from the response and that will save this answer in DataSink2 for later comparision. This step is then followed by a loop to start at line 2 of the first Property Transfer. Until all the lines are read. If this is done, all the responses will be saved in DataSink2 and are then ready to be compared with the response of my other request.
I don't know if I made myself understandable here....?
"As an aside = I understand using groovy shortcuts a lot - but is there a reason why you're not using say a file or directory datasource rather than the groovy to load in the file?"
I'm still green working with ReadyAPI and a colleage of mine presented me to work this way. Now, might you have a better way to compare to different responses in 2 different extensions, be my guest.... 🙂
My posts are GETters by the way
"can you confirm what you're actually passing to the REST request step? are you passing the whole .json file's content or just a couple of parameters?" just a couple of parameters needed here: cbe_number and denomination as parameters in the Request step. Those parameters are defined on TestCase level as "tempNumber" and "tempName" in tab Custom Properties and are called upon in the REST Request as
The DataSink2 will stash the responses in and excel file.
If there's anything you want to know, please tell me.
I'm struggling a little - youve provided the project .xml file which is really helpful - but you didn't provide the spreadsheets which are the source of the data and we can't execute the steps to generate the responses.
Can you attach the spreadsheets to help visualise what you're doing as well as sample responses please?
You mention .json in your previous posts - but the first test case is a SOAP request, the second is REST - so I'm kindof not understanding why you mention using json as a datasource. Also you Property Transfer steps to get the data are all using XPATH not JSONPATH excepting the property transfer used to grab values from the REST response.
Do your datasource spreadsheet contain json files? If this is the case, why have you copied the .json files into a spreadsheet?
Apologies if I haven't been clear - I'm just a little confused!
Yaks! So sorry people! I've send the wrong file... 😞 I'm so into different tickets and my job for the moment that I've missed.
So the "Results Comparison.xlsx" should have the results of the 2 environments (2 Testcases) whereas I can compare the responses in the same sheet.
@richie I remember now why I used a Groovy Script to read out the json file. If you add a DataSource object and you select JSON one is obliged to already have a response before you can use the "pick and select". But as I don't get responses for the moment, I wanted to mock this. 😉
Please let me know if I can be of any other help.
Thanks in advance,