#!/usr/bin/env python3 # scenarios/base.py - base scenario class # inherit from BaseScenario and override the `run()` method # to define your own load test behavior. that's it. import logging import time logger = logging.getLogger("loadtest.scenario") class BaseScenario: """ base class for all load test scenarios. subclass this and implement `run(page)` to define what each virtual user does during the load test. the `page` argument is a playwright Page object — you can navigate, click, scrape, fill forms, whatever you want. optionally override `setup(page)` and `teardown(page)` for per-iteration init and cleanup. """ name = "base" def setup(self, page): """ called BEFORE each iteration of `run()`. override this if you need to do login, seed data, etc. """ pass def run(self, page): """ the main scenario logic. this is what each virtual user will execute on every iteration. override this method in your subclass. Args: page: a playwright Page object. """ raise NotImplementedError( "you need to implement the run() method in your scenario. " "check out scenarios/example.py for reference." ) def teardown(self, page): """ called AFTER each iteration of `run()`. override this for cleanup, logging out, etc. """ pass def on_response(self, response): """ optional hook — called on every HTTP response the page receives during the scenario. useful for logging API calls, checking status codes, etc. override if you want response-level visibility. Args: response: a playwright Response object. """ pass def on_request(self, request): """ optional hook — called on every HTTP request the page makes during the scenario. useful for logging outgoing requests. override if you want request-level visibility. Args: request: a playwright Request object. """ pass