Module: Specbook::Recorders::CapybaraScreenshotPatch

Defined in:
lib/specbook/recorders/screenshot.rb

Instance Method Summary collapse

Instance Method Details

#accept_confirm(text = nil, &block) ⇒ Object



325
326
327
# File 'lib/specbook/recorders/screenshot.rb', line 325

def accept_confirm(text = nil, &block)
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Accept confirm dialog", action_type: "confirm") }
end

#attach_file(locator = nil, path = nil, **opts) ⇒ Object



321
322
323
# File 'lib/specbook/recorders/screenshot.rb', line 321

def attach_file(locator = nil, path = nil, **opts)
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Attach file '#{locator}'", action_type: "fill") }
end

#check(locator = nil, **opts) ⇒ Object



311
312
313
314
# File 'lib/specbook/recorders/screenshot.rb', line 311

def check(locator = nil, **opts)
  el = begin; find_field(locator); rescue Capybara::ElementNotFound; nil; end
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Check '#{locator}'", target_element: el, action_type: "check") }
end

#choose(locator = nil, **opts) ⇒ Object



302
303
304
305
306
307
308
309
# File 'lib/specbook/recorders/screenshot.rb', line 302

def choose(locator = nil, **opts)
  el = begin
    find(:radio_button, locator)
  rescue Capybara::ElementNotFound, Capybara::Ambiguous
    begin; find(:css, "label", text: locator); rescue; nil; end
  end
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Choose '#{locator}'", target_element: el, action_type: "check") }
end

#click_button(locator = nil, **opts) ⇒ Object



281
282
283
284
285
286
287
288
289
290
# File 'lib/specbook/recorders/screenshot.rb', line 281

def click_button(locator = nil, **opts)
  # Find element for bbox before clicking
  el = begin
    find_button(locator || opts[:text], wait: 0)
  rescue Capybara::ElementNotFound, Capybara::Ambiguous
    begin; find(:css, "button", text: locator || opts[:text], wait: 0); rescue; nil; end
  end
  Specbook::Recorders::Screenshot.capture!(page, "Click button '#{locator || opts[:text]}'", target_element: el, action_type: "click")
  super
end


267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/specbook/recorders/screenshot.rb', line 267

def click_link(locator = nil, **opts)
  el = begin
    if opts[:href]
      find(:link, href: opts[:href], wait: 0)
    else
      find_link(locator || opts[:text], wait: 0)
    end
  rescue Capybara::ElementNotFound, Capybara::Ambiguous
    nil
  end
  Specbook::Recorders::Screenshot.capture!(page, "Click link '#{locator || opts[:text] || opts[:href]}'", target_element: el, action_type: "click")
  super
end

#click_on(locator = nil, **opts) ⇒ Object



260
261
262
263
264
265
# File 'lib/specbook/recorders/screenshot.rb', line 260

def click_on(locator = nil, **opts)
  el = _find_target_element(locator, opts)
  # Capture BEFORE click — shows what was clicked, not the post-click state
  Specbook::Recorders::Screenshot.capture!(page, "Click '#{locator || opts[:text] || 'element'}'", target_element: el, action_type: "click")
  super
end

#fill_in(locator = nil, with:, **opts) ⇒ Object



292
293
294
295
# File 'lib/specbook/recorders/screenshot.rb', line 292

def fill_in(locator = nil, with:, **opts)
  el = begin; find_field(locator || opts[:id] || opts[:name]); rescue Capybara::ElementNotFound; nil; end
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Type '#{with.to_s.truncate(30)}' into '#{locator}'", target_element: el, action_type: "fill") }
end

#select(value = nil, from: nil, **opts) ⇒ Object



297
298
299
300
# File 'lib/specbook/recorders/screenshot.rb', line 297

def select(value = nil, from: nil, **opts)
  el = begin; find_field(from); rescue Capybara::ElementNotFound; nil; end
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Select '#{value}' from '#{from}'", target_element: el, action_type: "select") }
end

#uncheck(locator = nil, **opts) ⇒ Object



316
317
318
319
# File 'lib/specbook/recorders/screenshot.rb', line 316

def uncheck(locator = nil, **opts)
  el = begin; find_field(locator); rescue Capybara::ElementNotFound; nil; end
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Uncheck '#{locator}'", target_element: el, action_type: "check") }
end

#visit(path) ⇒ Object



254
255
256
257
258
# File 'lib/specbook/recorders/screenshot.rb', line 254

def visit(path, **)
  # Flush pending assertions BEFORE navigating (while old page is still visible)
  Specbook::Recorders::Screenshot.flush_assertions!(page) if Specbook::Recorders::Screenshot.pending_assertions.present?
  super.tap { Specbook::Recorders::Screenshot.capture!(page, "Navigate to #{path}", action_type: "navigate") }
end