项目作者: siddharth23

项目描述 :
Use this plugin to query Postgres database and use response in cypress tests
高级语言: JavaScript
项目地址: git://github.com/siddharth23/cypress-postgres.git
创建时间: 2020-08-07T19:02:01Z
项目社区:https://github.com/siddharth23/cypress-postgres

开源协议:

下载


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
  1. * 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)
});
};

  1. # How to use it
  2. To query postgres database follow below steps-
  3. * Add postgres database connection details in cypress.json file. Details like-

“db”:
{“user”: “postgres”,
“host”: “localhost”,
“database”: “postgres”,
“password”: “*“,
“port”:5432
}

  1. * 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}]”)
});

  1. * If you need to query multiple database you can also pass the connection from scripts like below-
  2. * Create connection in your scripts-

let connection={“user”: “postgres”,
“host”: “localhost”,
“database”: “postgres”,
“password”: “*“,
“port”:5432
}

  1. * 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

Siddharth Kala
Siddharth Kala

💻 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!