pythonperformance-testingplaywright-pythonchrome-devtools-protocol

How can I measure Total Blocking Time using new_cdp_session in Playwright tests?


I'm trying to measure total blocking time with in playwright tests using new_cdp_session. There are a lot of different metrics in it, but there is no TBT (Total Blocking Time), LCP (Largest Contentful Paint) or CLS (Cumulative Layout Shift). My code:

from playwright.sync_api import Page


def test_get_metrics(page: Page):
    client = page.context.new_cdp_session(page)
    client.send('Performance.enable')
    page.goto('https://www.google.com')
    metrics = client.send('Performance.getMetrics')
    client.send('Performance.disable')
    print(metrics)

Maybe someone know how to get f.e. TBT with new_cdp_session or suggest any other options to reach it?


Solution

  • Actually there are no core web vitals in CDP performance metrics, but I've managed to integrate light-house-cli with playwright to measure them