Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Optional error raising #69

Merged
merged 5 commits into from

3 participants

@rentalcustard

@jonleighton: this builds on @john-griffin's work from #62 per our discussion. I've removed the need to split out messages from error classes by passing exception objects directly to the log, and we're no longer suppressing BrowserErrors. As a consequence of the former, the error-handling logic is now inlined.

john-griffin and others added some commits
@john-griffin john-griffin add an option to prevent re-raising of Javascript errors in Ruby 1a53f66
@rentalcustard rentalcustard Tweak john-griffin's work.
* Don't suppress browser errors, only JS errors
* Send exception objects to the log to avoid message-splitting pain
ee7f317
@jonleighton
Owner

Please could you add something to the change log? (It's at the bottom of README.md.) Thanks

@jonleighton jonleighton merged commit 10fe8e5 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 31, 2012
  1. @john-griffin @rentalcustard
  2. @rentalcustard

    Tweak john-griffin's work.

    rentalcustard authored
    * Don't suppress browser errors, only JS errors
    * Send exception objects to the log to avoid message-splitting pain
  3. @rentalcustard

    Update changelog

    rentalcustard authored
  4. @rentalcustard

    Rename raise_errors -> js_errors

    rentalcustard authored
    Resolves an ambiguity
  5. @rentalcustard

    Satisfy Jon's OCD

    rentalcustard authored
This page is out of date. Refresh to see the latest.
View
8 README.md
@@ -158,6 +158,7 @@ end
when communicating with PhantomJS. `nil` means wait forever. Default
is 30.
* `:inspector` (Boolean, String) - See 'Remote Debugging', above.
+* `:js_errors` (Boolean) - When false, Javascript errors do not get re-raised in Ruby.
## Bugs ##
@@ -181,6 +182,13 @@ makes debugging easier). Running `rake autocompile` will watch the
## Changes ##
+### 0.7.0 ###
+
+#### Features ####
+
+* Added an option ":js_errors", allowing poltergeist to continue
+ running after JS errors. (John Griffin & Tom Stuart) [Issue #62] [Issue #69]
+
### 0.6.0 ###
#### Features ####
View
22 lib/capybara/poltergeist/browser.rb
@@ -2,12 +2,13 @@
module Capybara::Poltergeist
class Browser
- attr_reader :server, :client, :logger
+ attr_reader :server, :client, :logger, :js_errors
- def initialize(server, client, logger = nil)
- @server = server
- @client = client
- @logger = logger
+ def initialize(server, client, logger = nil, js_errors = true)
+ @server = server
+ @client = client
+ @logger = logger
+ @js_errors = js_errors
end
def restart
@@ -123,13 +124,17 @@ def command(name, *args)
if json['error']
if json['error']['name'] == 'Poltergeist.JavascriptError'
- raise JavascriptError.new(json['error'])
+ error = JavascriptError.new(json['error'])
+ if js_errors
+ raise error
+ else
+ log error
+ end
else
raise BrowserError.new(json['error'])
end
- else
- json['response']
end
+ json['response']
rescue DeadClient
restart
@@ -137,7 +142,6 @@ def command(name, *args)
end
private
-
def log(message)
logger.puts message if logger
end
View
6 lib/capybara/poltergeist/driver.rb
@@ -17,7 +17,7 @@ def initialize(app, options = {})
end
def browser
- @browser ||= Browser.new(server, client, logger)
+ @browser ||= Browser.new(server, client, logger, js_errors)
end
def inspector
@@ -58,6 +58,10 @@ def logger
options[:logger] || (options[:debug] && STDERR)
end
+ def js_errors
+ options.fetch(:js_errors, true)
+ end
+
def visit(path)
browser.visit app_server.url(path)
end
View
7 spec/integration/driver_spec.rb
@@ -160,6 +160,13 @@ module Capybara::Poltergeist
# should not raise again
@driver.evaluate_script("1+1").should == 2
end
+
+ it "doesn't propagate a Javascript error to ruby if error raising disabled" do
+ driver = Capybara::Poltergeist::Driver.new(nil, :js_errors => false)
+ driver.execute_script "setTimeout(function() { omg }, 0)"
+ sleep 0.01
+ expect { driver.execute_script "" }.to_not raise_error(JavascriptError)
+ end
end
end
end
Something went wrong with that request. Please try again.