Skip to content
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

Added example for running specific scenario via cli #1762

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

taylorflatt
Copy link
Contributor

Why?

On a number of occasions I have found colleagues wanting to run a specific scenario of a given test script. Early on I saw folks would just comment things out to get to the behavior they wanted or would start nesting scripts and fanning tests out.

What?

  • Added an example to the scenario section outlining how to effectively use an environment variable to run a specific scenario among a group.
  • Tested example in all versions that it works as expected.

image

Checklist

  • I have used a meaningful title for the PR.
  • I have described the changes I've made in the "What?" section above.
  • I have performed a self-review of my changes.
  • I have run the npm start command locally and verified that the changes look good.
  • I have made my changes in the docs/sources/next folder of the documentation.
  • I have reflected my changes in the docs/sources/v{most_recent_release} folder of the documentation.
  • I have reflected my changes in the relevant folders of the two previous k6 versions of the documentation (if still applicable to previous versions).

Related PR(s)/Issue(s)

@taylorflatt taylorflatt changed the title Added ex for custom cli env exec. Added example for running specific scenario via cli Oct 4, 2024
@taylorflatt
Copy link
Contributor Author

Any thoughts @heitortsergent?

@heitortsergent
Copy link
Collaborator

Hi @taylorflatt! Sorry for the delay here 🙏 .

I checked with the team and they agreed that this is a good suggestion! I just want to review some of the wording, I should be able to do that tomorrow and then we can get this merged. And thanks for opening the PR! 🙇

@taylorflatt
Copy link
Contributor Author

Excellent! No problemo.

I installed vale locally and it doesn't seem like it is picking up any blockers when I point to either the .vale configuration in k6-docs or the writers-toolkit. The error in the action for prose linting is odd and if a real error on my side a bit confusing:

  E100 [loadINI/homedir] Runtime error
  
  $HOME is not defined

Do you have any direction on this?

Copy link
Collaborator

@heitortsergent heitortsergent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@taylorflatt I left some suggestions on the wording, let me know what you think. 🙏


## Run specific scenario via environment variable

Utilizing an [environment variable](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/environment-variables/#environment-variables) and a bit of code, you can run a specific scenario via command line as opposed to running all configured scenarios. By default, [k6 runs all scenarios listed in a file](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/scenarios/#scenarios).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Utilizing an [environment variable](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/environment-variables/#environment-variables) and a bit of code, you can run a specific scenario via command line as opposed to running all configured scenarios. By default, [k6 runs all scenarios listed in a file](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/scenarios/#scenarios).
k6 runs all [scenarios](https://grafana.com/docs/k6/<K6_VERSION>/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/<K6_VERSION>/using-k6/environment-variables/#environment-variables), you can tell k6 to only run a specific scenario via the command-line.

I think if we change the order of the sentences here, it might be a little bit easier to read.


Utilizing an [environment variable](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/environment-variables/#environment-variables) and a bit of code, you can run a specific scenario via command line as opposed to running all configured scenarios. By default, [k6 runs all scenarios listed in a file](https://grafana.com/docs/k6/<K6_VERSION>/using-k6/scenarios/#scenarios).

The following provides an example of how to add the ability to run a specific scenario among multiple configured scenarios:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The following provides an example of how to add the ability to run a specific scenario among multiple configured scenarios:
The following example shows a test script that uses a `SCENARIO` environment variable, if it exists, to choose which scenario to execute:


const { SCENARIO } = __ENV;
export const options = {
// if a scenario is supplied via cli env, then run that scenario. Otherwise, run like normal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// if a scenario is supplied via cli env, then run that scenario. Otherwise, run like normal
// if a scenario is passed via a CLI env variable, then run that scenario. Otherwise, run


{{< /code >}}

Alternatively, slightly modifying this approach, it can instead be used as a skip feature. Reading from the custom environment variable allows calling a specific scenario via command line:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Alternatively, slightly modifying this approach, it can instead be used as a skip feature. Reading from the custom environment variable allows calling a specific scenario via command line:
Then from the command line, you could run the test script and only execute the `my_web_test` scenario by running:

I think we can just give an instruction for the user as to how they can execute this from the command line. If we want to mention using this as a skip feature, I think we should do it after the command line examples, or in the first section.

@heitortsergent
Copy link
Collaborator

Oh, and don't worry about the Vale check in the PR. I need to fix it so it's consistent with the writers-toolkit one we use in other repositories.

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.

2 participants