Class: Playwright::Tracing

Inherits:
PlaywrightApi show all
Defined in:
lib/playwright_api/tracing.rb

Overview

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(“playwright.dev”) context.tracing.stop(path = “trace.zip”) “`

Instance Method Summary collapse

Methods inherited from PlaywrightApi

#initialize, unwrap, wrap

Constructor Details

This class inherits a constructor from Playwright::PlaywrightApi

Instance Method Details

#off(event, callback) ⇒ Object

– inherited from EventEmitter –



69
70
71
# File 'lib/playwright_api/tracing.rb', line 69

def off(event, callback)
  event_emitter_proxy.off(event, callback)
end

#on(event, callback) ⇒ Object

– inherited from EventEmitter –



81
82
83
# File 'lib/playwright_api/tracing.rb', line 81

def on(event, callback)
  event_emitter_proxy.on(event, callback)
end

#once(event, callback) ⇒ Object

– inherited from EventEmitter –



75
76
77
# File 'lib/playwright_api/tracing.rb', line 75

def once(event, callback)
  event_emitter_proxy.once(event, callback)
end

#start(name: nil, screenshots: nil, snapshots: nil, sources: nil, title: nil) ⇒ Object

Start tracing.

“‘python sync context.tracing.start(name=“trace”, screenshots=True, snapshots=True) page = context.new_page() page.goto(“playwright.dev”) context.tracing.stop(path = “trace.zip”) “`



25
26
27
28
29
30
31
32
# File 'lib/playwright_api/tracing.rb', line 25

def start(
      name: nil,
      screenshots: nil,
      snapshots: nil,
      sources: nil,
      title: nil)
  wrap_impl(@impl.start(name: unwrap_impl(name), screenshots: unwrap_impl(screenshots), snapshots: unwrap_impl(snapshots), sources: unwrap_impl(sources), title: unwrap_impl(title)))
end

#start_chunk(title: nil) ⇒ Object

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(“playwright.dev”)

context.tracing.start_chunk() page.locator(“text=Get Started”).click() # 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(“example.com”) # Save a second trace file with different actions. context.tracing.stop_chunk(path = “trace2.zip”) “‘



53
54
55
# File 'lib/playwright_api/tracing.rb', line 53

def start_chunk(title: nil)
  wrap_impl(@impl.start_chunk(title: unwrap_impl(title)))
end

#stop(path: nil) ⇒ Object

Stop tracing.



58
59
60
# File 'lib/playwright_api/tracing.rb', line 58

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

#stop_chunk(path: nil) ⇒ Object

Stop the trace chunk. See [‘method: Tracing.startChunk`] for more details about multiple trace chunks.



63
64
65
# File 'lib/playwright_api/tracing.rb', line 63

def stop_chunk(path: nil)
  wrap_impl(@impl.stop_chunk(path: unwrap_impl(path)))
end