Wednesday, 7 June 2017

Create wrapper function for cucumber-nightwatch

I want to wrap some functions with cucumber-nightwatch in custom JavaScript files. I tried to do the following (in controls.js):

const browser = require('nightwatch-cucumber');

var waitForElementVisibleAndClick = (selector) => {
  browser.waitForElementVisible(selector, 10000);
  browser.click(selector);
};

module.exports = {
  waitForElementVisibleAndClick
};

And after I want to use these wrapper function in tests:

const controlHelper = require('../helper/controls');

module.exports = {
  elements: {},
  commands: [{
    checkout() {
      return controlHelper.waitForElementVisibleAndClick(checkoutButton)
    }
  }]
};

But in execution I get the following error:

TypeError: browser.waitForElementVisible is not a function

How can I solve the problem. I have to say, that I'm new to JavaScript ;)



via Martin

No comments:

Post a Comment