diff --git a/docs/sources/k6/next/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/next/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/next/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/next/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.47.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.47.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.47.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.47.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.48.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.48.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.48.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.48.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.49.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.49.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.49.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.49.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.50.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.50.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.50.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.50.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.51.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.51.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.51.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.51.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.52.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.52.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.52.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.52.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.53.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.53.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.53.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.53.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}} diff --git a/docs/sources/k6/v0.54.x/using-k6/scenarios/advanced-examples.md b/docs/sources/k6/v0.54.x/using-k6/scenarios/advanced-examples.md index b237a3c38d..71e75b89e0 100644 --- a/docs/sources/k6/v0.54.x/using-k6/scenarios/advanced-examples.md +++ b/docs/sources/k6/v0.54.x/using-k6/scenarios/advanced-examples.md @@ -201,3 +201,64 @@ export function apitest() { ``` {{< /code >}} + +## Run specific scenario via environment variable + +k6 runs all [scenarios](https://grafana.com/docs/k6//using-k6/scenarios/#scenarios) listed in a test script by default. But, with some small code changes and using [environment variables](https://grafana.com/docs/k6//using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line. + +The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute: +{{< code >}} + +```javascript +import http from 'k6/http'; + +const scenarios = { + my_web_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, + my_api_test: { + executor: 'per-vu-iterations', + vus: 1, + iterations: 1, + maxDuration: '30s', + }, +}; + +const { SCENARIO } = __ENV; +export const options = { + // if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run + // using the pre-configured scenarios above. + scenarios: SCENARIO ? { [SCENARIO]: scenarios[SCENARIO] } : scenarios, + discardResponseBodies: true, + thresholds: { + http_req_duration: ['p(95)<250', 'p(99)<350'], + }, +}; + +export default function () { + const response = http.get('https://test-api.k6.io/public/crocodiles/'); +} +``` + +{{< /code >}} + +Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running: + +{{< code >}} + +```bash +$ SCENARIO=my_web_test k6 run script.js +``` + +```windows +C:\k6> set "SCENARIO=my_web_test" && k6 run script.js +``` + +```powershell +PS C:\k6> $env:SCENARIO="my_web_test"; k6 run script.js +``` + +{{< /code >}}