Method: Capybara::Session#within_window
- Defined in:
- lib/capybara/session.rb
#within_window(window) ⇒ Object #within_window(proc_or_lambda) ⇒ Object
This method does the following:
- Switches to the given window (it can be located by window instance/lambda/string).
- Executes the given block (within window located at previous step).
- Switches back (this step will be invoked even if an exception occurs at the second step).
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 |
# File 'lib/capybara/session.rb', line 545 def within_window(window_or_proc) original = current_window scopes << nil begin case window_or_proc when Capybara::Window _switch_to_window(window_or_proc) unless original == window_or_proc when Proc _switch_to_window { window_or_proc.call } else raise ArgumentError, '`#within_window` requires a `Capybara::Window` instance or a lambda' end begin yield if block_given? ensure _switch_to_window(original) unless original == window_or_proc end ensure scopes.pop end end |