Skip to content

Feature/ Event Support #75

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 2, 2022

Conversation

ajanes93
Copy link
Contributor

@ajanes93 ajanes93 commented Aug 23, 2022

Feature/ Event Support

This PR adds support for collection level prerequest and test scripts.

  • Adds prequest_script and test_script config options
  • Allows a path to a script file to be defined for each option
  • If the specified files exist then the content of these is added to the relevant event property in the structure
  • Adds test for this feature

* Adds prequest_script and test_script config options
* Allows a path to a script file to be defined for each option
* If the specified files exist then they are added to the event property in the structure
* Added test for feature
* Tidy formatting of Events comment in config/api-postman.php
* Adds trailing comma in src/Commands/ExportPostmanCommand.php
* Use single quotes in tests/Feature/ExportPostmanTest.php
@andreaselia
Copy link
Owner

Hi @ajanes93, thank you for your contribution 🎉

I'll take a deeper look into this when I have some spare time to give it a proper test. Could you tell me what your use case is for such a feature, please?

@ajanes93
Copy link
Contributor Author

Thanks for looking into this @andreaselia

I want to be able to set pre-request and test scripts at a collection level so that I can do specific things before and after each request has run.

Some use cases:

  1. Set environment variables before a request is run. The values of these variables can then be used in headers, or in the request body
  2. Add tests to check response header or body values after each request has run

@andreaselia
Copy link
Owner

andreaselia commented Aug 23, 2022

Thanks for the info @ajanes93, much appreciated 👍

Cc: @tomirons

@tomirons
Copy link
Collaborator

@ajanes93 nice work on this!

My only concern with this is the support for different kinds of scripts. Is JavaScript the only one that is supported at this time? Should we validate the script before running it?

@ajanes93
Copy link
Contributor Author

Thanks @tomirons. Regarding your questions I just had a read through the Postman Docs and JavaScript is the only script format they support. See below:

Scripts in Postman

Postman has a powerful runtime based on Node.js that allows you to add dynamic behavior to requests and collections. This allows you to write API tests, build requests that can contain dynamic parameters, pass data between requests, and a lot more. You can add JavaScript code to execute during two events in the flow:

  1. Before a request is sent to the server, as a pre-request script under the Pre-request Script tab.
  2. After a response is received, as a test script under the Tests tab.

Taken from Postman Docs: Intro To Scripts

@tomirons tomirons merged commit ec35f26 into andreaselia:master Sep 2, 2022
@andreaselia
Copy link
Owner

Thanks for handling that @tomirons, and for your contribution @ajanes93 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants