Skip to content

Commit

Permalink
feat: added postman example with environment file
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelangarano committed Dec 6, 2024
1 parent fa8b668 commit acd4043
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 21 deletions.
10 changes: 5 additions & 5 deletions packages/postman/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Report test results generated by Postname to Currents
- Run Postman tests using `newman`

```sh
npx newman run ./tests.json -r junit --reporter-junit-export .junit/results.xml
npx newman run ./collection.json -e ./environment.json -r cli,junit --reporter-junit-export ./results.xml
```

- Convert JUnit test results to Currents-compatible format

```sh
npx currents convert \
--input-format=junit \
--input-file=.junit/results.xml \
--input-file=results.xml \
--framework=postman \
--framework-version=v11.2.0
```
Expand All @@ -31,15 +31,15 @@ npx currents upload --key=your-record-key --project-id=currents-project-id

```bash
# Run Postman tests
❯ npx newman run ./tests.json -r junit --reporter-junit-export .junit/results.xml
❯ npx newman run ./collection.json -e ./environment.json -r cli,junit --reporter-junit-export ./results.xml

# Convert Postman results to Currents results
❯ npx currents convert \
--input-format=junit \
--input-file=.junit/results.xml \
--input-file=results.xml \
--framework=postman \
--framework-version=v11.2.0
[currents] Convertion files: .junit/results.xml
[currents] Convertion files: results.xml
[currents] Conversion completed, report saved to: /Users/agoldis/currents-junit-xml-example/packages/postman/.currents/2024-11-27T21-14-06-189Z-24038566-8abf-42b5-910d-2af57dd4d3c6

# Report the results to Currents
Expand Down
68 changes: 52 additions & 16 deletions packages/postman/tests.json → packages/postman/collection.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
"listen": "test",
"script": {
"exec": [
"let prevCiBuildId = pm.environment.get(\"prevCiBuildId\");",
"console.log(`Using prevCiBuildId: ${prevCiBuildId}`);",
"",
"pm.test(\"Response status code is 200\", function () {",
" pm.response.to.have.status(200);",
"});",
Expand Down Expand Up @@ -45,17 +48,14 @@
"header": [
{
"key": "Authorization",
"value": "Bearer your-api-key",
"value": "Bearer {{API_TOKEN}}",
"type": "text"
}
],
"url": {
"raw": "https://api.currents.dev/v1/runs/previous?projectId=your-project-id&ciBuildId=your-ci-build-id&pwLastRun=true",
"protocol": "https",
"raw": "{{API_URL}}/v1/runs/previous?projectId=LrO7nE&ciBuildId={{prevCiBuildId}}&pwLastRun=true",
"host": [
"api",
"currents",
"dev"
"{{API_URL}}"
],
"path": [
"v1",
Expand All @@ -65,11 +65,11 @@
"query": [
{
"key": "projectId",
"value": "your-project-id"
"value": "LrO7nE"
},
{
"key": "ciBuildId",
"value": "your-ci-build-id"
"value": "{{prevCiBuildId}}"
},
{
"key": "pwLastRun",
Expand Down Expand Up @@ -107,7 +107,12 @@
" pm.expect(responseData).to.be.an('object');",
" pm.expect(responseData.status).to.be.a('string');",
" pm.expect(responseData.data).to.be.an('object');",
"});"
"});",
"",
"",
"let responseData = pm.response.json();",
"console.log(`Saving prevCiBuildId: ${responseData.data.meta.ciBuildId}`);",
"pm.environment.set(\"prevCiBuildId\", responseData.data.meta.ciBuildId);"
],
"type": "text/javascript",
"packages": {}
Expand All @@ -119,26 +124,57 @@
"header": [
{
"key": "Authorization",
"value": "Bearer your-api-key",
"value": "Bearer {{API_TOKEN}}",
"type": "text"
}
],
"url": {
"raw": "https://api.currents.dev/v1/runs/your-run-id",
"protocol": "https",
"raw": "{{API_URL}}/v1/runs/f6fe40a7856d160d",
"host": [
"api",
"currents",
"dev"
"{{API_URL}}"
],
"path": [
"v1",
"runs",
"your-run-id"
"f6fe40a7856d160d"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"packages": {},
"exec": [
""
]
}
}
],
"variable": [
{
"key": "API_TOKEN",
"value": "dXGDik1SmFlDfOCyDpmhS8dNzmMrG27P0noe7qbGNvnMQQmPwWcN51dFGu1SouRP",
"type": "string"
},
{
"key": "API_URL",
"value": "https://api.currents.dev",
"type": "string"
}
]
}
15 changes: 15 additions & 0 deletions packages/postman/environment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"id": "a452db80-b375-460d-9ad3-99c61c2788b2",
"name": "Testing",
"values": [
{
"key": "prevCiBuildId",
"value": "reporter-PipelineTest-3-3",
"type": "default",
"enabled": true
}
],
"_postman_variable_scope": "environment",
"_postman_exported_at": "2024-12-06T05:22:31.134Z",
"_postman_exported_using": "Postman/11.21.0"
}
26 changes: 26 additions & 0 deletions packages/postman/results.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="Tests" tests="2" time="0.768">
<testsuite name="Currents API" id="92fa1e9b-1d37-4ff7-9247-a0e547952a0e" timestamp="2024-12-06T05:29:43.578Z" tests="4" failures="1" errors="0" time="0.631">
<testcase name="Response status code is 200" time="0.631" classname="CurrentsApi"/>
<testcase name="Response time is less than 200ms" time="0.631" classname="CurrentsApi">
<failure type="AssertionFailure" message="expected 631 to be below 200">
<![CDATA[Failed 1 times.]]>
<![CDATA[Collection JSON ID: e1e87782-7e0d-48dc-a937-3f6e1b931edc.]]>
<![CDATA[Collection name: Tests.]]>
<![CDATA[Request name: Currents API.]]>
<![CDATA[Test description: Response time is less than 200ms.]]>
<![CDATA[Error message: expected 631 to be below 200.]]>
<![CDATA[Stacktrace: AssertionError: expected 631 to be below 200
at Object.eval sandbox-script.js:2:1).]]>
</failure>
</testcase>
<testcase name="Status code is 200" time="0.631" classname="CurrentsApi"/>
<testcase name="Validate the response schema for required fields and data types" time="0.631" classname="CurrentsApi"/>
</testsuite>
<testsuite name="Get Run" id="75119228-2d2d-4e59-b426-60a002b8cdce" timestamp="2024-12-06T05:29:43.578Z" tests="4" failures="0" errors="0" time="0.137">
<testcase name="Response status code is 200" time="0.137" classname="GetRun"/>
<testcase name="Response time is less than 200ms" time="0.137" classname="GetRun"/>
<testcase name="Status code is 200" time="0.137" classname="GetRun"/>
<testcase name="Validate the response schema for required fields and data types" time="0.137" classname="GetRun"/>
</testsuite>
</testsuites>

0 comments on commit acd4043

Please sign in to comment.