What is the mechanism to incorporate send and download postman option from within Newman call - newman

What is the mechanism to incorporate send and download postman option from within Newman call?
Output of my REST call is file (image/binary). On running with Newman I don't see the output. Is there any way to save the contents in a file.

as of now newman do not have this feature. but you can have a workaround where you can read the output stream and write it into the file at desired location .
attaching sample code :
var i = 0,
fs = require('fs'),
newman = require('newman'); // ensure that you have run "npm i newman" in the same directory as this file
newman.run({
// run options go here
}, function (err, summary) {
// handle collection run err, process the run summary here
}).on('request', function (err, execution) { // This is triggered when a response has been recieved
if (err) { return console.error(err); }
fs.writeFile(`response${i++}.txt`, execution.response.stream, function (error) {
if (error) { console.error(error); }
});
});

Related

Enabling Google Cloud Run chunked encoding

I have tried returning 'transfer-encoding:chunked' header to a large download but the response terminated at "31.9M" which is very close to the documented "32MB" limit.
The Unofficial FAQ states chunked encoding is now possible, but I can't seem to get it working.
Do I have to flip any flags (e.g. https/2) to enable streaming? Is it only possible in some regions? (I am using europe-west1)
The following minimal case does actually stream 45MB over Cloud Run, without any special configuration, confirmed in us-central1 and europe-west1
FROM node:14-slim
COPY index.js index.js
CMD [ "node", "index.js" ]
const http = require('http');
http.createServer((request, response) => {
response.setHeader('Transfer-Encoding', 'chunked');
// 45MB
var i = 1000000;
function nextChunk() {
return new Promise(resolve => {
if (i-- > 0) {
response.write(
'123456781234567812345678123456781234567812345678',
() => nextChunk()
);
} else {
response.end();
}
})
};
Promise.all(nextChunk())
}).listen(process.env.PORT || 8080);
Even after straming into chunks I'm always getting error after 32 MB reponse size, I can't get the response header 'Transfer-Encoding' = 'chunked' from Cloud Run service response :
I'm using NestJs, and I can get it in the response Headers when I execute the app locally.
I'm specifying it as :
#Get('streamable')
#Header('Transfer-Encoding', 'chunked')
async streamable(#Res() res) { etc.. res.write(chunk)}

how to take a screenshot by a locator and then compare with the other locator with the screenshot using appium with webdriverio

how to take a screenshot by a locator and then compare with the other locator with the screenshot(and compare those two images) using appium with webdriverio. I tried looking at a tutorial but not able to find anything that works
You can capture screenshot of an element with webdriver io as mentioned below
it('should save a screenshot of the browser view', function () {
const elem = $('#someElem');
elem.saveScreenshot('./some/path/elemScreenshot.png');
});
you can see more about in on official documentation of webdriver-io
Once you capture screenshot for both element then you can use Visual Regression service for WebdriverIO V5 called wdio-image-comparison-service.
Installation:
Install this module locally with the following command to be used as a (dev-)dependency:
npm install --save-dev wdio-image-comparison-service
Instructions on how to install WebdriverIO can be found here.
Usage:
wdio-image-comparison-service supports NodeJS 8 or higher
Configuration:
wdio-image-comparison-service is a service so it can be used as a normal service. You can set it up in your wdio.conf.js file with the following:
const { join } = require('path');
// wdio.conf.js
exports.config = {
// ...
// =====
// Setup
// =====
services: [
['image-comparison',
// The options
{
// Some options, see the docs for more
baselineFolder: join(process.cwd(), './tests/sauceLabsBaseline/'),
formatImageName: '{tag}-{logName}-{width}x{height}',
screenshotPath: join(process.cwd(), '.tmp/'),
savePerInstance: true,
autoSaveBaseline: true,
blockOutStatusBar: true,
blockOutToolBar: true,
// ... more options
}],
],
// ...
};
Writing tests to compare screenshot of 2 elements:
describe('Example', () => {
beforeEach(() => {
browser.url('https://webdriver.io');
});
it('should save some screenshots', () => {
// Save an element
browser.saveElement($('#element-id'), 'firstButtonElement', { /* some options*/ });
});
it('should compare successful with a baseline', () => {
// Check an element
expect(browser.checkElement($('#element-id'), 'firstButtonElement', { /* some options*/ })).toEqual(0);
});
});
Referenec: Please check all details about image comparison here

How to capture responsebody from newman

I want to capture the responsebody in Newman.
const newman = require('newman');
newman.run({
collection: require('./xxx.json'),
iterationData: './data.jsp',
reporters: 'cli'
}, function (err, summary) {
if (err) { throw err; }
console.log('collection run complete!');
console.log(summary);
});
I use the code above. it works fine but I want to capture the json output here from the call. How can I achieve it?
Perhaps you used a wrong term for retrieving json response body. If you want to just get the response body you need to parse JSON returned and to save it to a variable.
If you would use newman to run through command line there are everything is super simple:
let body = JSON.parse(responseBody)
console.log(body)
and after test where you need to see the response you put this 2 lines of code.
But with your case perhaps you need that:
1) Callback option
const newman = require('newman');
newman.run({
collection: require('./xxx.json'),
iterationData: './data.jsp',
reporters: 'cli'
}, function (err, summary) {
if (err) { throw err; }
console.log('collection run complete!');
console.log(summary);
})
.on('request', function (err, data) {
// err, data can be used to write to files using the node fs module.
});
or the better and modern option:
let response = await newman.run({
collection: 'collection',
environment: 'env',
})
.on('request', async function (err, data) {
// err, data can be used to write to files using the node fs module.
});
console.log(response)
Not sure I will be working as expected, but at least try.
Btw, where do you run these tests? just in clear env or use some runner framework.
Postman return execution summary in Callback function. after execution if you save the summary in callback and return it. you can access request/response/ headers.
function runcollection(callback){
newman.run({
collection: 'C:\\newman\\PMP Dependency latest collection\\Updated\\TestCollection.postman_collection.json',
environment: 'C:\\newman\\PMP Dependency latest collection\\Updated\\Test.postman_environment.json',
iterationCount :1
},function(error, summary){
callback(summary)
});
}
runcollection(result => {console.log(result.run.executions[0].response.stream.toString())});

Appium ios automation nodejs scripts

I am trying to automate an iOS native app on a real device using Appium(from terminal) and nodejs script. I am able to install and launch the app till the first screen of the app but after that no nodejs scripts other than sleep is getting executed. I need to type in some text in the the textfields present in the screen but the cursor is getting pointed and nothing happens after that. Please tell me whether I am using the correct nodejs commands here.
NB:The same nodejs script was working fine for android automation
var wd = require("wd");
require('colors');
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var capture = require("capture");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var host, port, username, accessKey, desired;
console.log("Print 1");
var desired = {
'browserName': '',
'automationName': 'Appium',
'platformName': 'iOS',
'platformVersion': '6.1.4',
'deviceType':'iPhone',
'deviceName' :'xxx’s iPhone',
// 'nativeInstrumentsLib' : 'true',
'app': "/Users/Desktop/xxx_my_appname-358.ipa",
'bundleId': 'com.xxx.myapp',
'deviceOrientation': 'portrait'
};
host = "localhost";
port = 4723;
// Instantiate a new browser session
var browser = wd.promiseChainRemote(host, port, username, accessKey);
// See whats going on
browser.on('status', function (info) {
console.log(info.cyan);
});
browser.on('command', function (meth, path, data) {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
// Run the test
browser.init(desired)
// then(function () {
browser
// yield.elementByName("userNameTextField").click()
.sleep(30000) // **** WORKING FINE**
.elementByName('User Id').type('userID') // ** NOT WORKING **
.elementByName('Next').click() // ** NOT WORKING **
.elementByName('Password').type('password') // ** NOT WORKING *
.sleep(30000) // **** WORKING FINE**
.fin(function () {
return browser
.sleep(30000)
.quit()
console.log("inside click");
// });
})
.catch(function (err) {
console.log(err);
console.log("Entering into error Catch...")
throw err;
})
.done();
Try using the Appium app inspector to get the xpath of the elements:
.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]").sendKeys("userID")
.elementByXPath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]").sendKeys("password")

How to run terminal commands using Dart HttpRequest?

I need to send a request to the server to run a jar file with a string argument/parameter and return the results as a string.
On server side you can run a process and send result back like this :
HttpServer.bind(InternetAddress.ANY_IP_V4, 3031).then((server) {
server.listen((HttpRequest request) {
var param = request.uri.queryParameters['name'];
Process.run('java', ['-jar', 'myJar.jar', param]).then((pr) =>
request.response
..write(pr.stdout)
..close()
);
});
});

Resources