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

Web UI dropdown for custom args with choices #2372

Merged
merged 7 commits into from
Jul 18, 2023

Conversation

ktrnka
Copy link
Contributor

@ktrnka ktrnka commented Jul 17, 2023

Addresses #2371

This adds web UI support for a dropdown list in custom arguments:
Screen Shot 2023-07-16 at 7 34 44 PM

Code:

parser.add_argument("--env", choices=["dev", "staging", "prod"], default="dev")

argparse already checks those choices on command-line args, this PR just makes the web UI behave similarly.

The CSS width is different for select (340) vs input (set to 328, actual 340) to get them to be the same actual width. I'm not exactly sure why but it looks like it has to do with differences in how padding is handled between the two tags.

Testing

I ran locally with scripts/run-local-web.sh on OS X in a virtual env with Python 3.11.3

I wasn't able to get the tox tests running locally (I tried on master before making changes but it failed). Sorry about that! Hopefully the github actions aren't too burdensome.

@ktrnka ktrnka changed the title Custom arg dropdown Web UI dropdown for custom args with choices Jul 17, 2023
@cyberw
Copy link
Collaborator

cyberw commented Jul 17, 2023

Nice! Can you add a note about this feature in the documentation (.rst files), as well as a test case (add this type of extra arg to one of the existing gui args tests. I hope such a test exists :)

@ktrnka
Copy link
Contributor Author

ktrnka commented Jul 17, 2023

Nice! Can you add a note about this feature in the documentation (.rst files), as well as a test case (add this type of extra arg to one of the existing gui args tests. I hope such a test exists :)

Makes sense, yeah I'll take a shot at that when I get home later.

I'll see what I can do with the GUI tests... there's an existing custom args test but it doesn't test the GUI itself, it tests that parse_args works as expected and that Flask can receive those values. There are a couple others though that test the HTML results and I'll see if I can combine the custom arg test with one of those.

@ktrnka
Copy link
Contributor Author

ktrnka commented Jul 18, 2023

Ok I think this works! I was able to run the test locally and confirm that it failed while in development then passed when done.

I chose regex to test the generated html because it's less brittle than assertIn. I considered doing an xpath-based test which would be more robust, but would add a single-use dependency to the test suite.

@cyberw cyberw merged commit 3b73576 into locustio:master Jul 18, 2023
@cyberw
Copy link
Collaborator

cyberw commented Jul 18, 2023

👍👍

@ktrnka ktrnka deleted the custom-arg-dropdown branch July 18, 2023 21:11
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