From d9dff6a80f9abd41505167543f49ff5e53378ca3 Mon Sep 17 00:00:00 2001 From: Thomas Walpole Date: Wed, 2 Jul 2014 19:10:30 -0700 Subject: [PATCH] allow for blockless modal methods in selenium --- lib/capybara/selenium/driver.rb | 4 ++-- spec/selenium_spec.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/capybara/selenium/driver.rb b/lib/capybara/selenium/driver.rb index 274a1cba..ae3c4972 100644 --- a/lib/capybara/selenium/driver.rb +++ b/lib/capybara/selenium/driver.rb @@ -205,7 +205,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base end def accept_modal(type, options={}, &blk) - yield + yield if block_given? modal = find_modal(options) modal.send_keys options[:with] if options[:with] message = modal.text @@ -214,7 +214,7 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base end def dismiss_modal(type, options={}, &blk) - yield + yield if block_given? modal = find_modal(options) message = modal.text modal.dismiss diff --git a/spec/selenium_spec.rb b/spec/selenium_spec.rb index 74738b41..9420a612 100644 --- a/spec/selenium_spec.rb +++ b/spec/selenium_spec.rb @@ -63,6 +63,16 @@ RSpec.describe Capybara::Session do expect($?.exitstatus).to be 0 end end + + describe "#accept_alert", focus: true do + it "supports a blockless mode" do + @session.visit('/with_js') + @session.click_link('Open alert') + expect(@session.driver.browser.switch_to.alert).to be_kind_of Selenium::WebDriver::Alert + @session.accept_alert + expect{@session.driver.browser.switch_to.alert}.to raise_error("No alert is present") + end + end end end @@ -81,4 +91,3 @@ RSpec.describe Capybara::Selenium::Driver do end end -