How to write Postman tests to compare a response body with an external JSON/CSV file using Newman? - node.js

It is well documented how to use an external data file with the Collection Runner in Postman to run multiple iterations. However, what I'd like to do is write tests to compare the response body from a GET request to a JSON/CSV file.
From the research I've done it seems this isn't possible using just Postman. I wonder though if it'd be possible with Newman?
I have no experience with Newman but am curious if this might work. Could you create a Postman collection with an env variable called TestJsonFile and write tests comparing values from that to the response body. Then export said collection and using Newman set the TestJsonFile value to that of a JSON/CSV file (--env-var "TestJsonFile=<path_to_file>") and run the collection with that variable?
This seems plausible to me; maybe I could create a Node project to do it all in one place. I'd just like to ask if anyone has done something similar as it seems like it should be doable.
Any critiques or suggestions would be much appreciated, thank you for reading!

Related

Using variables with YAML in Node.js

Is there any way to parse data to a .yaml file in node.js? I've been searching about this for hours and found nothing useful.
Let's say I have a string in a .yaml file:
message: Hello, ${user.fullName}, have a nice day.
As I've been reading, there's something called "placeholders" but it seems only available in spring framework.
This is what I found.
And in other places, they use a different syntax like {{user.fullName}}
So, is there any way to replace ${user.fullName} with an actual value in node.js? I don't know if I should manually handle this thing that they call "placeholder" myself with string.replace(). I checked the main YAML docs and there's nothing called "placeholder" or even "variable" in their entire docs!
But, similarly, I can achieve a similar result with pug.js using #{user.fullName} (with # instead) and then call something like: pug.renderFile('template.pug', {fullName: 'Timothy'}). Check pug.js docs for more details.
Thanks for your help!

Webdriver IO How to store Excel file in cache and call from cache on Node JS

I have an excel file that I want to only call in once and make available to all of my tests, at the moment it's being called on each test, I have tried storing it in the cache using https://www.npmjs.com/package/node-cache but when I tried to get it from cache it's saying undefined, so then I tried using onPrepare hook with no luck. Can someone point me in the right direction thanks in advance.
Assuming that excel has data for test automation and it does not include any writing operations, I would suggest reading the content and store it in a constant. If you declare that variable globally, it will be available to all your tests. The complexity of this READ function depends on how diverse is your data. You can use libraries like https://www.npmjs.com/package/xlsx, https://www.npmjs.com/package/exceljs, etc..,

Karate + Cucumber report missing Doc Strings for the called scenario responses

Cucumber report is missing the doc strings for the responses from a called scenario.
in a given scenario, i am calling multiple scenarios using Call ()
its printing randomly sometimes response from the called scenarios and sometimes not. This is preventing us visualizing the data flow between API in the test report.
Although the karate-log is having the response from that called scenario, its just the cucumber reporting is not printing it. we are using karate 0.9.4, cucumber reporting 4.6.0.
When statement not printing Doc String
I am trying to print it like this.
When Statement with Doc string
Please try with 0.9.6.RC3 - if it still doesn't work it is a bug and please follow this process (we need a way to replicate): https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue

Save a tensorflow.js model in node

I am trying to save a tensorflow.js model I have as a json file but it's not working.
var exampleModel = {input:1,name:'model'}
fs.writeFileSync('model.json', JSON.stringify(model,null,2))
//=> '"{\"input\":1, \"name\": \"model\"}"'
It's not in json format. I wasted a lot of time trying to manually create a json but that didn't work either and I will have to redo it by copying it to a normal object or something.
Seems noone knows anything about this. The problem was that I was using node and I needed to require "#tensorflow/tfjs-node" underneath my tfjs require line. I had to search for this page specifically as there wasn't anything about it in their documentation: https://js.tensorflow.org/tutorials/model-save-load.html
Here's another helpful link: https://github.com/tensorflow/tfjs-node

Read Jenkins build console output and set email content

I have certain errors which I set in my code, which should add corresponding error messages to the email content of the final build email.
I was thinking of printing something such as ("EMAIL CONTENT ERROR: _______") to the console, reading through it (in a pre-send groovy script?), and adding corresponding error messages for each error found.
I was thinking of using a pre-send groovy script, setting the mimeMessage object(was reading jenkins email-ext documentation). Would this be viable?
Also, I have never used groovy before, so pointers to how to approach this would be extremely helpful(or a link to where i can find an implementation of something with a similar idea of reading console). Any advice would be greatly appreciated. Thanks in advance!
Can you check attaching "Build Log" This would highlight all the process of build process.
This is a very similar concept to the question here. The technique there was to use the log parser plugin to scan the console output for you, and then use groovy to add all the errors into an email.
This is generally a pretty good idea because it also means that you can view the same set of highlighted errors from jenkins itself, rather than just the email.
There are a couple of ways this is different from your setup, the main points are:
Yes, write errors directly to the console in a known format
Set the log parser up with regular expressions that find your error format
Instead of a pre-send script, in this case you would use a groovy template for your email generation
The template reads the error list from the console parser and adds them to your email. Each one is a link that links back to the jenkins console output.

Resources