Module: Specbook::Recorders::CapybaraSessionActionPatch
- Defined in:
- lib/specbook/recorders/screenshot.rb
Overview
Session-level action patches — captures bbox for click/fill/select/choose These prepend on Session so they work from both test class AND step definitions
Instance Method Summary collapse
- #accept_confirm(text = nil, &block) ⇒ Object
- #attach_file(locator = nil, path = nil, **opts) ⇒ Object
- #check(locator = nil, **opts) ⇒ Object
- #choose(locator = nil, **opts) ⇒ Object
- #click_button(locator = nil, **opts) ⇒ Object
- #click_link(locator = nil, **opts) ⇒ Object
- #click_on(locator = nil, **opts) ⇒ Object
- #fill_in(locator = nil, with:, **opts) ⇒ Object
- #select(value = nil, from: nil, **opts) ⇒ Object
- #uncheck(locator = nil, **opts) ⇒ Object
- #visit(path) ⇒ Object
Instance Method Details
#accept_confirm(text = nil, &block) ⇒ Object
551 552 553 |
# File 'lib/specbook/recorders/screenshot.rb', line 551 def accept_confirm(text = nil, &block) super.tap { Specbook::Recorders::Screenshot.capture!(self, "Accept confirm dialog", action_type: "confirm") } end |
#attach_file(locator = nil, path = nil, **opts) ⇒ Object
542 543 544 |
# File 'lib/specbook/recorders/screenshot.rb', line 542 def attach_file(locator = nil, path = nil, **opts) super.tap { Specbook::Recorders::Screenshot.capture!(self, "Attach file '#{locator}'", action_type: "fill") } end |
#check(locator = nil, **opts) ⇒ Object
532 533 534 535 |
# File 'lib/specbook/recorders/screenshot.rb', line 532 def check(locator = nil, **opts) el = begin; find_field(locator); rescue; nil; end super.tap { Specbook::Recorders::Screenshot.capture!(self, "Check '#{locator}'", target_element: el, action_type: "check") } end |
#choose(locator = nil, **opts) ⇒ Object
526 527 528 529 530 |
# File 'lib/specbook/recorders/screenshot.rb', line 526 def choose(locator = nil, **opts) # Radio buttons are often sr-only (hidden). Find the visible parent label card by text. el = begin; find(:css, "label", text: /\A#{Regexp.escape(locator)}\z/); rescue; begin; find(:css, "label", text: locator); rescue; nil; end; end super.tap { Specbook::Recorders::Screenshot.capture!(self, "Choose '#{locator}'", target_element: el, action_type: "check") } end |
#click_button(locator = nil, **opts) ⇒ Object
496 497 498 499 500 |
# File 'lib/specbook/recorders/screenshot.rb', line 496 def (locator = nil, **opts) el = begin; (locator || opts[:text]); rescue; begin; find(:css, "button", text: locator || opts[:text]); rescue; nil; end; end Specbook::Recorders::Screenshot.capture!(self, "Click button '#{locator || opts[:text]}'", target_element: el, action_type: "click") super end |
#click_link(locator = nil, **opts) ⇒ Object
502 503 504 505 506 507 508 |
# File 'lib/specbook/recorders/screenshot.rb', line 502 def click_link(locator = nil, **opts) el = begin opts[:href] ? find(:link, href: opts[:href]) : find_link(locator || opts[:text]) rescue; nil; end Specbook::Recorders::Screenshot.capture!(self, "Click link '#{locator || opts[:text] || opts[:href]}'", target_element: el, action_type: "click") super end |
#click_on(locator = nil, **opts) ⇒ Object
510 511 512 513 514 |
# File 'lib/specbook/recorders/screenshot.rb', line 510 def click_on(locator = nil, **opts) el = begin; find_link(locator); rescue; begin; (locator); rescue; nil; end; end Specbook::Recorders::Screenshot.capture!(self, "Click '#{locator}'", target_element: el, action_type: "click") super end |
#fill_in(locator = nil, with:, **opts) ⇒ Object
516 517 518 519 |
# File 'lib/specbook/recorders/screenshot.rb', line 516 def fill_in(locator = nil, with:, **opts) el = begin; find_field(locator || opts[:id] || opts[:name]); rescue; nil; end super.tap { Specbook::Recorders::Screenshot.capture!(self, "Type '#{with.to_s.truncate(30)}' into '#{locator}'", target_element: el, action_type: "fill") } end |
#select(value = nil, from: nil, **opts) ⇒ Object
521 522 523 524 |
# File 'lib/specbook/recorders/screenshot.rb', line 521 def select(value = nil, from: nil, **opts) el = begin; find_field(from); rescue; nil; end super.tap { Specbook::Recorders::Screenshot.capture!(self, "Select '#{value}' from '#{from}'", target_element: el, action_type: "select") } end |
#uncheck(locator = nil, **opts) ⇒ Object
537 538 539 540 |
# File 'lib/specbook/recorders/screenshot.rb', line 537 def uncheck(locator = nil, **opts) el = begin; find_field(locator); rescue; nil; end super.tap { Specbook::Recorders::Screenshot.capture!(self, "Uncheck '#{locator}'", target_element: el, action_type: "check") } end |
#visit(path) ⇒ Object
546 547 548 549 |
# File 'lib/specbook/recorders/screenshot.rb', line 546 def visit(path, **) Specbook::Recorders::Screenshot.flush_assertions!(self) if Specbook::Recorders::Screenshot.pending_assertions.present? super.tap { Specbook::Recorders::Screenshot.capture!(self, "Navigate to #{path}", action_type: "navigate") } end |