cypress postgresql server
npm install cypress-postgresqlpackage.json dependencies
"cypress-postgresql": "*"
`
or use npm install and save
`
npm install --save cypress-postgresql
`
Configure
Plugin file
The plug-in can be initialised in your cypress/plugins/index.js file as below.
`
const postgreSQL = require('cypress-postgresql');
const pg = require('pg');
const dbConfig = require('../../cypress.json');
module.exports = (on, config) => {
const pool = new pg.Pool(dbConfig.db);
tasks = postgreSQL.loadDBPlugin( pool );
on('task', tasks);
}
`
Commands file
The extension provides multiple sets of commands. You can import the ones you need. Example support/index.js file.
`
import postgreSQL from 'cypress-postgresql';
postgreSQL.loadDBCommands();
`
cypress.json
Your cypress.json (or environment specific files in the config directory) should specify the DB redentials in the following format
"db": {
"user": "",
"password": "",
"host": "",
"database": ""
}
Usage
cy.sqlServer(query)
`
cy.postgresql(SELECT 'test' FROM 'Test').should('eq', 'test');
`
Testing
Run
npm test` to execute Cypress tests. Note that DB credentials will need to be provided in your cypress.json file first.