lib/playwright_api/tracing.rb



module Playwright
  # API for collecting and saving Playwright traces. Playwright traces can be opened in [Trace Viewer](./trace-viewer.md)
  # after Playwright script runs.
  #
  # Start recording a trace before performing actions. At the end, stop tracing and save it to a file.
  #
  # ```python sync
  # browser = chromium.launch()
  # context = browser.new_context()
  # context.tracing.start(screenshots=True, snapshots=True)
  # page = context.new_page()
  # page.goto("https://playwright.dev")
  # context.tracing.stop(path = "trace.zip")
  # ```
  class Tracing < PlaywrightApi

    # Start tracing.
    #
    # ```python sync
    # context.tracing.start(name="trace", screenshots=True, snapshots=True)
    # page = context.new_page()
    # page.goto("https://playwright.dev")
    # context.tracing.stop(path = "trace.zip")
    # ```
    def start(name: nil, screenshots: nil, snapshots: nil, title: nil)
      wrap_impl(@impl.start(name: unwrap_impl(name), screenshots: unwrap_impl(screenshots), snapshots: unwrap_impl(snapshots), title: unwrap_impl(title)))
    end

    # Start a new trace chunk. If you'd like to record multiple traces on the same `BrowserContext`, use
    # [`method: Tracing.start`] once, and then create multiple trace chunks with [`method: Tracing.startChunk`] and
    # [`method: Tracing.stopChunk`].
    #
    # ```python sync
    # context.tracing.start(name="trace", screenshots=True, snapshots=True)
    # page = context.new_page()
    # page.goto("https://playwright.dev")
    #
    # context.tracing.start_chunk()
    # page.click("text=Get Started")
    # # Everything between start_chunk and stop_chunk will be recorded in the trace.
    # context.tracing.stop_chunk(path = "trace1.zip")
    #
    # context.tracing.start_chunk()
    # page.goto("http://example.com")
    # # Save a second trace file with different actions.
    # context.tracing.stop_chunk(path = "trace2.zip")
    # ```
    def start_chunk(title: nil)
      wrap_impl(@impl.start_chunk(title: unwrap_impl(title)))
    end

    # Stop tracing.
    def stop(path: nil)
      wrap_impl(@impl.stop(path: unwrap_impl(path)))
    end

    # Stop the trace chunk. See [`method: Tracing.startChunk`] for more details about multiple trace chunks.
    def stop_chunk(path: nil)
      wrap_impl(@impl.stop_chunk(path: unwrap_impl(path)))
    end
  end
end