From 7e094b234f547489a61cd74e01c1bd04d39a414c Mon Sep 17 00:00:00 2001 From: George He Date: Tue, 22 Oct 2024 17:54:06 +0800 Subject: [PATCH] fix(runner): update and add examples (#238) * doc: example csv use for collection runner * fix: incorrect after-response script example * fix: add an example for iterationData --------- Co-authored-by: Filipe Freire --- docs/insomnia/after-response-script.md | 2 +- docs/insomnia/collection-runner.md | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/insomnia/after-response-script.md b/docs/insomnia/after-response-script.md index 35c688c..708b3c0 100644 --- a/docs/insomnia/after-response-script.md +++ b/docs/insomnia/after-response-script.md @@ -19,7 +19,7 @@ For tests and assertions you can use `insomnia.test` and `insomnia.expect` funct ```js insomnia.test('Check if status is 200', () => { - insomnia.expect(insomnia.response.status).to.eql(200); + insomnia.expect(insomnia.response.code).to.eql(200); }); ``` diff --git a/docs/insomnia/collection-runner.md b/docs/insomnia/collection-runner.md index 936b15b..db36f91 100644 --- a/docs/insomnia/collection-runner.md +++ b/docs/insomnia/collection-runner.md @@ -45,6 +45,7 @@ And when running the collection runner they will be replaced in place. ![example collection run variables results](/assets/images/example-result-collection-runner-variables.png) {:.alert .alert-primary} + **Note**: It is also allowed to reference values from CSV or JSON in the same manner as referencing [environment variables](/insomnia/environment-variables/). And variables from data files will take precedence over [environment variables](/insomnia/environment-variables/). @@ -58,6 +59,19 @@ JSON also works with runner, this is an example: ] ``` +#### Accessing CSV or JSON data from Scripts + +It is allowed to access values from custom CSV or JSON file. For each row, you can access values through `insomnia.iterationData`. + +For example, if the above JSON file has been uploaded, you can access `id` and `deviceName` in this way: + +```javascript +const id = insomnia.iterationData.get('id'); +const deviceName = insomnia.iterationData.get('deviceName'); +``` + +And most of methods of `insomnia.environment` also work for `insomnia.iterationData`. + ## Test Results in the Collection Tab With the Collection Runner, we have also introduced a new **Test Results** section.