https://github.com/siddharth23/cypress-postgres
Use this plugin to query Postgres database and use response in cypress tests
https://github.com/siddharth23/cypress-postgres
cypress cypress-plugin cypress-tests postgres postgres-database postgresql postgresql-database queryresponse sql-query
Last synced: 10 months ago
JSON representation
Use this plugin to query Postgres database and use response in cypress tests
- Host: GitHub
- URL: https://github.com/siddharth23/cypress-postgres
- Owner: siddharth23
- Created: 2020-08-07T19:02:01.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-09T05:47:38.000Z (almost 3 years ago)
- Last Synced: 2025-04-01T16:33:16.221Z (10 months ago)
- Topics: cypress, cypress-plugin, cypress-tests, postgres, postgres-database, postgresql, postgresql-database, queryresponse, sql-query
- Language: JavaScript
- Homepage: https://github.com/siddharth23/cypress-postgres
- Size: 14.6 KB
- Stars: 7
- Watchers: 1
- Forks: 10
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cypress POSTGRES
Test sql query to your postgres database in cypress tests
Use this plugin to query postgres database and use response in cypress tests
# Installation
* Run below command in terminal to install the cypress postgres
```bash
npm i -D cypress-postgres
```
* Open your `cypress/plugins/index.js` file and register a new task
```
module.exports = on => {
on("task", {
dbQuery:(query)=> require("cypress-postgres")(query.query,query.connection)
});
};
```
# How to use it
To query postgres database follow below steps-
* Add postgres database connection details in cypress.json file. Details like-
```
"db":
{"user": "postgres",
"host": "localhost",
"database": "postgres",
"password": "*****",
"port":5432
}
```
* Use dbQuery task in your tests to query postgres database like below-
```
cy.task("dbQuery", {"query":"your sql query"}).then(queryResponse => {
expect(queryResponse).to.equal("[{Your expected query result}]")
});
```
* If you need to query multiple database you can also pass the connection from scripts like below-
* Create connection in your scripts-
```
let connection={"user": "postgres",
"host": "localhost",
"database": "postgres",
"password": "*****",
"port":5432
}
```
* And use this in your test scripts like below-
```
cy.task("dbQuery", {"query":"your sql query","connection":connection}).then(queryResponse => {
expect(queryResponse).to.equal("[{Your expected query result}]")
});
```
## Contributors
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!