when I execute browser.verify.myCustomAssertion(), and there is an error inside myCustomAssertion definition function, I expect that the error will be visible in the test runner output console, but what happens is that no output is written for the custom assertion as if there was no such line in the test case at all. Also, no error message is logged to the test runner output console.
When the same custom assertion run via .assert, browser.assert.myCustomAssertion(), the error is visible
Steps to reproduce
setup new nightwatch project - it comes with sample for custom assertion and examples of simple google search page object.
create new custom assertion in file /custom-assertions/myCustomAssertion.js - paste below content
create new test file in /test/custom/testCustomAssertion.js - paste below content
while in project directory, run nightwatch test using npx nightwatch --group custom
see that there should be error but no error is visible in the console output
change the .verify to .assert in the test case, or uncomment the line with the .assert
run the test again
see that the error is visible in the console output, but it should have been visible in step 5 as well.
files content
// .../test/custom/testCustomAssertion.js
describe('Test Custom Assertion', () => {
test('custom assertion should display error in the output console', async function testSouldShowError(browser){
const searchPage = browser.page.google.search()
await searchPage.navigate()
await browser.verify.myCustomAssertion('foo') // <---- should show error in console but swallows it.
// When running the same assertion via .assert, the error is visible in the
// output console as expected
// await browser.assert.myCustomAssertion('foo')
})
});
// .../custom-assertions/myCustomAssertion.js
/** A custom Nightwatch assertion. The assertion name is the filename. */
exports.assertion = function myCustomAssertion(expected = 'ok') {
/** when called, this function bound to AssertionInstance object */
this.api = 'this line throws Error, which is swallowed when assertion called under .verify, but visible when called under .assert'
// throw new Error('something went wrong')
// Message to be displayed on the console while running this assertion.
this.message = `Testing my custom assertion working`;
// Expected value of the assertion, to be displayed in case of failure.
this.expected = expected;
// Given the result value (from `this.value` below), this function will
// evaluate if the assertion has passed.
this.evaluate = function (value) {
return value === this.expected;
};
// Retrieve the value from the result object we got after running the
// assertion command (defined below), which is to be evaluated against
// the value passed into the assertion as the second argument.
this.value = function (result) {
return result.value;
};
// The command to be executed by the assertion runner, to find the actual
// result. Nightwatch API is available as `this.api`.
this.command = function (callback) {
const result = {
value: 'ok'
}
callback(result)
};
};
Sample test
test/custom/
describe('Test Custom Assertion', () => {
test('custom assertion should display error in the output console', async function testSouldShowError(browser){
const searchPage = browser.page.google.search()
await searchPage.navigate()
await browser.verify.myCustomAssertion('foo') // <---- should show error in console but swallows it.
// When running the same assertion via .assert, the error is visible in the
// output console as expected
// await browser.assert.myCustomAssertion('foo')
})
});
### Command to run
```bash
npx nightwatch --group custom
Description of the bug/issue
when I execute browser.verify.myCustomAssertion(), and there is an error inside myCustomAssertion definition function, I expect that the error will be visible in the test runner output console, but what happens is that no output is written for the custom assertion as if there was no such line in the test case at all. Also, no error message is logged to the test runner output console.
When the same custom assertion run via .assert,
browser.assert.myCustomAssertion()
, the error is visibleSteps to reproduce
npx nightwatch --group custom
files content
Sample test
Verbose Output
Nightwatch Configuration
No response
Nightwatch.js Version
3.4.1
Node Version
20.11.1
Browser
chrome (123.0.6312.59) on MAC
Operating System
MacOs 14.4 (23E214)
Additional Information
No response