Coder Social home page Coder Social logo

cucumber-mink's Introduction

Cukes

NPM Version Build Status Test Coverage

Introduction

cucumber-mink is a cucumber-js step definition library. You can run your test with any Selenium compatible browser like Phantomjs !

40+ available steps

Prerequisites

Quick start

Launch the headless browser (default configuration is Phantomjs)

phantomjs -w

Install cucumber-mink library locally

npm install --save cucumber-mink

Create mink.js file a the root of your project

var mink = require('cucumber-mink');

module.exports = function () {
  mink.call(this);
};

Use pre-defined steps in your features/__.feature files

// features/home.feature
Feature: I can use cucumber.mink to check the content of my website

  Background:
    Given I browse "http://localhost:3000"

  Scenario: Check Homepage content
    Given I am on the homepage
    And   I should see "Welcome to my awesome application" in the "h1" element

Run your tests

cucumber-js --require mink.js

Run a specific scenario based on the line of scenario

cucumber-js --require mink.js features/test.feature:<LINE_NUMBER>

You can use an environment variable and then reference it in your features files to set the base url of your application.

export CUCUMBER_URL=http://localhost:3000
...
  Background:
    Given I browse "${CUCUMBER_URL}"
    
  Scenario:
    Given I am on "/post/2"
...

Override to standard Cucumber

The standard step definition methods are overridden by cucumber-mink so that it's easier to call the driver.

#####World.defineStep(String pattern, Fn(Driver, [] stepsInput, Fn cb)) The driver object is injected as the first arguments in the step function. This avoid heavy use of this keyword. This affects also siblings methods : World.Given, World.Then, World.When.

Meta-steps builder

I order to keep your features files clean and to follow the DRY principle you can declare your own "Meta" steps that will execute several basic steps available in this library.

Here is an example of how to create a "I am logged in" step for your test suite:

So the initial multi-steps scenario to log into the application could be:

Given I am on "/login"
  And I fill in the following:
    | input.username | test@test.com |
    | input.password | test          |
  And I press "Login"

And we want to write in our tests only a one liner like:

Given I am logged in

Usage

#####Mink.metaStep(Driver, [] stepsArray, Fn callback) Call multiple callback function in one step effectively creating a "meta" steps. StepsArray should be an Array of objects like:

var stepsArray = [
  {
    stepFunc: Ext.Navigation.browse,
    args: ['/form']
  },
  {
    stepFunc: Ext.Action.click,
    args: ['button[type="submit"]']
  }
];

Example

Inside your features/ folder, create a new step_definitions/ folder. Step definitions are the glue between features written in Gherkin and the actual SUT (system under test). They are written in JavaScript. Create a login.js file like this:

// features/step_definitions/login.js

var Mink = require('cucumber-mink'),
    Ext  = Mink.Ext;

/////////////////////////

function login (Driver, callback) {

  var loginFormArray = [
    { field: 'input.username', value: '[email protected]' },
    { field: 'input.password', value: 'test' }
  ];

  var stepsArray = [
    {
      stepFunc: Ext.Navigation.browse,
      args: ['/login']
    },
    {
      stepFunc: Ext.Form.fillFields,
      args: [loginFormArray]
    },
    {
      stepFunc: Ext.Action.click,
      args: ['Login']
    }
  ];

  return Mink.metaStep(Driver, stepsArray, callback);
}

/////////////////////////

module.exports = function() {
  this.Given(/^I am logged in$/, login);
};

Now, use your newly defined step inside a .feature file:

Scenario: I log into the application and see my dashboard
  Given I am logged in
  Then I should be on "/dashboard"

Important, don't forget to launch your test suite with the correct command: in this case

cucumber-js --require mink.js --require features/step_definitions/

You can pass in any function inside the stepFunc field, here we use Mink's function available in lib/step_definitions/ext. There is a complete example here: meta.js

Driver

cucumber-mink comes with support for WebDriverIO out of the box:

  • WebDriverIO - webdriver module for Node.js. webdriverio. This driver allow you to communicate with any Selenium compatible grid/hub. The driver default settings use Phantomjs/GhostDriver.

var parameters = { driver: { type: 'webdriverio', options : { desiredCapabilities: { browserName: 'phantomjs' }, logLevel: 'silent', port: 8910 } } }; ```

This driver can be used to communicate with various browser, like a locally running [Chrome](https://code.google.com/p/selenium/wiki/ChromeDriver) 
or on some distant services like [SauceLabs](https://saucelabs.com/) and [BrowserStack](http://www.browserstack.com/). See [examples](examples/)

Code Quality

Dependency Status Codacy Badge Code Climate

Maintainers

The npm module for this library is maintained by:

List of all contributors

License

MIT

cucumber-mink's People

Contributors

arnaud-dezandee avatar gvianot2 avatar jbelfodil avatar rmat0n 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.