question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

this is not nightwatch api in step definition functions.

See original GitHub issue

I’m submitting a … (check one with “x”)

[x] bug report
[ ] feature request
[ ] support request => Please do not submit support request here, instead use https://groups.google.com/d/forum/nightwatch-cucumber

Current behavior

    "cucumber": "^1.3.1",
    "nightwatch": "^0.9.6",
    "nightwatch-cucumber": "^5.5.2",
// client/tests/e2e/steps/index.js
var debug = require('debug')('test/e2e/steps');

module.exports = function () {
    debug('loading');
    require('../parts/general').call(this, options);
    debug('ready');
};
// client/tests/e2e/parts/general.js
/*eslint no-param-reassign: "options" */
var debug = require('debug')('test/e2e/parts/general');

module.exports = function (options) {
    debug('loading');

    options = Object.assign({}, options);

    /**
     * Assert something displays the text
     * @param  {any} selector   xPath selector
     * @param  {String} text  text to confirm
     */
    this.Then('"$selector" should display "$text"',
        function assertTextIsDisplayed (selector, text, done) {
            debug('Then.assertTextIsDisplayed', selector);
            this.useXpath()
                getText(selector, function (result) {
                    this.assert.equal(typeof result, 'object');
                    this.assert.equal(result.status, 0);
                    this.assert.equal(result.value, text);
                    done();
                });
    });
}
...
   Step Definition: client/test/e2e/parts/general.js:16
   Message:
     TypeError: this.useXpath is not a function
...

Expected/desired behavior

That this inside a step definition be the nightwatch api.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
airtonixcommented, Oct 24, 2016

I beg to differ.

Without the callback, subsequent steps begin to execute before the current step has finished, this causing failure of my tests.

Essentially I 'm not sure I see the point of a step definition that can’t make use of the nightwatch api?

At the moment I’m on a tight deadline where every minute I spend costs the client money. I’ve already spent far too much time trying to workout why my tests were failing…

Some of my step definitions absolutely require some kind of asynchronous behaviour, that should be either one of : a generator, a Promise or a callback.

For now I had to roll back to an older version of your library. where I won’t have beforeEach or afterEach support.

0reactions
mucsi96commented, Nov 13, 2016

You can return promise in step definition. And it will async

this.Given(/^a user "([^"]*)"$/, function (name) {
    return fetch('http://another/api', {
      method: 'POST'
      body: { name },
    });
  });

Or you can you generators

this.Given(/^a user "([^"]*)"$/, function * (name) {
    yield fetch('http://another/api', {
      method: 'POST'
      body: { name },
    });
  });

Hope this helps. I will close the separately ceated issue #146

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developer Guide - Nightwatch.js
In depth guides on how to use Nightwatch to write and execute tests.
Read more >
client.elements is not working from a step definition using ...
I'm trying to do nightwatch and cucumber integration for BDD. I'm unable to access client.elements function in a step function. const { client...
Read more >
Using with Cucumber - Nightwatch API
For Cucumber to be able to understand and execute the feature file we need to create matching step definitions for every feature step...
Read more >
Crazy Powerful Nightwatch.js Cucumber Step Definitions
There are two problems with the smart step definition approach. First of all the backticks, which are used to mark selectors, destroy the...
Read more >
Need help regarding terminating session for each scenario ...
I have developed a framework using nightwatch along with cucumber. ... Now i have problem lets say last step definition of a test...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found