Skip to content

Commit e099b18

Browse files
AntyaDevOleksPal
andauthored
Add custom headers for the PostmanScenario example and fix templates for scenarios generation (#8)
Co-authored-by: User <oleksandr.palamarchuk1310@gmail.com>
1 parent 05b9d86 commit e099b18

File tree

8 files changed

+295
-52
lines changed

8 files changed

+295
-52
lines changed

examples/Demo/PostmanExample_15steps_v2.0.json

Lines changed: 180 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,18 @@
1010
"name": "LIST USERS",
1111
"request": {
1212
"method": "GET",
13-
"header": [],
13+
"header": [
14+
{
15+
"key": "Key1",
16+
"value": "Value1",
17+
"type": "text"
18+
},
19+
{
20+
"key": "Key2",
21+
"value": "Value2",
22+
"type": "text"
23+
}
24+
],
1425
"url": {
1526
"raw": "https://reqres.in/api/users?page=2",
1627
"protocol": "https",
@@ -39,7 +50,18 @@
3950
"type": "noauth"
4051
},
4152
"method": "GET",
42-
"header": [],
53+
"header": [
54+
{
55+
"key": "Key1",
56+
"value": "Value1",
57+
"type": "text"
58+
},
59+
{
60+
"key": "Key2",
61+
"value": "Value2",
62+
"type": "text"
63+
}
64+
],
4365
"url": "https://reqres.in/api/users/2"
4466
},
4567
"response": []
@@ -51,7 +73,18 @@
5173
"type": "noauth"
5274
},
5375
"method": "GET",
54-
"header": [],
76+
"header": [
77+
{
78+
"key": "Key1",
79+
"value": "Value1",
80+
"type": "text"
81+
},
82+
{
83+
"key": "Key2",
84+
"value": "Value2",
85+
"type": "text"
86+
}
87+
],
5588
"url": "https://reqres.in/api/users/23"
5689
},
5790
"response": []
@@ -63,7 +96,18 @@
6396
"type": "noauth"
6497
},
6598
"method": "GET",
66-
"header": [],
99+
"header": [
100+
{
101+
"key": "Key1",
102+
"value": "Value1",
103+
"type": "text"
104+
},
105+
{
106+
"key": "Key2",
107+
"value": "Value2",
108+
"type": "text"
109+
}
110+
],
67111
"url": "https://reqres.in/api/unknown"
68112
},
69113
"response": []
@@ -75,7 +119,18 @@
75119
"type": "noauth"
76120
},
77121
"method": "GET",
78-
"header": [],
122+
"header": [
123+
{
124+
"key": "Key1",
125+
"value": "Value1",
126+
"type": "text"
127+
},
128+
{
129+
"key": "Key2",
130+
"value": "Value2",
131+
"type": "text"
132+
}
133+
],
79134
"url": "https://reqres.in/api/unknown/2"
80135
},
81136
"response": []
@@ -87,7 +142,18 @@
87142
"type": "noauth"
88143
},
89144
"method": "GET",
90-
"header": [],
145+
"header": [
146+
{
147+
"key": "Key1",
148+
"value": "Value1",
149+
"type": "text"
150+
},
151+
{
152+
"key": "Key2",
153+
"value": "Value2",
154+
"type": "text"
155+
}
156+
],
91157
"url": "https://reqres.in/api/unknown/23"
92158
},
93159
"response": []
@@ -99,7 +165,18 @@
99165
"type": "noauth"
100166
},
101167
"method": "POST",
102-
"header": [],
168+
"header": [
169+
{
170+
"key": "Key1",
171+
"value": "Value1",
172+
"type": "text"
173+
},
174+
{
175+
"key": "Key2",
176+
"value": "Value2",
177+
"type": "text"
178+
}
179+
],
103180
"body": {
104181
"mode": "raw",
105182
"raw": "{\r\n \"name\": \"morpheus\",\r\n \"job\": \"leader\"\r\n}",
@@ -120,7 +197,18 @@
120197
"type": "noauth"
121198
},
122199
"method": "PUT",
123-
"header": [],
200+
"header": [
201+
{
202+
"key": "Key1",
203+
"value": "Value1",
204+
"type": "text"
205+
},
206+
{
207+
"key": "Key2",
208+
"value": "Value2",
209+
"type": "text"
210+
}
211+
],
124212
"body": {
125213
"mode": "raw",
126214
"raw": "{\r\n \"name\": \"morpheus\",\r\n \"job\": \"zion resident\"\r\n}",
@@ -141,7 +229,18 @@
141229
"type": "noauth"
142230
},
143231
"method": "PATCH",
144-
"header": [],
232+
"header": [
233+
{
234+
"key": "Key1",
235+
"value": "Value1",
236+
"type": "text"
237+
},
238+
{
239+
"key": "Key2",
240+
"value": "Value2",
241+
"type": "text"
242+
}
243+
],
145244
"body": {
146245
"mode": "raw",
147246
"raw": "{\r\n \"name\": \"morpheus\",\r\n \"job\": \"zion resident\"\r\n}",
@@ -162,7 +261,18 @@
162261
"type": "noauth"
163262
},
164263
"method": "DELETE",
165-
"header": [],
264+
"header": [
265+
{
266+
"key": "Key1",
267+
"value": "Value1",
268+
"type": "text"
269+
},
270+
{
271+
"key": "Key2",
272+
"value": "Value2",
273+
"type": "text"
274+
}
275+
],
166276
"url": "https://reqres.in/api/users/2"
167277
},
168278
"response": []
@@ -174,7 +284,18 @@
174284
"type": "noauth"
175285
},
176286
"method": "POST",
177-
"header": [],
287+
"header": [
288+
{
289+
"key": "Key1",
290+
"value": "Value1",
291+
"type": "text"
292+
},
293+
{
294+
"key": "Key2",
295+
"value": "Value2",
296+
"type": "text"
297+
}
298+
],
178299
"body": {
179300
"mode": "raw",
180301
"raw": "{\r\n \"email\": \"eve.holt@reqres.in\",\r\n \"password\": \"pistol\"\r\n}",
@@ -195,7 +316,18 @@
195316
"type": "noauth"
196317
},
197318
"method": "POST",
198-
"header": [],
319+
"header": [
320+
{
321+
"key": "Key1",
322+
"value": "Value1",
323+
"type": "text"
324+
},
325+
{
326+
"key": "Key2",
327+
"value": "Value2",
328+
"type": "text"
329+
}
330+
],
199331
"body": {
200332
"mode": "raw",
201333
"raw": "{\r\n \"email\": \"sydney@fife\"\r\n}",
@@ -216,7 +348,18 @@
216348
"type": "noauth"
217349
},
218350
"method": "POST",
219-
"header": [],
351+
"header": [
352+
{
353+
"key": "Key1",
354+
"value": "Value1",
355+
"type": "text"
356+
},
357+
{
358+
"key": "Key2",
359+
"value": "Value2",
360+
"type": "text"
361+
}
362+
],
220363
"body": {
221364
"mode": "raw",
222365
"raw": "{\r\n \"email\": \"eve.holt@reqres.in\",\r\n \"password\": \"cityslicka\"\r\n}",
@@ -237,7 +380,18 @@
237380
"type": "noauth"
238381
},
239382
"method": "POST",
240-
"header": [],
383+
"header": [
384+
{
385+
"key": "Key1",
386+
"value": "Value1",
387+
"type": "text"
388+
},
389+
{
390+
"key": "Key2",
391+
"value": "Value2",
392+
"type": "text"
393+
}
394+
],
241395
"body": {
242396
"mode": "raw",
243397
"raw": "{\r\n \"email\": \"peter@klaven\"\r\n}",
@@ -258,7 +412,18 @@
258412
"type": "noauth"
259413
},
260414
"method": "GET",
261-
"header": [],
415+
"header": [
416+
{
417+
"key": "Key1",
418+
"value": "Value1",
419+
"type": "text"
420+
},
421+
{
422+
"key": "Key2",
423+
"value": "Value2",
424+
"type": "text"
425+
}
426+
],
262427
"url": {
263428
"raw": "https://reqres.in/api/users?delay=3",
264429
"protocol": "https",

src/NBomber.Converter/HAR/HarScenarioTemplate.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class HelloWorldExample
1515
var step{{ forloop.index }} = await Step.Run("step {{ forloop.index }} - {{ entry.Request.ActionName }}", context, async () =>
1616
{
1717
var request = Http.CreateRequest("{{ entry.Request.Method }}", "{{ entry.Request.Url }}")
18-
{% for header in entry.Request.Headers -%}
18+
{%- for header in entry.Request.Headers -%}
1919
{%- unless header.Name contains ":" or header.Name == "content-length" %}
2020
.WithHeader("{{ header.Name }}", "{{ header.Value | replace: '\"', '\\\"' }}"){% if forloop.last -%};
2121
{% endif -%}

src/NBomber.Converter/NBomber.Converter.sln

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ VisualStudioVersion = 17.5.2.0
44
MinimumVisualStudioVersion = 10.0.40219.1
55
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NBomber.Converter", "NBomber.Converter.csproj", "{1F7F69E0-CA18-9649-3E70-03512122665B}"
66
EndProject
7+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NBomber.Converter.Tests", "..\..\tests\NBomber.Converter.Tests\NBomber.Converter.Tests.csproj", "{0409E802-396C-6A4B-983A-DD080AACF4F0}"
8+
EndProject
9+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NBomber.Converter.Tool", "..\NBomber.Converter.Tool\NBomber.Converter.Tool.csproj", "{3E8D4BB2-1659-B664-AEB4-05C96EFFC3DE}"
10+
EndProject
11+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "..\..\examples\Demo\Demo.csproj", "{DA223B8A-C087-E6A4-8206-61E06BA41B45}"
12+
EndProject
713
Global
814
GlobalSection(SolutionConfigurationPlatforms) = preSolution
915
Debug|Any CPU = Debug|Any CPU
@@ -14,6 +20,18 @@ Global
1420
{1F7F69E0-CA18-9649-3E70-03512122665B}.Debug|Any CPU.Build.0 = Debug|Any CPU
1521
{1F7F69E0-CA18-9649-3E70-03512122665B}.Release|Any CPU.ActiveCfg = Release|Any CPU
1622
{1F7F69E0-CA18-9649-3E70-03512122665B}.Release|Any CPU.Build.0 = Release|Any CPU
23+
{0409E802-396C-6A4B-983A-DD080AACF4F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
24+
{0409E802-396C-6A4B-983A-DD080AACF4F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
25+
{0409E802-396C-6A4B-983A-DD080AACF4F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
26+
{0409E802-396C-6A4B-983A-DD080AACF4F0}.Release|Any CPU.Build.0 = Release|Any CPU
27+
{3E8D4BB2-1659-B664-AEB4-05C96EFFC3DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
28+
{3E8D4BB2-1659-B664-AEB4-05C96EFFC3DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
29+
{3E8D4BB2-1659-B664-AEB4-05C96EFFC3DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
30+
{3E8D4BB2-1659-B664-AEB4-05C96EFFC3DE}.Release|Any CPU.Build.0 = Release|Any CPU
31+
{DA223B8A-C087-E6A4-8206-61E06BA41B45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
32+
{DA223B8A-C087-E6A4-8206-61E06BA41B45}.Debug|Any CPU.Build.0 = Debug|Any CPU
33+
{DA223B8A-C087-E6A4-8206-61E06BA41B45}.Release|Any CPU.ActiveCfg = Release|Any CPU
34+
{DA223B8A-C087-E6A4-8206-61E06BA41B45}.Release|Any CPU.Build.0 = Release|Any CPU
1735
EndGlobalSection
1836
GlobalSection(SolutionProperties) = preSolution
1937
HideSolutionNode = FALSE

src/NBomber.Converter/Postman/Contracts/PostmanCollection.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class Item
3333
public Request Request { get; set; }
3434

3535
[JsonPropertyName("response")]
36-
public List<Response> Responses { get; set; } // Response object
36+
public List<Response> Responses { get; set; }
3737
}
3838

3939
public class Request
@@ -42,7 +42,7 @@ public class Request
4242
public string Method { get; set; }
4343

4444
[JsonPropertyName("header")]
45-
public List<(string, string)> Headers { get; set; }
45+
public List<Header> Headers { get; set; }
4646

4747
[JsonPropertyName("url")]
4848
public JsonNode Url { get; set; }
@@ -51,6 +51,18 @@ public class Request
5151
public Body Body { get; set; }
5252
}
5353

54+
public class Header
55+
{
56+
[JsonPropertyName("key")]
57+
public string Key { get; set; }
58+
59+
[JsonPropertyName("value")]
60+
public string Value { get; set; }
61+
62+
[JsonPropertyName("type")]
63+
public string Type { get; set; }
64+
}
65+
5466
public class Url
5567
{
5668
[JsonPropertyName("raw")]

src/NBomber.Converter/Postman/PostmanScenarioTemplate.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ public class HelloWorldPostmanExample
1717
var request = Http.CreateRequest("{{ item.Request.Method }}", "{{ item.Request.PlainUrl }}")
1818
{%- if item.Request.Headers.size == 0 -%};{%- endif -%}
1919
{% for header in item.Request.Headers -%}
20-
{% unless header.Key contains ":" or header.Key == "content-length" -%}
21-
.WithHeader("{{ header.Item1 }}", "{{ header.Item2 | replace: '\"', '\\\"' }}")
22-
{% if forloop.last -%}
23-
.WithHeader("{{ header.Item1 }}", "{{ header.Item2 | replace: '\"', '\\\"' }}");
20+
{%- unless header.Key contains ":" or header.Key == "content-length" %}
21+
.WithHeader("{{ header.Key }}", "{{ header.Value | replace: '\"', '\\\"' }}"){% if forloop.last -%};
2422
{% endif -%}
2523
{% endunless -%}
2624
{% else -%}

0 commit comments

Comments
 (0)