Class: Browserctl::PageProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/browserctl/workflow/page_proxy.rb

Overview

Per-page wrapper handed to workflow step blocks via ‘page(:name)`. Forwards one-liners to the daemon `Client`, unwraps the response, and — when a replay context is attached — falls back to fingerprint-based rematching when a selector goes missing.

Extracted from ‘workflow.rb` so the proxy can be loaded and reasoned about independently of the workflow DSL / registry; behaviour is unchanged.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, client, replay_context: nil, matcher: nil) ⇒ PageProxy

Returns a new instance of PageProxy.



32
33
34
35
36
37
# File 'lib/browserctl/workflow/page_proxy.rb', line 32

def initialize(name, client, replay_context: nil, matcher: nil)
  @name           = name
  @client         = client
  @replay_context = replay_context
  @matcher        = matcher || Replay::FingerprintMatcher.new
end

Instance Attribute Details

#replay_contextObject

Returns the value of attribute replay_context.



15
16
17
# File 'lib/browserctl/workflow/page_proxy.rb', line 15

def replay_context
  @replay_context
end

Class Method Details

.delegate_unwrap(method_name, extract: nil) ⇒ Object

Declarative wrapper for ‘unwrap @client.METHOD(@name, …)` one-liners. Forwards positional + keyword args verbatim. Pass `extract:` to return a single key from the client response instead of unwrapping.



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/browserctl/workflow/page_proxy.rb', line 20

def self.delegate_unwrap(method_name, extract: nil)
  if extract
    define_method(method_name) do |*args, **kwargs|
      @client.public_send(method_name, @name, *args, **kwargs)[extract]
    end
  else
    define_method(method_name) do |*args, **kwargs|
      unwrap @client.public_send(method_name, @name, *args, **kwargs)
    end
  end
end

Instance Method Details

#click(selector = nil, ref: nil) ⇒ Object



60
61
62
63
64
# File 'lib/browserctl/workflow/page_proxy.rb', line 60

def click(selector = nil, ref: nil)
  with_selector_fallback(:click, selector, ref) do |sel, r|
    @client.click(@name, sel, ref: r)
  end
end

#fill(selector = nil, value = nil, ref: nil) ⇒ Object



54
55
56
57
58
# File 'lib/browserctl/workflow/page_proxy.rb', line 54

def fill(selector = nil, value = nil, ref: nil)
  with_selector_fallback(:fill, selector, ref) do |sel, r|
    @client.fill(@name, sel, value, ref: r)
  end
end

#hover(selector = nil, ref: nil) ⇒ Object



66
67
68
69
70
# File 'lib/browserctl/workflow/page_proxy.rb', line 66

def hover(selector = nil, ref: nil)
  with_selector_fallback(:hover, selector, ref) do |sel, r|
    @client.hover(@name, sel, ref: r)
  end
end

#select(selector = nil, value = nil, ref: nil) ⇒ Object



78
79
80
81
82
# File 'lib/browserctl/workflow/page_proxy.rb', line 78

def select(selector = nil, value = nil, ref: nil)
  with_selector_fallback(:select, selector, ref) do |sel, r|
    @client.select(@name, sel, value, ref: r)
  end
end

#upload(selector = nil, path = nil, ref: nil) ⇒ Object



72
73
74
75
76
# File 'lib/browserctl/workflow/page_proxy.rb', line 72

def upload(selector = nil, path = nil, ref: nil)
  with_selector_fallback(:upload, selector, ref) do |sel, r|
    @client.upload(@name, sel, path, ref: r)
  end
end