newman icon indicating copy to clipboard operation
newman copied to clipboard

newman doesn't execute test scripts declared in `script.src` field

Open ildanno opened this issue 5 years ago • 5 comments

  1. Newman Version (can be found via newman -v): 4.5.1

  2. OS details (type, version, and architecture): Official Docker image, alpine-based (postman/newman:4.5.1-alpine)

  3. Are you using Newman as a library, or via the CLI? CLI

  4. Did you encounter this recently, or has this bug always been there: This is the very first time I try to execute this

  5. Expected behaviour: Execute test scripts in external files, as well as embedded ones

  6. Command / script used to run Newman:

docker run --rm -t -i -v $PWD:/etc/newman postman/newman:4.5.1-alpine run collection.json
  1. Sample collection, and auxiliary files (minus the sensitive details):
  • collection.json:
{
	"info": {
		"name": "Examples",
		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
	},
	"item": [
		{
			"name": "HTTP GET with embedded test script",
			"event": [
				{
					"listen": "test",
					"script": {
						"exec": [
							"pm.test(\"Embedded: status code is 200\", function () {",
							"    pm.response.to.have.status(200);",
							"});"
						],
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "GET",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": ""
				},
				"url": {
					"raw": "https://postman-echo.com/get",
					"protocol": "https",
					"host": [
						"postman-echo",
						"com"
					],
					"path": [
						"get"
					]
				}
			},
			"response": []
		},
		{
			"name": "HTTP GET with linked test script",
			"event": [
				{
					"listen": "test",
					"script": {
						"src": "./test_script.js",
						"type": "text/javascript"
					}
				}
			],
			"request": {
				"method": "GET",
				"header": [],
				"body": {
					"mode": "raw",
					"raw": ""
				},
				"url": {
					"raw": "https://postman-echo.com/get",
					"protocol": "https",
					"host": [
						"postman-echo",
						"com"
					],
					"path": [
						"get"
					]
				}
			},
			"response": []
		}
	]
}
  • test_script.js:
pm.test("Linked: status code is 200", function () {
    pm.response.to.have.status(200);
});
  1. Screenshots (if applicable): As you can see, no assertion is executed for call HTTP GET with linked test script, and the total count is 1:
Examples

→ HTTP GET with embedded test script
  GET https://postman-echo.com/get [200 OK, 604B, 644ms]
  ✓  Embedded: status code is 200

→ HTTP GET with linked test script
  GET https://postman-echo.com/get [200 OK, 698B, 116ms]

┌─────────────────────────┬─────────────────────┬────────────────────┐
│                         │            executed │             failed │
├─────────────────────────┼─────────────────────┼────────────────────┤
│              iterations │                   1 │                  0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│                requests │                   2 │                  0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│            test-scripts │                   2 │                  0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│      prerequest-scripts │                   0 │                  0 │
├─────────────────────────┼─────────────────────┼────────────────────┤
│              assertions │                   1 │                  0 │
├─────────────────────────┴─────────────────────┴────────────────────┤
│ total run duration: 862ms                                          │
├────────────────────────────────────────────────────────────────────┤
│ total data received: 544B (approx)                                 │
├────────────────────────────────────────────────────────────────────┤
│ average response time: 380ms [min: 116ms, max: 644ms, s.d.: 264ms] │
└────────────────────────────────────────────────────────────────────┘

ildanno avatar Jul 25 '19 14:07 ildanno

Any update on if this will be addressed? I see src in the v2.1 schema, but it doesn't seem to be implemented.

sauln avatar Jun 23 '20 21:06 sauln

I would love love love to be able to edit postman scripts outside of the postman app, as my postman collections/test/environments live within a github repo alongside other source-controlled code.

I find it hard to believe the only way I can update my Postman scripts is editing from within Postman just so I can export it in order to overwrite the postman_collection.json file that already exists for my tests. It is a real killer of my workflow and probably the only thing I dont like about Postman

Am I missing something obvious or is there just no way to support editing tests in the text editor of your choice? I thought that would be an MVP kind of thing. Or is this feature not implemented because it kind of competes with the paid Workspaces?

manbradcalf avatar Jan 07 '22 21:01 manbradcalf

@manbradcalf have you found a way by chance or is this still DOA?

zealoushacker avatar Nov 15 '23 16:11 zealoushacker

@manbradcalf have you found a way by chance or is this still DOA?

No.

I ended up migrating the tests that lived inside my Postman collections to a source-controlled node / mocha / chai / axios project.

Node for the runtime Mocha for the test runner Chai for the assertions Axios to make the http calls

manbradcalf avatar Nov 15 '23 17:11 manbradcalf

@manbradcalf have you found a way by chance or is this still DOA?

No.

I ended up migrating the tests that lived inside my Postman collections to a source-controlled node / mocha / chai / axios project.

Node for the runtime Mocha for the test runner Chai for the assertions Axios to make the http calls

Yah, that seems like a much better strategy. I was leaning in a similar direction myself. Too bad, postman/newman. 😞

zealoushacker avatar Nov 15 '23 17:11 zealoushacker