diff options
| author | kj_sh604 | 2026-02-11 11:57:38 -0500 |
|---|---|---|
| committer | kj_sh604 | 2026-02-11 11:57:38 -0500 |
| commit | d060ff5ca58e87e6dd1c6d93b97adbfd45f57f9b (patch) | |
| tree | aded1017253e8aa5b5c2996caf30630f8ed89c1f /src/scenarios/example.py | |
| parent | aa845e20842ecf93f7e69b03097dbc6508a70fc8 (diff) | |
Diffstat (limited to 'src/scenarios/example.py')
| -rw-r--r-- | src/scenarios/example.py | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/scenarios/example.py b/src/scenarios/example.py new file mode 100644 index 0000000..fd555ff --- /dev/null +++ b/src/scenarios/example.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 + +# this is an example that shows how to write your own +# scenario. copy this file, rename it, and modify the run() +# method to do whatever you want. + +# the run() method receives a playwright Page object. +# you can navigate, click, scrape text, fill forms, +# take screenshots, assert content — the full playwright +# API is at your disposal. + +import logging + +from scenarios.base import BaseScenario + +logger = logging.getLogger("loadtest.scenario.example") + + +class ExampleScenario(BaseScenario): + """ + example scenario that demonstrates: + - navigating to the target URL + - scraping page content + - clicking links / navigating around + - filling out a form + - grabbing data from the page + + modify this to fit your actual load test needs. + """ + + name = "example" + + def setup(self, page): + logger.debug("[setup] preparing for iteration...") + + def run(self, page): + """ + this is where the action happens. each virtual user + will execute this method once per iteration. + """ + + logger.info("[run] navigating to base URL...") + page.goto("/") + page.wait_for_load_state("networkidle") + + title = page.title() + logger.info(f"[run] page title: {title}") + + # python playwright code goes here - click links, fill forms, scrape content, etc. + + logger.info("[run] scenario iteration complete.") + + def teardown(self, page): + logger.debug("[teardown] cleaning up after iteration...") + + def on_response(self, response): + """ + log every HTTP response for visibility. + you can filter by URL pattern, status code, etc. + """ + status = response.status + url = response.url + if status >= 400: + logger.warning(f"[response] {status} <- {url}") + else: + logger.debug(f"[response] {status} <- {url}") + + def on_request(self, request): + """ + log outgoing requests. + """ + logger.debug(f"[request] {request.method} -> {request.url}")
\ No newline at end of file |
