Skip to content

Commit

Permalink
Added playwright user to generate browser traffic
Browse files Browse the repository at this point in the history
  • Loading branch information
jordibisbal8 committed Nov 17, 2023
1 parent eaa699a commit 7e78c5b
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/loadgenerator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@


import json
import os
import random
import uuid
from locust import HttpUser, task, between
from locust_plugins.users.playwright import PlaywrightUser, pw, PageWithRetry, event

from opentelemetry import context, baggage, trace
from opentelemetry.metrics import set_meter_provider
Expand Down Expand Up @@ -129,3 +131,33 @@ def on_start(self):
ctx = baggage.set_baggage("synthetic_request", "true")
context.attach(ctx)
self.index()


browser_traffic_enabled = os.environ.get('LOCUST_BROWSER_TRAFFIC_ENABLED', False)

if browser_traffic_enabled:
class WebsiteBrowserUser(PlaywrightUser):
headless = True # to use a headless browser, without a GUI
multiplier = 1 # run concurrent playwright sessions/browsers for each Locust user
wait_time = between(1, 10)

@task
@pw
async def open_cart_browser_page(self, page: PageWithRetry):
try:
async with event(self, "Load up Cart Page"):
await page.goto("/cart")
except:
pass

@task
@pw
async def open_home_browser_page(self, page: PageWithRetry):
try:
async with event(self, "Load up Astronomy Shop home page"):
await page.goto("/")
async with event(self, "Click on a button"):
async with page.expect_navigation(wait_until="domcontentloaded"):
await page.click('button:has-text("Go Shopping")')
except:
pass

0 comments on commit 7e78c5b

Please sign in to comment.