npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nightwatch-mssql-assertions

v2.2.0

Published

Custom Nightwatch.js for writing assertions against mssql databases in your test cases.

Downloads

39

Readme

nightwatch-mssql-assertions

Node.js Test

Custom Nightwatch.js assertions for writing tests against mssql databases

Why write tests against the database during testing?

When running NightwatchJS or browser-based selenium tests it can be useful to verify that actions done by the user or your automation on the front end correctly update the backend. This assertion library allows you to connect to an MSSQL database and write tests or checks against the database tables.

Full database testing tutorial using nightwatch-mssql-assertions

Installation instructions

In your Nightwatch test project

npm install nightwatch-mssql-assertions --save

In your Nightwatch.js nightwatch.json configuration add or append this entry

"plugins": ["nightwatch-mssql-assertions"]

Or, if you are using a Nightwatch version older than 2.0 that doesn't use the plugin pattern use this entry instead

"custom_assertions_path": ["./node_modules/nightwatch-mssql-assertions/nightwatch/assertions"]

The package looks for the database configuration inside the test_settings section of the nightwatch.json file. Add a globals section if it doesn't already exist inside one of your nested test_settings such as default for example.

"test_settings": {
        "default": {
            "desiredCapabilities": {
                "browserName": "chrome"
            },
            "globals": {
                "dbUsername": "sa",
                "dbPassword": "theDatabasePasswordGoesHere",
                "dbAddress": "localhost",
                "dbPort": 1433,
                "dbName": "nightwatchDb"
            }
        }
    }

Specific config passing

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.

'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.

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:

module.exports = {
  "Database count test": function (browser) {
    browser.assert.recordCountIs(
      1,
      "tableNameHere",
      "myColumn = 'what I want'"
    );
  },
};
√ 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)