1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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}")
|