Skip to content

Commit c1f35e6

Browse files
committed
update readme
1 parent fbfa0cf commit c1f35e6

File tree

1 file changed

+79
-26
lines changed

1 file changed

+79
-26
lines changed

README.md

Lines changed: 79 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,6 @@
33

44
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.
55

6-
## Table of Contents
7-
- [Objectives](#objectives)
8-
- [Prerequisite](#prerequisite)
9-
- [Installation](#installation)
10-
- [Important information](#important-information)
11-
- [Lifecycle of Mocha Framework](#lifecycle-of-mocha-framework)
12-
- [Folder Structure and Usage](#folder-structure-and-usage)
13-
- [/runner](#runner)
14-
- [/tests/data](#testsdata)
15-
- [/tests/helper](#testshelper)
16-
- [/tests/pages](#testspages)
17-
- [/tests/scenarios](#testsscenarios)
18-
- [/tests/schema](#testsschema)
19-
- [Scenarios](#scenarios)
20-
- [Default templates](#default-templates)
21-
- [Default templates with body request](#default-templates-with-body-request)
22-
- [Pages](#pages)
23-
- [Default templates](#default-templates-1)
24-
- [Default templates with JSON body](#default-templates-with-json-body)
25-
- [Default templates with attachment body](#default-templates-with-attachment-body)
26-
- [Implementation](#implementation)
27-
- [Best Practices](#best-practices)
28-
- [Common Error](#common-error)
29-
306
## Objectives
317

328
1. Generate Postman collection with JSON format into Mocha-Chai template scripts
@@ -35,7 +11,29 @@ This project has created to relieve work load as SDET or Automation Test Enginee
3511
4. Have default verification for status code and json-schema
3612
5. Create scripts that easy to maintain
3713

38-
14+
## Table of Contents
15+
- [Prerequisite](#prerequisite)
16+
- [Installation](#installation)
17+
- [Important information](#important-information)
18+
- [Lifecycle of Mocha Framework](#lifecycle-of-mocha-framework)
19+
- [Folder Structure and Usage](#folder-structure-and-usage)
20+
- [/runner](#runner)
21+
- [/tests/data](#testsdata)
22+
- [/tests/helper](#testshelper)
23+
- [/tests/pages](#testspages)
24+
- [/tests/scenarios](#testsscenarios)
25+
- [/tests/schema](#testsschema)
26+
- [Scenarios](#scenarios)
27+
- [Default templates](#default-templates)
28+
- [Default templates with body request](#default-templates-with-body-request)
29+
- [Pages](#pages)
30+
- [Default templates](#default-templates-1)
31+
- [Default templates with JSON body](#default-templates-with-json-body)
32+
- [Default templates with attachment body](#default-templates-with-attachment-body)
33+
- [If You Need Other Arguments](#if-you-need-other-arguments)
34+
- [Implementation](#implementation)
35+
- [Best Practices](#best-practices)
36+
- [Common Error](#common-error)
3937

4038
## Prerequisite
4139

@@ -608,7 +606,7 @@ module.exports = request
608606
609607
From above, the request has body with `username` and `password` keys. The default value of each keys is `example`.
610608
611-
> You can define the constant or static value of key body request in this part of code and make changes to test-related data in your tests file.
609+
> You can define the constant or static value of key body request in this part of code and make changes to test-related data in your scenarios file.
612610
613611
- `new requestHelper().objectMapping(obj, args)` section
614612
@@ -759,6 +757,61 @@ For detailed explanation:
759757
You can define the static of default value of request key in this variable. Also, you can use the relative or absolute path for the value, but it is recommended to use a relative path based on your project root.
760758
- `objectMapping()` method of `requestHelper()` class will map the key-value defined in `objAtt` variable to the `args` variable of the arguments in `attach()` method.
761759
760+
### If You Need Other Arguments
761+
762+
In case you need to pass data (except the `datas.ddt` and `(err, ress)` function) from scenario file to page file, you can use the [concept of rest argument](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters) in method/function, which are location sensitive based on the value passed from method usage and method definition.
763+
764+
For example, you need to pass below data from scenario file to your request builder in page file:
765+
- token
766+
- id
767+
- query
768+
- path URL
769+
- etc, something similar
770+
771+
you can use this configuration steps:
772+
1. Define the value of argument in `request()` method in scenario file.
773+
774+
For example the token and id value:
775+
```js
776+
new Request().request(token_value, id_value,
777+
(err, res) => {});
778+
```
779+
780+
1. Map the argument passed in `request()` method from scenario file to your request builder in page file.
781+
782+
For above case, you want to map token and id value in your request API. The `request()` method in page file will look like this:
783+
784+
```js
785+
constructor() {
786+
this.api = process.env.APP_URL;
787+
this.path = "/Account/v1/User/";
788+
}
789+
790+
request(...args) {
791+
const response = this.api.get(this.path + args[1])
792+
.set("Authorization", "Bearer " + args[0])
793+
.end(new requestHelper().getExpectFunc(args))
794+
795+
return response
796+
}
797+
```
798+
799+
The simple explanation:
800+
- arguments in first index (`args[0]`) is used to store the token value in scenario file, so you map it to the token value in your API request.
801+
802+
Code section:
803+
```js
804+
"Bearer " + args[0]
805+
```
806+
- arguments in second index (`args[1]`) is used to store the id value for URL path in scenario file, so you map it to the id value in your API request.
807+
808+
Code section:
809+
```js
810+
this.path + args[1]
811+
```
812+
813+
> You can configure the scenario-related data needs in your scenario files and configure the data mapping in your page file.
814+
762815
## Implementation
763816
764817
## Best Practices

0 commit comments

Comments
 (0)