Git Product home page Git Product logo

chai-webdriver's Introduction

chai-webdriver Build Status Dependency Status NPM version

Provides selenium-webdriver sugar for the Chai assertion library. Allows you to create expressive integration tests:

expect('.frequency-field').dom.to.contain.text('One time')
expect('.toggle-pane').dom.to.not.be.visible()

What sorts of assertions can we make?

All assertions start with a Sizzle-compatible css selector, for example:

  • expect('.list')
  • expect('div > h1')
  • expect('a[href=http://google.com]')

Then we add the dom flag, like so:

  • expect(selector).dom

Finally, we can add our assertion to the chain:

  • expect(selector).dom.to.have.text('string') - Test the text value of the dom against supplied string. Exact matches only.
  • expect(selector).dom.to.contain.text('string') - Test the text value of the dom against supplied string. Partial matches allowed.
  • expect(selector).dom.to.match(/regex/) - Test the text value of the dom against the regular expression.
  • expect(selector).dom.to.have.text(/regex/) - Test the text value of the dom against the regular expression. (Same as match above).
  • expect(selector).dom.to.be.visible() - Check whether or not the element is being rendered
  • expect(selector).dom.to.be.disabled() - Check whether or not the form element is disabled
  • expect(selector).dom.to.have.count(number) - Test how many elements exist in the dom with the supplied selector
  • expect(selector).dom.to.have.style('property', 'value') - Test the CSS style of the element. Exact matches only, unfortunately, for now.
  • expect(selector).dom.to.have.value('string') - Test the value of a form field against supplied string.
  • expect(selector).dom.to.have.htmlClass('warning') - Tests that the element has warning as one of its class attributes.
  • expect(selector).dom.to.have.attribute('attribute', 'value') - Test an element's attribute value. Exact matches only. By omitting value test simply checks for existance of attribute.

You can also always add a not in there to negate the assertion:

  • expect(selector).dom.not.to.have.style('property', 'value')

Setup

Setup is pretty easy. Just:

// Start with a webdriver instance:
var sw = require('selenium-webdriver');
var driver = new sw.Builder()
  .withCapabilities(sw.Capabilities.chrome())
  .build()

// And then...
var chai = require('chai');
var chaiWebdriver = require('chai-webdriver');
chai.use(chaiWebdriver(driver));

// And you're good to go!
driver.get('http://github.com');
chai.expect('#site-container h1.heading').dom.to.not.contain.text("I'm a kitty!");

Contributing

so easy.

npm install           # download the neccesary development dependencies
npm run-script build  # compile coffee-script into javascript
npm test              # build and run the specs

License

MIT.

chai-webdriver's People

Contributors

chrismcmacken avatar demands avatar hurrymaplelad avatar jonstorer avatar sherrman avatar sylspren avatar waneka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.