diff --git a/README.md b/README.md index 85d3f80..5a8d334 100644 --- a/README.md +++ b/README.md @@ -161,8 +161,11 @@ makes debugging easier). Running `rake autocompile` will watch the `getBoundingClientRect()` method, which will be faster and less buggy. -* Handle `window.confirm()`. (Always returns true, which is the same - as capybara-webkit.) [Issue #10] +* Handle `window.confirm()`. Always returns true, which is the same + as capybara-webkit. [Issue #10] + +* Handle `window.prompt()`. Returns the default value, if present, or + null. ### 0.3.0 ### diff --git a/lib/capybara/poltergeist/client/agent.coffee b/lib/capybara/poltergeist/client/agent.coffee index 5c6f264..24f644e 100644 --- a/lib/capybara/poltergeist/client/agent.coffee +++ b/lib/capybara/poltergeist/client/agent.coffee @@ -177,3 +177,4 @@ document.addEventListener( ) window.confirm = (message) -> true +window.prompt = (message, _default) -> _default or null diff --git a/lib/capybara/poltergeist/client/compiled/agent.js b/lib/capybara/poltergeist/client/compiled/agent.js index e27cdb9..bb7a104 100644 --- a/lib/capybara/poltergeist/client/compiled/agent.js +++ b/lib/capybara/poltergeist/client/compiled/agent.js @@ -205,4 +205,7 @@ document.addEventListener('DOMContentLoaded', function() { }); window.confirm = function(message) { return true; +}; +window.prompt = function(message, _default) { + return _default || null; }; \ No newline at end of file diff --git a/spec/integration/session_spec.rb b/spec/integration/session_spec.rb index 214748d..6c7ac7b 100644 --- a/spec/integration/session_spec.rb +++ b/spec/integration/session_spec.rb @@ -75,9 +75,15 @@ describe Capybara::Session do end end - it 'should handle window.confirm() - returning true unconditionally' do + it 'should handle window.confirm(), returning true unconditionally' do @session.visit '/' @session.evaluate_script("window.confirm('foo')").should == true end + + it 'should handle window.prompt(), returning the default value or null' do + @session.visit '/' + @session.evaluate_script("window.prompt()").should == nil + @session.evaluate_script("window.prompt('foo', 'default')").should == 'default' + end end end