Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ildanno opened this issue Jul 25, 2019 · 5 comments
Open

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

ildanno opened this issue Jul 25, 2019 · 5 comments

Comments

@ildanno
Copy link

ildanno commented Jul 25, 2019

  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 ildanno changed the title newman doesn't execute test scripts declared in src field newman doesn't execute test scripts declared in script.src field Jul 25, 2019
@sauln
Copy link

sauln commented Jun 23, 2020

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

@manbradcalf
Copy link

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?

@zealoushacker
Copy link

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

@manbradcalf
Copy link

@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

@zealoushacker
Copy link

@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. 😞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants