Here you can find some of the most used scripts for Postman testing.
At least some of the most used by me :-)
(pm-objects.js)
- Global variables
- Environment variables
| // JavaScript function for converting simple XPath to CSS selector. | |
| // Ported by Dither from [cssify](https://github.com/santiycr/cssify) | |
| // Example: `cssify('//div[@id="girl"][2]/span[@class="body"]//a[contains(@class, "sexy")]//img[1]')` | |
| var sub_regexes = { | |
| "tag": "([a-zA-Z][a-zA-Z0-9]{0,10}|\\*)", | |
| "attribute": "[.a-zA-Z_:][-\\w:.]*(\\(\\))?)", | |
| "value": "\\s*[\\w/:][-/\\w\\s,:;.]*" | |
| }; |
| // Postman pre-request script for Joyent Signature Authentication | |
| // (https://github.com/joyent/node-http-signature/blob/master/http_signing.md) | |
| // | |
| // Set the following vars in your Postman environment: | |
| // apiHost | |
| // apiKey | |
| // apiSecret | |
| // | |
| // Set the following headers in Postman (copy/paste): | |
| // Authorization: Signature keyId="{{apiKey}}",algorithm="hmac-sha256",headers="host date",signature="{{signature}}" |
| // generating random data | |
| var randomData = Math.random(); | |
| // getting Auth tokens from other Auth services | |
| pm.sendRequest({ | |
| url:"https://postman-echo.com/basic-auth", | |
| method: "GET", | |
| header: { | |
| 'Authorization': 'Basic ' + btoa('postman:password') | |
| } |
In the index.js or the root file of your cypress/support folder,