Add ability to query for console messages and errors #201

Merged
merged 3 commits into from Dec 7, 2011

Conversation

Projects
None yet
9 participants
Contributor

joefiorini commented Oct 31, 2011

  • This changes the format of console message output to use "|" as the
    delimiter instead of ":"; ":" is no good for splitting when there are
    URLs and error messages in the output
  • WebPage tracks all console messages and clears them out on reset
Contributor

joefiorini commented Oct 31, 2011

Also added a matcher to be able to say:

page.should_not have_errors
Owner

mike-burns commented Oct 31, 2011

A tab character seems more canonical than a pipe.

Contributor

joefiorini commented Oct 31, 2011

All console messages are printed to the screen in raw format (with delimiters). Wouldn't using tabs would make this harder to read? I'm happy to change it something more canonical, but I'd prefer to use a printed character for that reason.

seanami commented Nov 1, 2011

Awesome. Excited to use page.should_not have_errors in my tests.

Contributor

joefiorini commented Nov 11, 2011

Is there something I can do to help move this along?

Contributor

morenocarullo commented Nov 11, 2011

+1 this pull request would be very useful.

Owner

jferris commented Nov 15, 2011

Thanks for putting this together. I'll try to have a look at this soon.

joefiorini added some commits Oct 31, 2011

@joefiorini joefiorini Add ability to query for console messages & errors
- This changes the format of console message output to use "|" as the
delimiter instead of ":"; ":" is no good for splitting when there are
URLs and error messages in the output
- WebPage tracks all console messages and clears them out on reset
62b4991
@joefiorini joefiorini Add matcher for javascript error checking 741261c
@joefiorini joefiorini Fix spec broken in previous commit 24ccd1f
Contributor

joefiorini commented Dec 6, 2011

It's been almost a month-and-a-half since I submitted this. I'm working on a screencast and would like to use this feature in it, but I don't want to point people to my personal fork. Are there problems with this I can fix or there anything else I can do to help get this through? Thanks!

@jferris jferris commented on the diff Dec 6, 2011

spec/driver_spec.rb
+ <script type="text/javascript">
+ console.log("hello");
+ console.log("hello again");
+ oops
+ </script>
+ </body>
+ </html>
+ HTML
+ [200,
+ { 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
+ [body]]
+ end
+ end
+
+ it "collects messages logged to the console" do
+ puts subject.console_messages.inspect
@jferris

jferris Dec 6, 2011

Owner

Was this left in unintentionally?

@jferris jferris merged commit 24ccd1f into thoughtbot:master Dec 7, 2011

Owner

jferris commented Dec 7, 2011

Thanks for the patch; this is merged into master.

Contributor

joefiorini commented Dec 7, 2011

Thanks for accepting this Joe, sorry about my stray puts :)

nuc commented Dec 14, 2011

I cannot make this to work :(

I'm pretty sure I have the latest version, but when I try page.should_not have_errors I get:

NoMethodError Exception: undefined method 'has_errors?' for #<Capybara::Session>
Contributor

joefiorini commented Dec 14, 2011

Try page.browser.should_not have_errors.

On Dec 14, 2011, at 7:39 AM, Giorgos Giannoutsosreply@reply.github.com wrote:

I cannot make this to work :(

I'm pretty sure I have the latest version, but when I try page.should_not have_errors I get:

NoMethodError Exception: undefined method 'has_errors?' for #Capybara::Session


Reply to this email directly or view it on GitHub:
#201 (comment)

There seems to be a race condition somewhere. Sometimes I get
|15|TypeError: Result of expression 'b' [undefined] is not an object.
in the console running my tests, but nothing ends up in console_messages. Other times it does end up there.

Contributor

chrisnicola commented Mar 16, 2012

@joefiorini page.browser is undefined and while page.driver.browser is the error is still:

NoMethodError Exception: undefined method 'has_errors?' for #<Capybara::Driver::Webkit::Browser:0x00000003181750>
Contributor

chrisnicola commented Mar 16, 2012

Possible that the RSpec API changed. I've fixed it in #297.

I'm getting the same error trying to test for JavaScript errors:

     Failure/Error: expect(page).not_to have_errors
     NoMethodError:
       undefined method `has_errors?' for #<Capybara::Session>

I have the following versions installed:

  • capybara 2.2.0
  • capybara-webkit 1.1.0
  • rspec-rails 2.14.0
  • rspec-core 2.14.7

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment