Pylenium.io
GitHub ↗️
  • Welcome to Pylenium
  • Getting Started
    • 1. Virtual Environments
    • 2. Setup pytest
    • 3. Project Structure with pytest
    • 4. Writing Tests with Pylenium
  • Guides
    • πŸ“ŠVisualize Test Results with Allure
    • πŸ“Logging
    • 🟨Run Tests in Containers
    • πŸ”€Run Tests in Parallel
    • πŸ§ͺShould / Expected Conditions
    • 🌐Script with Standalone Pylenium
  • CLI
    • πŸ’»Pylenium CLI
    • πŸ“ŠAllure CLI
  • Configuration
    • πŸ“„pylenium.json
    • πŸš—Driver
    • πŸ–₯️Viewport
  • Fixtures
    • ↗️api
    • πŸͺ“axe
    • πŸ₯Έfake
    • βœ…py
    • β˜‘οΈpyc
    • ❌pys
  • Driver Commands
    • Overview
    • πŸ—ΊοΈNavigation
      • go
      • quit
      • reload
      • visit
    • πŸ”Find Elements
      • contains
      • find
      • findx
      • get
      • getx
    • ⏱️Driver.should()
    • 🌐Browser
      • execute_script
      • execute_async_script
      • maximize_window
      • screenshot
      • scroll_to
      • title
      • url
      • window_handles
      • window_size
      • viewport
    • πŸͺCookies
      • delete_all_cookies
      • delete_cookie
      • get_all_cookies
      • get_cookie
      • set_cookie
    • πŸ”„Switch To
      • default_content
      • frame
      • frame_by_element
      • parent_frame
      • window
      • new_window
      • new_tab
    • πŸ“ŠWeb Performance
      • Performance API
      • CDP Performance
    • fake
    • wait
    • webdriver
  • Element Commands
    • πŸ”Find Elements
    • ⏱️Element.should()
    • πŸ‘Actions
      • check
      • clear
      • click
      • deselect
      • double_click
      • drag_to
      • drag_to_element
      • focus
      • hover
      • right_click
      • scroll_into_view
      • select_by_index
      • select_by_text
      • select_by_value
      • submit
      • type
      • uncheck
      • upload
    • πŸ”’Element Data
      • css_value
      • get_attribute
      • get_property
      • tag_name
      • text
      • is_checked
      • is_displayed
      • is_enabled
      • is_selected
    • πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦Family
      • children
      • parent
      • siblings
    • open_shadow_dom
    • screenshot
    • webelement
  • Elements Commands
    • ⏱️Elements.should()
    • first
    • length
    • last
    • is_empty
  • Contribute
    • Clone and Setup the Project
Powered by GitBook
On this page
  • Syntax
  • Usage
  • WebPerformance
  • Time Origin
  • Navigation Timing
  • Paint Timing
  • Resources
  • Metrics
  • Page Load Time
  • Time to First Byte
  • Time to First Contentful Paint
  • Time to Interactive (TTI)
  • Number of Requests
  • Time to DOM Content Loaded
  • Page Weight
  • Connection Time
  • Request Time
  • Fetch Time
  • Examples
  1. Driver Commands
  2. Web Performance

Performance API

Pylenium's custom performance API to capture different metrics.

PreviousWeb PerformanceNextCDP Performance

Last updated 12 months ago

Syntax

py.performance -> Performance
py.performance.get() -> WebPerformance

Usage

The Performance class is where everything lives. It provides access to the following methods:

WebPerformance

The main method used to generate a WebPerformance object from the current web page. This is really all you need from this API and will be discussed in more detail .

Calling this method too soon may yield NoneTypes because the browser hasn't generated them yet.

py.performance.get() -> WebPerformance

Time Origin

Return the timeOrigin precision value. This is the high-resolution timestamp of the start time of the performance measurement.

py.performance.get_time_origin() -> float

Navigation Timing

Return the PerformanceNavigationTiming W3 object as a Python object called NavigationTiming.

py.performance.get_navigation_timing() -> NavigationTiming

Paint Timing

Return the PerformancePaintTiming object as a Python object called PaintTiming.

py.performance.get_paint_timing() -> PaintTiming

Resources

Return a list of PerformanceResourceTiming objects as Python objects called [ResourceTiming].

py.performance.get_resources() -> List[ResourceTiming]

Metrics

All of the timing objects include A LOT of data points, but many of them may not be useful.

This is why the WebPerformance object exists! It contains calculations for metrics that have been very useful when we talk about and measure web performance. After navigating to a website and capturing these metrics with py.performance.get(), we can do whatever we want with them!

With a few lines of code, you have access to many valuable metrics:

# perf will be used in the examples below
py.visit("https://your-website.com")
perf = py.performance.get()

Page Load Time

The time it takes for the page to load as experienced by the user.

perf.page_load_time() -> float

Time to First Byte

The time it takes before the first byte of response is received from the server.

perf.time_to_first_byte() -> float

Time to First Contentful Paint

The time it takes for the majority of content to be fully rendered and consumable by the user.

perf.time_to_first_contentful_paint() -> float

Time to Interactive (TTI)

The time it takes for the layout to be stabilized and the page is responsive.

perf.time_to_interactive() -> float

Number of Requests

The number of requests sent from start of navigation until end of page load.

perf.number_of_requests() -> int

Time to DOM Content Loaded

The time it takes for the DOM content to load.

perf.time_to_dom_content_loaded() -> float

Page Weight

The amount of bytes transferred for the page to be loaded.

perf.page_weight() -> float

Connection Time

The time taken to connect to the server.

perf.connection_time() -> float

Request Time

The time taken to send a request to the server and receive the response.

perf.request_time() -> float

Fetch Time

The time to complete the document fetch (including accessing any caches, etc.).

perf.fetch_time() -> float

Examples

Store the entire WebPerformance object in a variable, then convert it to a Dictionary to log it.

perf = py.performance.get()
py.log.info(perf.dict())

Store a single data point in a variable and test against it.

tti = py.performance.get().time_to_interactive()
assert tti < BASELINE, f"TTI should be less than our baseline."

If you want to see ALL the data points, take a look at

πŸ“Š
the file in the GitHub Repo
further below in Metrics