Skip to content

Commit be5286d

Browse files
authored
Merge pull request #1 from hadiindrawan/dev
new version to main
2 parents 05a0cec + 109e1d8 commit be5286d

File tree

14 files changed

+746
-44
lines changed

14 files changed

+746
-44
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
node_modules
22
package-lock.json
33
.env
4-
.example.env
54
tests
65
runner
76
mochawesome-report
8-
notes.txt
9-
*.json
7+
notes.txt

README.md

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,32 @@
11

22
# Automation API Generator
33

4-
This project has created to relieve work load as SDET or Automation Test Engineer. In moderation, automation API code able to write with only run the script and generate from Postman collection. You just export the collection, and run the Generator to write the automation code.
5-
6-
7-
8-
9-
## Features
10-
11-
- Mocha chai generator
12-
13-
14-
## Installation
15-
16-
First export your Postman collection which want to generate
17-
18-
Clone the project repository to your directory and move json file (Postman collection export) to your directory
19-
20-
Install package with npm
21-
22-
```bash
23-
npm install
24-
```
25-
26-
Run the generator with
27-
```bash
28-
npm run generate <your-json-file>
29-
```
30-
31-
Example:
32-
```bash
33-
npm run generate MyProject.json
34-
```
35-
And, that's it, you just convert your Postman collection json file to Automation code (Mocha chai)
36-
## Configure your test
37-
38-
To run tests, you should configure some file
39-
40-
- If your scenario have some cases, you can using DDT (Data Driven Test), you can configure on test file in data variable
41-
- If you using json schema to validate the response, you just input each json response to json_response folder file
42-
- For run the test, you should configure the runner file
4+
This project has created to relieve work load as SDET or Automation Test Engineer. In moderation, automation API code able to write with only run the script and generate from Postman collection. You just export the collection and run the Generator to write the automation code.
5+
6+
## Objectives
7+
8+
1. Generate Postman collection with JSON format into Mocha-Chai template scripts
9+
2. Applying DDT (data-driven test) mechanism to request API with a lot of datas in body request
10+
3. Applying POM (page-object model) mechanism to request the API so it can be reused to another test file
11+
4. Have default verification for status code and json-schema
12+
5. Create scripts that easy to maintain
13+
14+
## List of Contents:
15+
- [Prerequisite](docs/prerequisite.md)
16+
- [Installation](docs/installation.md)
17+
- [Lifecycle of Mocha Framework](docs/lifecycle.md)
18+
- [Folder Structure and Usage](docs/folder.md)
19+
- [/runner](docs/folder.md#runner)
20+
- [/tests/data](docs/folder.md#testsdata)
21+
- [/tests/helper](docs/folder.md#testshelper)
22+
- [/tests/pages](docs/folder.md#testspages)
23+
- [/tests/scenarios](docs/folder.md#scenarios.md)
24+
- [/tests/schema](docs/folder.md#testsschema)
25+
- [Scenarios](docs/scenarios.md)
26+
- [Default templates](docs/scenarios.md#default-templates)
27+
- [Default templates with body request](docs/scenarios.md#default-templates-with-body-request)
28+
- [Pages](docs/pages.md)
29+
- [Default templates](docs/pages.md#default-templates)
30+
- [Implementation](docs/implementation.md)
31+
- [Best Practices](docs/practice.md)
32+
- [Common Error](docs/error.md)

docs/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
# Automation API Generator
3+
4+
This project has created to relieve work load as SDET or Automation Test Engineer. In moderation, automation API code able to write with only run the script and generate from Postman collection. You just export the collection, and run the Generator to write the automation code.
5+
6+
## Objectives
7+
8+
1. Generate Postman collection with JSON format into Mocha-Chai template scripts
9+
2. Applying DDT (data-driven test) mechanism to request API with a lot of datas in body request
10+
3. Applying POM (page-object model) mechanism to request the API so it can be reused to another test file
11+
4. Have default verification for status code and json-schema
12+
5. Create scripts that easy to maintain
13+
14+
## List of Contents:
15+
- [Prerequisite](prerequisite.md)
16+
- [Installation](installation.md)
17+
- [Lifecycle of Mocha Framework](lifecycle.md)
18+
- [Folder Structure and Usage](folder.md)
19+
- [/runner](folder.md#runner)
20+
- [/tests/data](folder.md#testsdata)
21+
- [/tests/helper](folder.md#testshelper)
22+
- [/tests/pages](folder.md#testspages)
23+
- [/tests/scenarios](folder.md#scenarios.md)
24+
- [/tests/schema](folder.md#testsschema)
25+
- [Scenarios](scenarios.md)
26+
- [Default templates](scenarios.md#default-templates)
27+
- [Default templates with body request](scenarios.md#default-templates-with-body-request)
28+
- [Pages](pages.md)
29+
- [Default templates](pages.md#default-templates)
30+
- [Default templates with JSON body](pages.md#default-templates-with-json-body)
31+
- [Default templates with attachment body](pages.md#default-templates-with-attachment-body)
32+
- [Implementation](implementation.md)
33+
- [Best Practices](practice.md)
34+
- [Common Error](error.md)

docs/error.md

Whitespace-only changes.

docs/folder.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Folder Structure and Usage
2+
3+
## /runner
4+
Folder to store runners for each group of test files. You may create a new file to categorize wach file tests based on the needs.
5+
6+
> It is generated automatically, grouped by your request folder in Postman collection. It will be stored by the order in which the requests are in your collection.
7+
8+
For example:
9+
10+
```javascript
11+
//file /runner/user.js
12+
require('../tests/scenarios/User/POST_register.spec')()
13+
require('../tests/scenarios/User/POST_login.spec')()
14+
module.exports = () => {}
15+
```
16+
17+
The simple explanation:
18+
- This file is generated from a collection with request folder called User and 2 requests inside, which are:
19+
1. Register
20+
2. Login
21+
- This `user` runner will run your test file with `register` and `login` test name. The `register` test will be run first, then the `login` test.
22+
- `module.exports = () => {}` code section is used to export this file so you can user it in your regression test file (if needed) or other runner files.
23+
24+
## /tests/data
25+
26+
Folder to store data required for the tests. By default, it will be empty, you can easily configure it based on your needs.
27+
28+
## /tests/helper
29+
30+
Folder to store required functions or methods for global use. Default will be filled with `requestHelper.js`. You may ignore this file and create a new file for your use.
31+
32+
## /tests/pages
33+
34+
Folder to store the detail request of each API. For detailed explanation, you can go to [Pages](pages.md) section.
35+
36+
## /tests/scenarios
37+
38+
Folder to store your test files. It is linked closely with pages file, especially with the same name files. For detailed explanation, you can go to [Scenarios](scenarios.md) section.
39+
40+
## /tests/schema
41+
42+
It stores the JSON of response body (if any) that will be converted automatically into JSON-schema in `pages` file.
43+
44+
> Data required is JSON response, not JSON-schema. You don't need to manually convert the JSON response to a JSON schema, because this template will do it!
45+
46+
How to use this folder:
47+
1. Default file will be filled with key `success` and `failed`
48+
49+
You may use this key or create your own object to store the JSON value
50+
2. Prepare your JSON response that will be saved in a file along with its schema category
51+
52+
For example:
53+
```json
54+
//schema category -> success
55+
//it's json response
56+
{
57+
"token": "1234567890",
58+
"expires": "1970-01-01T00:00:00.00Z",
59+
"status": "Success",
60+
"result": "Success"
61+
}
62+
```
63+
64+
3. Copy the predefined JSON response to value of key that match the category
65+
66+
For example:
67+
```json
68+
//file_name: login.json
69+
{
70+
"success":
71+
{
72+
"token": "1234567890",
73+
"expires": "1970-01-01T00:00:00.00Z",
74+
"status": "Success",
75+
"result": "Success"
76+
},
77+
"failed":
78+
{
79+
"example": ""
80+
}
81+
}
82+
```

docs/implementation.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Implementation

docs/installation.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Installation
2+
3+
1. Create your local project directory
4+
2. [Export your Postman collection](https://learning.postman.com/docs/getting-started/importing-and-exporting-data/#exporting-collections) to JSON with Collection v2.1 format
5+
3. Install package with npm
6+
7+
```bash
8+
npm install dot-generator-mocha
9+
```
10+
1. Generate template Mocha-Chai script with command
11+
```bash
12+
npx dot-generator-mocha '<your-file-path>'
13+
```
14+
The file path can be absolute or relative, depending on where the file is stored.
15+
For example, if your collection is stored in your local project directory:
16+
```bash
17+
npx dot-generator-mocha 'My Project.postman_collection.json'
18+
```
19+
or, if you use the absolute path:
20+
```bash
21+
npx dot-generator-mocha 'C:\Users\Downloads\My Project.postman_collection.json'
22+
```
23+
1. Finish, the Mocha-CHai template scripts is successfully generated
24+
25+
How to check if it's success:
26+
27+
If you have a Postman collection named "My Project" with a request inside a folder named "User".
28+
- In the terminal, there is log with format:
29+
```bash
30+
Generate Test tests/scenarios/<folder_name_of_Postman_collection>/<request_method>_<request_name>.spec.js
31+
```
32+
For example:
33+
```bash
34+
Generate Test tests/scenario/User/POST_login.spec.js
35+
```
36+
- In the local directory:
37+
- There are `tests` folder
38+
- Inside `tests` folder, there are `pages`, `scenarios`, and `schema` folders
39+
- Inside each that folder, there are folders which name same as the folder inside the Postman Collection
40+
- Inside the folder there are files that has same name as the request Postman name
41+
42+
For example, in the folder structure visualization:
43+
```js hl_lines="1 2"
44+
├───node_modules
45+
├───runner
46+
├───template
47+
└───tests
48+
├───data
49+
├───helper
50+
├───pages
51+
│ └───User
52+
│ POST_login.js
53+
├───scenarios
54+
│ └───User
55+
│ POST_login.spec.js
56+
└───schema
57+
└───User
58+
POST_login.json
59+
```
60+
<!--Needs to be highlighted-->
61+
The folder / file name with blue font is the newly generated files.
62+
2. Furhtermore, you can manage your test script files in your project directory
63+
64+
## Important information:
65+
66+
- For repetitive usage, the package will generate files based on new requests in your Postman collection and existing files will not be replaced
67+
- The package will read the existing test file name and do a comparison with the file to be generated. If the file to be generated does not exist, then the package will generate a new file.

docs/lifecycle.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Lifecycle of Mocha Framework
2+
3+
After the template file is generated into your local directory, you can follow this lifecycle of Mocha framework:
4+
1. Complete test files to meet your scenario needs --> folder: `/tests/scenario`
5+
2. Configure request in `pages` file (if needed) --> folder: `/tests/pages`
6+
3. Complete JSON-schema file to cover all your defined scenario --> folder: `/tests/schema`
7+
4. Configure runner based on the defined test order --> folder: `runner`
8+
5. Run your test
9+
10+
You may use this command:
11+
```bash
12+
npm run test
13+
```
14+
Or you can configure new command in `package.json` file

0 commit comments

Comments
 (0)