Permalink
Browse files

#evaluate_script shouldn't blow up if JSON parsing fails

  • Loading branch information...
1 parent a4fcb8e commit 93b8cf1043599e29468b809bd8e7f0f1cf0c881b @sdhull committed Feb 28, 2012
Showing with 8 additions and 1 deletion.
  1. +1 −1 lib/capybara/driver/webkit/browser.rb
  2. +7 −0 spec/driver_spec.rb
@@ -97,7 +97,7 @@ def command(name, *args)
def evaluate_script(script)
json = command('Evaluate', script)
- JSON.parse("[#{json}]").first
+ JSON.parse("[#{json}]").first rescue json
end
def execute_script(script)
View
@@ -96,6 +96,13 @@
end
end
+ it "returns a string if JSON parsing fails" do
+ subject.within_frame("f") do
+ result = subject.evaluate_script(%<document.getElementsByTagName('script')[0].textContent>)
+ result.should == "\"\n document.write(\\\"<p id='farewell'>goodbye</p>\\\");\n \""
+ end
+ end
+
it "executes Javascript" do
subject.within_frame("f") do
subject.execute_script(%<document.getElementById('farewell').innerHTML = 'yo'>)

0 comments on commit 93b8cf1

Please sign in to comment.