top of page
  • Seema Nair

BDD Framework for NodeJS Applications

My previous blog refers to using WebDriverIO as the automation tool for NodeJS Application. In this blog, we will see how we can use BDD Framework along with WebDriverIO for NodeJS applications.

Cucumber is the automation tool that is based on Behaviour Driven Development(BDD). You can easily use cucumber features into JavaScript . Install cucumber.js, which is a JavaScript implementation for running cucumber specs on Node.js.

BDD Framework has three layers

1) Layer 1: Steps in Gherkin syntax

Gherkins is a business readable language that helps you describe the behaviour of your application. It supports many spoken languages. Gherkin is widely used in the agile methodology by product owners to describe the acceptance criteria for user stories. The same description in Gherkin syntax can be used by test engineers to automate tests in a easily readable format. Gherkin files should always be written in business language and not technical language

Gherkin Example :

Given I have logged into the application And I view my dashboard

Then I should be able to view my notifications

2) Layer 2: CucumberJS file for the Gherkin Steps:

You can create separate JS file for each page in the application to follow the Page Object Model(POM).


import { defineSupportCode } from 'cucumber';

var LoginMethods = require('../pages/');

defineSupportCode(({ Given, When, Then }) => {

When(/^I have logged into the application$/,



Then(/^I have successfully logged into the application$/,





import { defineSupportCode } from 'cucumber';

var DashboardMethods = require('../pages/');

defineSupportCode(({ Given, When, Then }) => {

When(/^I view my dashboard$/,



Then(/^I should be able to view my notificationst$/,





3) Layer 3: WebDriverIO methods with Chai framework for assertions.

import testData from "../constants/testData.json";

import { expect } from "chai";

module.exports = {

openPage: function() {





login: function(type) {

let username,password;

username = testData.login.validUserEmail

password = testData.login.validUserPwd





submitForm: function() {'#submit')

expect(browser.getText('#dashboardHeader')).to.eql("My Dashboard")



62 views0 comments
bottom of page