0.3.1 • Published 9 years ago

cucumberjs-chromedriver v0.3.1

Weekly downloads
54
License
MIT
Repository
github
Last release
9 years ago

cucumberjs-chromedriver

Making local BDD easier.

Getting started

npm install cucumberjs -g
npm install cucumberjs-chromedriver --save-dev

create a feature ./example.feature

Feature: Example feature
  As a user of cucumber.js
  I want to have documentation on cucumber
  So that I can concentrate on building awesome applications

  Scenario: Reading documentation
    When I am on the Cucumber.js GitHub repository
    Then I should see "cucumber" in the page title

create a world file ./local-world.js

module.exports = require('cucumberjs-chromedriver');

this injects cucumberjs-chromedriver into the necessary hooks to start and stop the chromedriver. See Api for more advanced topics.

create a step file ./example.steps.js

var chai = require("chai"),
    chaiAsPromised = require('chai-as-promised');

chai.should();

chai.use(chaiAsPromised);

module.exports = function () {
    this.When(/^I am on the Cucumber.js GitHub repository$/, function () {
        return this.browser.get('./');
    });

    this.Then(/^I should see "(.*)" in the page title$/, function (title) {
        return this.browser.title().should.eventually.contain(title);
  });
};

notice this is requiring more npm installs (but you don't have to use chai if you don't want to)

npm install chai --save-dev
npm install chai-as-promised --save-dev

And run your tests...

cucumberjs example.feature -r local-world.js -r example.steps.js --contentPath=http://github.com/cucumber/cucumber-js/

cucumberjs has conventions so you don't have to be so explicity, but I find them to confuse more than help...

Api

What is injected into the World?

propertydescription
browserthis is a browser instance from wd.js
browser.pause()returns a promise that will never resolve. This makes it easy to stop a test at a certain point in the workflow to manually inspect in the chromedriver browser. Ctr+C to kill the process.
browser.SPECIAL_KEYSwd Special Keys so you don't need to require wd just for the keys

How do I debug what webdriver is doing?

Pass debug through the CLI --debug when starting cucumberjs and it will output webdriver debugging.

How do I extend the world?

module.exports = function(){
	// you can pass `contentPath` or `debug` through here instead of the CLI if you want
    require('cucumberjs-chromedriver').call(this, { contentPath : 'http://localhost:8001' });

	// cache the World factory provided by `cucumberjs-chromedriver`
	var chromeDriverWorldFactory = this.World;
    // create a new WorldFactory
     this.World = function(callback){
     	// now you can do stuff before
         chromeDriverWorldFactory(function(theirWorld){
	         // or after, like extending the world
             var myWorld = Object.create(theirWorld);
             myWorld.jon = 'hoguet';
             // finally pass the world to the callback (which becomes the `this` for all scenarios)
             callback(myWorld);
         });
     };
};

Running Locally

npm install
npm test