diff --git a/qase-newman/README.md b/qase-newman/README.md index 0746604c..a7db2670 100644 --- a/qase-newman/README.md +++ b/qase-newman/README.md @@ -48,6 +48,8 @@ https://app.qase.io/run/QASE_PROJECT_CODE
+You can find more information about using the reporter [here](./docs/usage.md). + ## Configuration Qase Newman reporter can be configured in multiple ways: diff --git a/qase-newman/changelog.md b/qase-newman/changelog.md index 6c80dd64..b627b1cd 100644 --- a/qase-newman/changelog.md +++ b/qase-newman/changelog.md @@ -1,3 +1,10 @@ +# qase-newman@2.1.0 + +## What's new + +Added support parameters from data files in Newman. +How to use parameters from data files in Newman, see [here](./docs/usage.md). + # qase-newman@2.0.0 ## What's new diff --git a/qase-newman/docs/usage.md b/qase-newman/docs/usage.md new file mode 100644 index 00000000..9a8a40ed --- /dev/null +++ b/qase-newman/docs/usage.md @@ -0,0 +1,59 @@ +# How to Use Parameters from Data Files in Newman + +Newman allows you to leverage parameters from data files to make your API tests more dynamic and efficient. By utilizing +the `--data` or `-d` option when running a collection, you can feed your tests with various input sets. The data files +can be formatted as either JSON or CSV. + +### Example Data File + +Consider the following `data.json` file, which contains user data structured as complex objects: + +```json +[ + { + "userid": 1, + "user": { + "name": "John", + "age": 30 + } + }, + { + "userid": 2, + "user": { + "name": "Jane", + "age": 25 + } + } +] +``` + +### Example Tests + +Below are example tests that utilize the data parameters defined in the data file: + +```javascript +// qase.parameters: userId, user.name +pm.test("Status code is 201", function() { + pm.response.to.have.status(201); +}); + +// qase.parameters: userId +pm.test("Response has correct userId", function() { + var jsonData = pm.response.json(); + pm.expect(jsonData.userId).to.eql(pm.iterationData.get("userid")); +}); + +pm.test("Response has correct name", function() { + var jsonData = pm.response.json(); + pm.expect(jsonData.user.name).to.eql(pm.iterationData.get("user.name")); +}); +``` + +### Expected Behavior + +When you run the tests, the following behavior is expected: + +- In the **`Status code is 201`** test, both `userId` and `user.name` will be passed as parameters. +- In the **`Response has correct userId`** test, only the `userId` parameter will be passed. +- In the **`Response has correct name`** test, all relevant parameters from the data file will be passed, including + `userId`, `user.name`, and `user.age`. diff --git a/qase-newman/package.json b/qase-newman/package.json index 07675a91..28961502 100644 --- a/qase-newman/package.json +++ b/qase-newman/package.json @@ -1,6 +1,6 @@ { "name": "newman-reporter-qase", - "version": "2.0.1", + "version": "2.1.0", "description": "Qase TMS Newman Reporter", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -45,7 +45,7 @@ "devDependencies": { "@jest/globals": "^29.5.0", "@types/jest": "^29.5.2", - "@types/newman": "^5.3.3", + "@types/newman": "^5.3.6", "@types/postman-collection": "^3.5.7", "jest": "^29.5.0", "postman-collection": "^4.1.7", diff --git a/qase-newman/src/reporter.ts b/qase-newman/src/reporter.ts index 3058bd77..ed3ad628 100644 --- a/qase-newman/src/reporter.ts +++ b/qase-newman/src/reporter.ts @@ -1,10 +1,8 @@ import { EventEmitter } from 'events'; import semver from 'semver'; -import { NewmanRunExecution } from 'newman'; -import { - EventList, PropertyBase, PropertyBaseDefinition, -} from 'postman-collection'; +import { NewmanRunExecution, NewmanRunOptions } from 'newman'; +import { EventList, PropertyBase, PropertyBaseDefinition } from 'postman-collection'; import { ConfigType, QaseReporter, @@ -13,7 +11,9 @@ import { TestResultType, getPackageVersion, ConfigLoader, - composeOptions, Relation, SuiteData, + composeOptions, + Relation, + SuiteData, } from 'qase-javascript-commons'; export type NewmanQaseOptionsType = ConfigType; @@ -27,6 +27,11 @@ export class NewmanQaseReporter { */ static qaseIdRegExp = /\/\/\s*?[qQ]ase:\s?((?:[\d]+[\s,]{0,})+)/; + /** + * @type {RegExp} + */ + static qaseParamRegExp = /qase\.parameters:\s*([\w.]+(?:\s*,\s*[\w.]+)*)/i; + /** * @param {EventList} eventList * @returns {number[]} @@ -50,9 +55,33 @@ export class NewmanQaseReporter { return ids; } + /** + * @param {EventList} eventList + * @returns {string[]} + * @private + */ + private static getParameters(eventList: EventList) { + const params: string[] = []; + + eventList.each((event) => { + if (event.listen === 'test' && event.script.exec) { + event.script.exec.forEach((line) => { + const match = line.match(NewmanQaseReporter.qaseParamRegExp); + + if (match) { + const parameters: string[] = match[1]?.split(/\s*,\s*/) ?? []; + + params.push(...parameters); + } + }); + } + }); + + return params; + } + /** * @param {PropertyBase