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

feature: added support parameters from data files #694

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions qase-newman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ https://app.qase.io/run/QASE_PROJECT_CODE
<img src="./screenshots/demo.gif">
</p>

You can find more information about using the reporter [here](./docs/usage.md).

## Configuration

Qase Newman reporter can be configured in multiple ways:
Expand Down
7 changes: 7 additions & 0 deletions qase-newman/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# [email protected]

## 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).

# [email protected]

## What's new
Expand Down
80 changes: 80 additions & 0 deletions qase-newman/docs/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# 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, by default, test will not have any parameters passed. But you can enable
specific option in config file to pass all parameters from data file if test have not commented `qase.parameters`
line.

```json
{
"debug": true,
"testops": {
"api": {
"token": "api_key"
},
"project": "project_code",
"run": {
"complete": true
}
},
"framework": {
"newman": {
"autoCollectParams": true
}
}
}
```
5 changes: 3 additions & 2 deletions qase-newman/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "newman-reporter-qase",
"version": "2.0.1",
"version": "2.0.2",
"description": "Qase TMS Newman Reporter",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -45,8 +45,9 @@
"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",
"ajv": "^8.17.1",
"jest": "^29.5.0",
"postman-collection": "^4.1.7",
"ts-jest": "^29.1.0"
Expand Down
31 changes: 31 additions & 0 deletions qase-newman/src/configSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { JSONSchemaType } from 'ajv';

import { FrameworkOptionsType } from 'qase-javascript-commons';

import { ReporterOptionsType } from './options';

export const configSchema: JSONSchemaType<FrameworkOptionsType<'newman', ReporterOptionsType>> = {
type: 'object',
nullable: true,

properties: {
framework: {
type: 'object',
nullable: true,

properties: {
newman: {
type: 'object',
nullable: true,

properties: {
autoCollectParams: {
type: 'boolean',
nullable: true,
},
},
},
},
},
},
};
3 changes: 3 additions & 0 deletions qase-newman/src/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface ReporterOptionsType {
autoCollectParams?: boolean;
}
Loading
Loading