Custom Nightwatch.js for writing assertions against mssql databases in your test cases.
npm install nightwatch-mssql-assertionsjson
"test_settings": {
"default": {
"desiredCapabilities": {
"browserName": "chrome"
},
"globals": {
"dbUsername": "sa",
"dbPassword": "theDatabasePasswordGoesHere",
"dbAddress": "localhost",
"dbPort": 1433,
"dbName": "nightwatchDb"
}
}
}
`
$3
In the 2.x versions I've added the ability to _optionally_ pass the entire database configuration object for more flexibility and more advanced multi-environment test configurations and globals files.
_If the configuration object is not passed in as a third parameter in the command it will default to use the above example_
For example you could read the config out of globals.js for a specific staging environment database configuration.
`js
'Verify only one John Doe': function (browser) {
browser
.assert
.recordCountIs(1, "people", "first_name = 'John' AND last_name = 'Doe'",
browser.globals.env.staging.sql.userDb);
},
`
globals.js could look like this where you could have entries for staging and other environments or perhaps multiple different databases within the sql collection.
`js
env: {
staging: {
sql: {
userDb: {
user: "usernameHere",
password: "something secure",
server: "server123.myco.org",
port: 1433,
database: "users",
encrypt: true,
options: {
enableArithAbort: true,
encrypt: true,
trustServerCertificate: true // useful for self-signed certs in test environments
}
}
}
}
}
`
Writing Nightwatch tests with SQL assertions
This first publish adds the .recordCountIs(\expectedCount, tableName, whereClause--or null to return count of entire table\) assertion which allows you to verify a specified row/record count against a WHERE clause you specify.
Example:
`js
module.exports = {
"Database count test": function (browser) {
browser.assert.recordCountIs(
1,
"tableNameHere",
"myColumn = 'what I want'"
);
},
};
`
`sh
ā Testing if the record count (first_name = 'John' AND last_name = 'Wick') equals 0 (99ms)
ā Testing if the record count (first_name = 'John' AND last_name = 'Wick') equals 3 (103ms)
``