Class: Browserctl::WorkflowContext
Instance Attribute Summary collapse
Instance Method Summary
collapse
#fetch, #load_state, #save_state, #store
Constructor Details
#initialize(params, client, replay_context: nil) ⇒ WorkflowContext
Returns a new instance of WorkflowContext.
80
81
82
83
84
|
# File 'lib/browserctl/workflow.rb', line 80
def initialize(params, client, replay_context: nil)
@params = params
@client = client
@replay_context = replay_context
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
86
87
88
89
90
|
# File 'lib/browserctl/workflow.rb', line 86
def method_missing(name, *args)
return @params[name] if @params.key?(name)
super
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
78
79
80
|
# File 'lib/browserctl/workflow.rb', line 78
def client
@client
end
|
#params ⇒ Object
Returns the value of attribute params.
78
79
80
|
# File 'lib/browserctl/workflow.rb', line 78
def params
@params
end
|
#replay_context ⇒ Object
Returns the value of attribute replay_context.
78
79
80
|
# File 'lib/browserctl/workflow.rb', line 78
def replay_context
@replay_context
end
|
Instance Method Details
#ask(prompt) ⇒ Object
114
115
116
117
|
# File 'lib/browserctl/workflow.rb', line 114
def ask(prompt)
$stderr.print("[browserctl] #{prompt} ")
$stdin.gets.chomp
end
|
#assert(condition, msg = "assertion failed") ⇒ Object
131
132
133
|
# File 'lib/browserctl/workflow.rb', line 131
def assert(condition, msg = "assertion failed")
raise WorkflowError, msg unless condition
end
|
#assert_snapshot_stable(page_name, expected_digest:) ⇒ Object
Snapshots the named page and compares its digest against ‘expected_digest`. Under `workflow run –check` (a replay context is attached), a mismatch is recorded as a drift event with reason “post-snapshot mismatch” and the step still passes. Outside –check, mismatch raises WorkflowError so the workflow fails fast.
140
141
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/browserctl/workflow.rb', line 140
def assert_snapshot_stable(page_name, expected_digest:)
res = @client.snapshot(page_name.to_s, format: "elements")
snapshot = res[:snapshot]
actual = Replay::SnapshotDiff.digest(snapshot)
return if actual == expected_digest
msg = "post-snapshot mismatch on :#{page_name} — expected #{expected_digest}, got #{actual}"
raise WorkflowError, msg unless @replay_context
@replay_context.record(command: :assert_snapshot_stable, selector: page_name.to_s,
matched_ref: nil, score: nil, reason: "post-snapshot mismatch")
warn "[browserctl replay] #{msg}"
end
|
#close_page(page_name) ⇒ Object
107
108
109
110
111
112
|
# File 'lib/browserctl/workflow.rb', line 107
def close_page(page_name)
res = @client.page_close(page_name.to_s)
raise WorkflowError, res[:error] if res[:error]
res
end
|
#compose ⇒ Object
154
155
156
157
158
|
# File 'lib/browserctl/workflow.rb', line 154
def compose(*)
raise WorkflowError,
"`compose` must be called at the workflow definition level, not inside a step block. " \
"Did you mean `invoke`?"
end
|
#invoke(target_name, page: nil, **override_params) ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
|
# File 'lib/browserctl/workflow.rb', line 119
def invoke(target_name, page: nil, **override_params)
name = target_name.to_s
guard_circular!(name)
flow = lookup_flow_target(name)
if flow
track_invoke(name) { run_invoked_flow(flow, page_name: page, **override_params) }
else
track_invoke(name) { run_nested(target_name, **override_params) }
end
end
|
#open_page(page_name, url: nil) ⇒ Object
100
101
102
103
104
105
|
# File 'lib/browserctl/workflow.rb', line 100
def open_page(page_name, url: nil)
res = @client.page_open(page_name.to_s, url: url)
raise WorkflowError, res[:error] if res[:error]
res
end
|
#page(name) ⇒ Object
96
97
98
|
# File 'lib/browserctl/workflow.rb', line 96
def page(name)
PageProxy.new(name.to_s, @client, replay_context: @replay_context)
end
|
#respond_to_missing?(name, include_private = false) ⇒ Boolean
92
93
94
|
# File 'lib/browserctl/workflow.rb', line 92
def respond_to_missing?(name, include_private = false)
@params.key?(name) || super
end
|