Watir-webdriver or Capybara
Asked Answered
F

3

12

I currently use Watir-webdriver for all my front end testing, but the development team use Capybara to run their tests on Jenkins CI. We both use the same Cucumber features.

Is it worth us doing seperate tests and effectively twice? Which one is the better tool to use? I've read all the comparisons available on the web and prefer using watir-webdriver, but Capybara allows me to use headless testing seamlessly.

So any useful thoughts and ideas? I'm at a crossroads and not sure whether to give up Watir-webdriver and just go with the rest of the dev team and use Capybara.

Firewarden answered 21/12, 2012 at 14:17 Comment(0)
S
2

We're having exactly the same sort of discussion on my current project. One of the developers is a big fan of Capybara, whereas my familiarity is with Watir-webdriver.

Capybara has a real simplicity to it, which makes it very quick to get tests up and running but I worry about maintenance issues over time, and I also worry that its simplicity may also mean a lack of flexibility.

Watir-webdriver allows me to write an abstraction layer for my web pages, identifying elements exactly how I want/need to (flexibility), which also means that the "testing" layer can still look simple to the people writing the test scenarios, like Capybara, but maintenance over time will be rapid, because the code is inherently kept DRY. There's a little more up-front cost to getting that page element layer written, but I have a sense of security that future maintenance of the framework will be rapid.

Of course, I'm biased--but open-minded. I'd love to hear a counterpoint from a Capybara fan.

Secant answered 21/12, 2012 at 15:37 Comment(3)
Hey Abe, check out this URL: watirmelon.com/2011/12/03/…Firewarden
Thanks Azher. I'd read that before and agree with it, though I've seen Capybara folks recently saying that it's outdated and wrong-headed, now, though they weren't too specific as to why (Wish I had a link handy to the conversation where I saw this).Secant
Ah! Found it: groups.google.com/forum/?fromgroups=#!topic/ruby-capybara/… ... Says that Alister is spreading FUD (among other things).Secant
S
6

As to whether using two different tools for the same cucumber features depends on the test domain and which suits it best. If Watir-webdriver suits front-end testing better than Capybara-webdriver, or vice versa. You'd need to invest some time investigating Capybara (a design spike, to use Agile parlance) to compare it to what you're used to. Try to be objective, even though it's very difficult (in my experience) with a familiar framework, and then do a Cost Benefit Analysis of changing. The direct Cost may only be time/effort but it's still a cost which can impact project delivery.

Capybara is not incompatible with DRY programming - an abstraction layer (like Abe mentions in his reply) is possible with Capybara's custom selectors. Once these have been created, you can use capybara finders and matchers on your custom selectors like so;

Capybara.add_selector(:slide_show) do
  xpath { ".//div[contains(@class,'slideshow')]" }
end

Capybara.add_selector(:slide_show_element) do
  xpath { ".//div[contains(@class,'slideshowelem')]" }
end

allows you to use Capybara's find;

find(:slide_show_element, 'Sunset').click

From the Cucumber perspective it's possible to pass that locator string through from the step;

And I Click "Sunset" in the "Holiday Pictures" Slide Show

through a step definition like this;

Given /^(?:I |)Click "(.*?)" in the "(.*?)" Slide Show$/i do |picture,slideshow|
   within(:slide_show, slideshow) do 
     find(:slide_show_element, picture).click
   end
end

So, the question remains one of process - is having two frameworks impacting your workflow? And would reconciling the two involve an unacceptable loss of time?

Simdars answered 1/5, 2013 at 10:20 Comment(0)
S
2

We're having exactly the same sort of discussion on my current project. One of the developers is a big fan of Capybara, whereas my familiarity is with Watir-webdriver.

Capybara has a real simplicity to it, which makes it very quick to get tests up and running but I worry about maintenance issues over time, and I also worry that its simplicity may also mean a lack of flexibility.

Watir-webdriver allows me to write an abstraction layer for my web pages, identifying elements exactly how I want/need to (flexibility), which also means that the "testing" layer can still look simple to the people writing the test scenarios, like Capybara, but maintenance over time will be rapid, because the code is inherently kept DRY. There's a little more up-front cost to getting that page element layer written, but I have a sense of security that future maintenance of the framework will be rapid.

Of course, I'm biased--but open-minded. I'd love to hear a counterpoint from a Capybara fan.

Secant answered 21/12, 2012 at 15:37 Comment(3)
Hey Abe, check out this URL: watirmelon.com/2011/12/03/…Firewarden
Thanks Azher. I'd read that before and agree with it, though I've seen Capybara folks recently saying that it's outdated and wrong-headed, now, though they weren't too specific as to why (Wish I had a link handy to the conversation where I saw this).Secant
Ah! Found it: groups.google.com/forum/?fromgroups=#!topic/ruby-capybara/… ... Says that Alister is spreading FUD (among other things).Secant
T
1

If you are on Linux, you can run real browsers headless with watir-webdriver: http://watirwebdriver.com/headless/

There is probably a way to run headless browser(s) using watir-webdriver, if that is what you want to do.

Is it better to use one tool or both depends on your context. Do you have any problems with using both tools?

Toothpick answered 21/12, 2012 at 15:1 Comment(1)
Many thanks for the URL. In regards to using both tools, I don't really have a problem. I'm more used to writing tests using watir-webdriver and prefer the flexibility of writing tests and being more in control. Whereas I would need a bit of help with Capybara for the slightly complex test step defs, even though they are quite similar.Firewarden

© 2022 - 2024 — McMap. All rights reserved.