Class: Playwright::Screencast

Inherits:
Object
  • Object
show all
Defined in:
lib/playwright/screencast.rb

Instance Method Summary collapse

Constructor Details

#initialize(page) ⇒ Screencast

Returns a new instance of Screencast.



5
6
7
8
9
10
11
12
# File 'lib/playwright/screencast.rb', line 5

def initialize(page)
  @page = page
  @started = false
  @save_path = nil
  @artifact = nil
  @on_frame = nil
  @page.send(:channel).on('screencastFrame', method(:handle_screencast_frame))
end

Instance Method Details

#hide_actionsObject



75
76
77
# File 'lib/playwright/screencast.rb', line 75

def hide_actions
  @page.send(:channel).send_message_to_server('screencastHideActions')
end

#hide_overlaysObject



83
84
85
# File 'lib/playwright/screencast.rb', line 83

def hide_overlays
  @page.send(:channel).send_message_to_server('screencastSetOverlayVisible', visible: false)
end

#show_actions(duration: nil, fontSize: nil, position: nil) ⇒ Object



66
67
68
69
70
71
72
73
# File 'lib/playwright/screencast.rb', line 66

def show_actions(duration: nil, fontSize: nil, position: nil)
  params = {}
  params[:duration] = duration if duration
  params[:fontSize] = fontSize if fontSize
  params[:position] = position if position
  @page.send(:channel).send_message_to_server('screencastShowActions', params)
  DisposableStub.new { hide_actions }
end

#show_chapter(title, description: nil, duration: nil) ⇒ Object



59
60
61
62
63
64
# File 'lib/playwright/screencast.rb', line 59

def show_chapter(title, description: nil, duration: nil)
  params = { title: title }
  params[:description] = description if description
  params[:duration] = duration if duration
  @page.send(:channel).send_message_to_server('screencastChapter', params)
end

#show_overlay(html, duration: nil) ⇒ Object



49
50
51
52
53
54
55
56
57
# File 'lib/playwright/screencast.rb', line 49

def show_overlay(html, duration: nil)
  params = { html: html }
  params[:duration] = duration if duration
  result = @page.send(:channel).send_message_to_server_result('screencastShowOverlay', params)
  overlay_id = result['id'] if result.is_a?(Hash)
  DisposableStub.new {
    @page.send(:channel).send_message_to_server('screencastRemoveOverlay', id: overlay_id) if overlay_id
  }
end

#show_overlaysObject



79
80
81
# File 'lib/playwright/screencast.rb', line 79

def show_overlays
  @page.send(:channel).send_message_to_server('screencastSetOverlayVisible', visible: true)
end

#start(path: nil, size: nil, quality: nil, &on_frame) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/playwright/screencast.rb', line 14

def start(path: nil, size: nil, quality: nil, &on_frame)
  raise 'Screencast is already started' if @started

  @started = true
  @on_frame = on_frame if on_frame

  params = {}
  params[:record] = true if path
  params[:size] = size if size
  params[:quality] = quality if quality
  params[:sendFrames] = true if on_frame

  result = @page.send(:channel).send_message_to_server_result('screencastStart', params)
  if result.is_a?(Hash) && result['artifact']
    @artifact = ChannelOwners::Artifact.from(result['artifact'])
    @save_path = path
  end

  DisposableStub.new { stop }
end

#stopObject



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/playwright/screencast.rb', line 35

def stop
  return unless @started

  @started = false
  @on_frame = nil
  @page.send(:channel).send_message_to_server('screencastStop')

  if @save_path && @artifact
    @artifact.save_as(@save_path)
  end
  @artifact = nil
  @save_path = nil
end