You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
OS Details( Microsoft Windows 10 pro, Version 10.0.17763 Build 10.0.17763)
3: Using Newman as a library
4: Just started using Newman 5 days ago and issue has existed the entire time I've been using Newman
5: Expected behavior:
I ran a collection called sales collection runs perfectly fine in Postman Runner, encounters an error when running using Newman. The collection two calls. The first call (Sales Token) works perfectly fine and all the tests return as expected. the second call (Sale) has a couple of environment variables that are passed from the response and is wrapped in a conditional statement based on whether the or whether not the response returns a 201 status or a 422. I also written some test scripts that run whether or whether not the status returned is 422 or 201. Sale also has some environment variables that are passed in from a CSV and are set as an environment variable. The problem is that whenever I run the collection using Newman, (Sale) returns a 422 and also returns a TypeError Cannot read property 'incomingTransactionCode' of undefined at test-script inside "Sale" for all iterations. This error does not occur in the Postman Runner.
Command used to run Newman:
node command_line_runner
Below is the code in the command_line_runner.js file:
/*
The conditional vars are based on whether or whether not the response code returned is 201.
If so, then the variables are given a value, if not then the values remain null.
This is to prevent undefined variables that are expected to have values causing the tests to abort test runs.
*/
if (responseCode == 201){
if (cvv == 999) {
//local conditional vars
ITC = jsonRespData.Transaction.incomingTransCode;
saleGuid = jsonRespData.guid;
//environment conditional vars
pm.environment.set("IncomingTransactionCode", ITC);
pm.environment.set("saleGuid", saleGuid);
}
}
//Global Vars
//Tests
//condition based on cvv code being 999
/*
will only run the following tests:
response status test(201)
ITC test
based on the Cvv value being 999
*/
if(cvv == 999) {
//response status test(201)
//will return pass if response code is 201
pm.test("Response is 201", function () {
pm.response.to.have.status(201);
});
//ITC test
// will return pass if ITC is returned
pm.test("ITC test", function(){
pm.expect(ITC).to.not.be.null;
});
console.log(saleGuid);
//condition based on cvv code being 996
/*
will only run the following tests:
response status test(422)
invalid Cvv test
based on the Cvv value being 996
*/
}else if(cvv == 996) {
//response status test(422)
// will pass if response code is 422
pm.test("Response is 422", function () {
pm.response.to.have.status(422);
});
CvvNumb,Amount,ExpectedPayments,Comments 999,35,3,should return a successful sale and create a ITC 996,70,4,should return a 422 error that states that the Cvv number is invalid and should not create an ITC
Below are the results when running in Newman:
Below are the results in running in Postman Runner:
The text was updated successfully, but these errors were encountered:
kbryantkb
changed the title
Canno read property 'xxx' of undefined at test script
Cannot read property 'xxx' of undefined at test script {{URGENT}}
Apr 29, 2019
kbryantkb
changed the title
Cannot read property 'xxx' of undefined at test script {{URGENT}}
Cannot read property 'incomingTransCode' of undefined at test script {{URGENT}}
Apr 29, 2019
@kbryantkb Cannot read property x of undefined is because of unsafe access to a property which in your case is incomingTransCode in jsonRespData.Transaction object.
Which means response it received in Newman is different (Transaction is undefined) from what it got in the collection runner.
I see you used two different data file (CSV) as well, might be that's the issue.
I suggest you add console.log (or add tests) for request body sent and the response received to verify those first for every iteration.
Closing this issue because it's not related to Newman, maybe you could post this question in https://community.getpostman.com/ to get help around how to fix this.
Version and environment information
3: Using Newman as a library
4: Just started using Newman 5 days ago and issue has existed the entire time I've been using Newman
5: Expected behavior:
I ran a collection called sales collection runs perfectly fine in Postman Runner, encounters an error when running using Newman. The collection two calls. The first call (Sales Token) works perfectly fine and all the tests return as expected. the second call (Sale) has a couple of environment variables that are passed from the response and is wrapped in a conditional statement based on whether the or whether not the response returns a 201 status or a 422. I also written some test scripts that run whether or whether not the status returned is 422 or 201. Sale also has some environment variables that are passed in from a CSV and are set as an environment variable. The problem is that whenever I run the collection using Newman, (Sale) returns a 422 and also returns a TypeError Cannot read property 'incomingTransactionCode' of undefined at test-script inside "Sale" for all iterations. This error does not occur in the Postman Runner.
Command used to run Newman:
node command_line_runner
Below is the code in the command_line_runner.js file:
newman.run({ collection: 'https://api.getpostman.com/collections/xxxxxxxxxxxxxxxxxx?apikey=xxxxxxxxxxxxxxxxxxxx', environment: 'https://api.getpostman.com/environments/xxxxxxxxxxxxxxxxxx?apikey=xxxxxxxxxxxxxxxxxx', iterationData: './postman_test_data/submit_sales_test.csv', reporters: 'cli' }, function(err, summary){ if (err) {throw err;} console.log(summary.run.stats); });
Required parts of the body:
{ { "DeviceGuid": "{{Device}}", "Amount": "{{amount}}", "OrderNumber": "ABCXYZ-PARENT", "SendReceipt": false, "RiskProcessingOnly": false, "Transactions": { "ExpectedPayments": "{{expectedPayments}}" },"Card": { "CardHolderName": "Joe Cardholder", "CardNumber": "4111111111111111", "ExpirationDate": "1901", "Cvv2" : "{{cvvNumb}}", "Customer": { "FirstName": "Joe", "LastName": "Cardholder", "Email": "joe.cardholder@mailinator.com", "Address1": "123 Main St", "Address2": "Suite 500", "City": "Beverly Hills", "State": "CA", "Zip": "90210" } }
Prereqs:
`var cvvNumb, amount, expectedPayments;
//data feed
cvvNumb = data.CvvNumb;
pm.environment.set("cvvNumb",cvvNumb);
amount = data.Amount;
pm.environment.set("amount", amount);
expectedPayments = data.ExpectedPayments;
pm.environment.set("expectedPayments", expectedPayments);`
Test Scripts:
`var ITC, saleGuid, responseCode, cvv, jsonRespData, reqBody;
//local vars
jsonRespData = pm.response.json();
reqBody = JSON.parse(pm.request.body.raw);
responseCode = pm.response.code;
cvv = reqBody.Card.Cvv2;
//conditional vars
/*
The conditional vars are based on whether or whether not the response code returned is 201.
If so, then the variables are given a value, if not then the values remain null.
This is to prevent undefined variables that are expected to have values causing the tests to abort test runs.
*/
if (responseCode == 201){
if (cvv == 999) {
//local conditional vars
ITC = jsonRespData.Transaction.incomingTransCode;
saleGuid = jsonRespData.guid;
//environment conditional vars
pm.environment.set("IncomingTransactionCode", ITC);
pm.environment.set("saleGuid", saleGuid);
}
}
//Global Vars
//Tests
//condition based on cvv code being 999
/*
will only run the following tests:
based on the Cvv value being 999
*/
if(cvv == 999) {
//response status test(201)
//will return pass if response code is 201
pm.test("Response is 201", function () {
pm.response.to.have.status(201);
});
//ITC test
// will return pass if ITC is returned
pm.test("ITC test", function(){
pm.expect(ITC).to.not.be.null;
});
console.log(saleGuid);
//condition based on cvv code being 996
/*
will only run the following tests:
based on the Cvv value being 996
*/
}else if(cvv == 996) {
//response status test(422)
// will pass if response code is 422
pm.test("Response is 422", function () {
pm.response.to.have.status(422);
});
//invalid Cvv test
//will return pass if returns Cvv verification error
pm.test("CVV Error Message", function() {
pm.expect(jsonRespData.message).to.eql("Error code D2020. CVV2 verification failed");
});
}`
Data CSV:
CvvNumb,Amount,ExpectedPayments,Comments 999,35,3,should return a successful sale and create a ITC 996,70,4,should return a 422 error that states that the Cvv number is invalid and should not create an ITC
Below are the results when running in Newman:
Below are the results in running in Postman Runner:
The text was updated successfully, but these errors were encountered: