27

Does anyone know whether there is anything similar to capybara for Node.js?

1

8 Answers 8

12

How about Zombie?

Zombie.js

Insanely fast, headless full-stack testing using Node.js

The Bite

If you're going to write an insanely fast, headless browser, how can you not call it Zombie Zombie it is.

Zombie.js is a lightweight framework for testing client-side JavaScript code in a simulated environment. No browser required.

2
  • 2
    In that case, you should take a look at phantomjs... the reason I ask the question is capybara is a generic framework for other web acceptance testing systems, like Selenium, htmlunit, etc.
    – Chris
    Sep 29, 2011 at 4:12
  • I guess at the moment, nothing like capybara exists for node so I'm awarding you the points - thanks for your input!
    – Chris
    Oct 2, 2011 at 9:33
5

I'm a rails-turned-node developer and I've always been looking for a analogy in the JS world for the winning RSpec/Capybara combination. Here is what I've found what I like best.

  • Mocha - for running asynchronous tests
  • Chai - for assertions
  • Request - for handling HTTP request/response
  • Cheerio - for selecting HTML elements from responses

Here is a more involved post on how to set up this stack including continuous test running.

Happy Testing!

1
  • I'm testing a similar stack right now. It's very simple to get running but I can't find a nice way to execute the Cheerio scrape against rendered javascript, like in single page apps. Good luck.
    – Adam
    Sep 9, 2018 at 20:03
4

Cucumber-JS is the closest you will get in Javascript: https://github.com/cucumber/cucumber-js

You can use the library to drive JS, headless and Selenium, however it is missing the 'capybara' shared API between each of the different 'worlds'. There is a good talk at http://skillsmatter.com/podcast/agile-testing/cucumber-js-cuke-up-your-javascript and supporting github code at https://github.com/jbpros/cukecipes

I'm hoping that when the phantomjs webdriver wire protocol is finished (https://github.com/detro/ghostdriver) and if Soda/Selenium (https://github.com/LearnBoost/soda) is able to drive it then the headless tests will be able to be automated via Selenium thus bypassing the need for Capybara.

2

See jelly.io:

Jellyfish is a Node project that aims to make it easy to launch different JavaScript environments and run your code.

0

Hy!

I've created a library to help out with cucumber-js. It gives you callable steps and parsed arguments. This works with cucumber and doesn't replace it.

Quick features:

  • Sync step definitions, no more callbacks;
  • Call other step from step definitions;
  • Parse values such as arrays, objects and decimals;

https://github.com/hackhat/cucumberry

Hope you find it useful (:

0

We created a complete acceptance testing solution in JS

http://xolv.io/products/chimp

It uses CucumberJS (Mocha/Jasmine soon) to drive your acceptance tests

  • Downloads and starts Phantom / Selenium
  • Injects a preconfigured Webdriver.IO instance into the testing context
  • Includes the request npm library (for REST) the assertion library of your choice (Chai / Jasmine-expect)
  • Uses fibers for synchronous testing (no callback hell / promise confusion)
  • Works with SauceLabs / BrowserStacks etc
  • Support outside in testing with a watch mode that continuously runs the scenarios you tag with @focus
  • Supports CI out of the box and tested on Circle/Codeship/Travis (using headless Chrome/Firefox)

It doesn't make you coffee, yet

0

In terms of acceptance testing, I have heavily used Capybara for Rails. And I am unhappy with the alternatives listed here for NodeJS. You will want a popular web automation utility combined with the ability to make assertions against scenarios of a particular feature.

When you think of web automation in Node, Phantom and, thus, Casper is dead. So what is in the rise as of now? Puppeteer. I started using Puppeteer a few years ago when it was in beta and few articles and SO posts about it. But now Puppeteer is becoming the leader of web automation in Node. However, you cannot assert things in Puppeteer which is what you would expect from a testing framework.

But that doesn't stop us from integrating a testing tool into Puppeteer web automation. I found a few solutions using jest as the testing tool.

const puppeteer = require('puppeteer');
describe('Open Website', () => {
  var browser, page;
  var url = 'https://website.io'
  beforeEach (async () => {
    browser = await puppeteer.launch({ headless: false });
    page = await browser.newPage();
  })

afterEach (() => {
    browser.close()
  })

test('Title == Website Tools', async () => {
    await page.goto(url);
    const title = await page.title();
    expect(title).toBe("Website Tools");
  });
-1

Yes, see expresso and more here - Unit testing framework for node.js that specifically supports testing async code?

1
  • No, I was talking about a generic web acceptance testing framework.
    – Chris
    Sep 29, 2011 at 3:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.