0

I'm running into an issue connecting to the database using cypress-postgres. The server has multiple databases along with multiple schemas. I tried multiple plugins, but can't find a solution that will allow me to specify a particular schema in a database. The server is reachable over the VPN.

I will need to do this with a SQL database.

For example: Database Example.

Error that is returned:

no relation for home

package.json has following dependencies:

  "name": "tests",
  "version": "1.0.0",
  "description": "Automated Tests",
  "main": "index.js",
  "scripts": {
    "cypress:open": "cypress open",
    "test": "cypress open"
  },
  "repository": {
    "type": "git",
    "url": 
  },
  "author": "Michael Frazier 
  "license": "ISC",
  "dependencies": {
    "@testing-library/cypress": "^8.0.2",
    "@testing-library/vue": "^5.8.2",
    "@vue/test-utils": "^1.3.0",
    "cypress-commands": "^2.0.1",
    "cypress-downloadfile": "^1.2.1",
    "cypress-postgres": "^1.1.1",
    "cypress-postgresql": "^1.0.8",
    "cypress-real-events": "^1.6.0",
    "pg": "^8.7.1",
    "pg-promise": "^10.5.8",
    "yarn": "^1.22.17"
  },
  "devDependencies": {
    "@4tw/cypress-drag-drop": "^2.1.0",
    "@babel/core": "^7.15.0",
    "@babel/preset-env": "^7.15.0",
    "@cypress/skip-test": "^2.6.1",
    "@cypress/webpack-preprocessor": "^5.9.1",
    "@testing-library/dom": "^8.11.2",
    "@types/chai": "^4.2.21",
    "@types/jest": "^27.0.1",
    "@types/mocha": "^9.0.0",
    "cy-mobile-commands": "^0.3.0",
    "cypress": "^9.5.3",
    "cypress-file-upload": "^5.0.8",
    "cypress-fill-command": "^1.0.2",
    "cypress-iframe": "^1.0.1",
    "cypress-mailosaur": "^2.6.0",
    "cypress-mochawesome-reporter": "^2.4.0",
    "cypress-msteams-reporter": "^1.0.3",
    "cypress-plugin-tab": "^1.0.5",
    "cypress-wait-until": "^1.7.2",
    "dayjs": "^1.10.6",
    "faker": "^5.5.3",
    "mysql": "^2.18.1",
    "pdf-parse": "^1.1.1",
    "webpack": "^5.51.1"
  }
}

cypress.json has DB credentials in following format:

{
  "trashAssetsBeforeRuns": true,
  "responseTimeout": 30000,
  "requestTimeout": 50000,
  "defaultCommandTimeout": 4000,
  "experimentalSourceRewriting": true,
  "experimentalStudio": true,
  "projectId": "aycmk8",
  "reporter": "cypress-mochawesome-reporter",
  "reporterOptions": {
    "reportDir": "cypress/report",
    "charts": true,
    "reportPageTitle": "Melos Report"
  },

  "db":
  {"user": "postgres",
    "host": "",
    "database": "",
    "password": "",
    "schemas": "sct",
    "port": 5432
  }
}

Plugin in cypress\plugins\index.js file:

module.exports = async (on, config) => {
  on('task',
    {dbQuery: (query)=> require('cypress-postgres')(query.query,query.connection)})

Spec file has following test:

describe("Database Health Tests", function () {

  it('should ping the database to ensure its active ', function () {
    cy.task("dbQuery", {"query":"select * from home"})
  });
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.