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.

Confusing error message

See original GitHub issue

I have the following scenario (greatly simplify to demonstrate the issue):

shared.js -- can be reused in multiple page objects:
module.exports = function Shared() {
    return {
        selector: 'form',
        sections: {
            field: {
                selector: '.field',
                elements: {
                    label: '.label',
                },
                commands: [{
                    verify: function (input) {
                        this
                            .waitForElementVisible('@value');
                    },
                }],
            },
        },
    };
};
test.js--page object that uses shared.js:
var Shared = require('./shared');

module.exports = {
    sections: {
        form: {
            selector: '.test',
            sections: {
                shared: new Shared(),
            },
        },
    },
};
test1.js -- uses the test.js page object, which included the shared PO code:
module.exports = {
    before: function (browser) {
        browser.test = browser.page.test();
    },
    after: function (browser) {
        browser.end();
    },
    'Do something': function (browser) {
    },
};
test2.js -- uses the test.js page object, which included the shared PO code:
module.exports = {
    before: function (browser) {
        browser.test = browser.page.test();
    },
    after: function (browser) {
        browser.end();
    },
    'Do something': function (browser) {
    },
};

NOTE: Both test1.js and test2.js are under a group directory (e.g. groupTest)

Running the above with our test server…something like this:

node test/e2e/server.js --env default --config ./test/e2e/nightwatch.json --group test/e2e/tests/groupTest

results in the following:

Error: The command "AssertionError" is already defined!
    at addCommand (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\command-wrapper.js:162:19)
    at C:\Users\git\prs\node_modules\nightwatch\lib\page-object\command-wrapper.js:147:48
    at Array.forEach (native)
    at C:\Users\git\prs\node_modules\nightwatch\lib\page-object\command-wrapper.js:146:33
    at Array.forEach (native)
    at applyCommandsToTarget (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\command-wrapper.js:139:27)
    at module.exports.commandName.addWrappedCommands (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\command-wrapper.js:184:5)
    at new Section (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\section.js:31:18)
    at C:\Users\git\prs\node_modules\nightwatch\lib\page-object\page-utils.js:65:34
    at Array.forEach (native)
    at module.exports.createSections (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\page-utils.js:61:27)
    at new Section (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\section.js:28:6)
    at C:\Users\git\prs\node_modules\nightwatch\lib\page-object\page-utils.js:65:34
    at Array.forEach (native)
    at module.exports.createSections (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\page-utils.js:61:27)
    at new Section (C:\Users\git\prs\node_modules\nightwatch\lib\page-object\section.js:28:6)

That’s an extremely confusing error when the simple fix is to replace the following line in shared.js:

verify: function (input) {

to something else…for example:

verifyX: function (input) {

Perhaps verify is a reserved word in nightwatch?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

1reaction
scottymocommented, Feb 2, 2017

Like @vietnogi , very glad I found this page… I ran into the same problem, and naming my PO command to something other than “verify” fixed it.

@zelein My guess is that in your case, you may have done an “npm update” or “npm install” that pulled down new versions of your node packages, and somewhere in the new packages it pulled down was code that defined a verify() function (probably in the NightwatchJS code related to initializing page objects… not sure though).

In my case, I would not get the error the first time I created the page object that had a verify() function. But the second time in the code that created that PO–boom! Confusing “Error: The command “AssertionError” is already defined!”.

Anyways, thanks a bunch @webteckie for posting this, you saved me a lot of time digging around the code to try to find the problem!

0reactions
stale[bot]commented, Nov 14, 2018

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Weird Error Messages | TechRepublic
In this gallery, we'll take a look at 24 confusing or weird error messages. Images by Greg Shultz for TechRepublic.
Read more >
Error Messages: Examples, Best Practices & Common Mistakes
4 common mistakes with error messages · 1. Ambiguity · 2. Condescending language/blaming the user · 3. Poor placement of error messages ·...
Read more >
Confusing error messages: expected N arguments #42891
There are several weird things going on here: fs.createWriteStream(output) is squiggled and the error produced is Expected at least 1 arguments, ...
Read more >
6 Form Error Message Mistakes Almost Everyone Makes
Discover the most common mistakes when it comes to creating error messages for your web forms and learn how to correct those errors...
Read more >
How to Write Good Error Messages - UX Planet
Write error message in clear and simple language. User should be able to understand the problem while reading an error message. If error...
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