Looking for write-ups on two facets of Capybara

19 views
Skip to first unread message

Jack Royal-Gordon

unread,
Nov 21, 2020, 4:38:27 PM11/21/20
to Capybara
I'm using Capybara with Selenium and Firefox to test javascript on webpages in a Ruby on Rails app using RSpec as the test environment. Having just written and gotten working my first tests of Javascript, the experience has left me with a number of questions (it was very much a trial-and-error, google-any-messages-you-don't-understand, sort of experience). Foremost among them:

1) Pros and cons of the different configurations for running tests (e.g. headless, Capybara with Selenium and Firefox, Capybara with Webkit, etc.).

2) How to debug Javascript running with Capybara.

Thomas Walpole

unread,
Nov 21, 2020, 10:50:43 PM11/21/20
to Capybara
1. Configure your drivers so you can easily switch between headless and non-headless.
2. Run non-headless when debugging your tests so you can see what’s happening
3. Interact with the exact elements your user will be when you’re writing your tests
4. Set `Capybara.default_max_wait_time` to a high value when debugging so you can see what’s happening on the page when your actions/expectations are waiting

Jack Royal-Gordon

unread,
Nov 22, 2020, 1:06:38 AM11/22/20
to ruby-c...@googlegroups.com
Thanks, Thomas. Those all seem like reasonable suggestions. I shall explore these ideas in further detail.

--
You received this message because you are subscribed to the Google Groups "Capybara" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-capybar...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-capybara/74baf4f2-740d-4b17-8241-c4c4a8c7a926n%40googlegroups.com.

Chris Irish

unread,
Nov 23, 2020, 10:55:42 AM11/23/20
to Capybara
Also for debugging JS specifically

It can be helpful to put a debugger breakpoint in your rspec spec file (Byebug, pry, etc) after a page load, then open up dev tools in the browser when it's paused

You can use the devtools javascript console to play around, inspect elements, etc

Jack Royal-Gordon

unread,
Nov 23, 2020, 4:13:37 PM11/23/20
to ruby-c...@googlegroups.com
I did discover the “pause the spec so you can open the web console in the browser” technique. I would be happier if I could do that programmatically in the spec (e.g. a call like “page.driver.broser.show_web_console”). I don’t suppose anyone has found a way to do that?

You received this message because you are subscribed to a topic in the Google Groups "Capybara" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ruby-capybara/J26Cb988RXE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ruby-capybar...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-capybara/8b1fae09-75a7-4124-8dc9-c12da0a2b486n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages