使用Cypress任务为Postgres数据库中的变量赋值时出现问题
我试图从DB查询的结果中为变量赋值,设置了以下内容 关于Cypress.json使用Cypress任务为Postgres数据库中的变量赋值时出现问题,cypress,Cypress,我试图从DB查询的结果中为变量赋值,设置了以下内容 关于Cypress.json { "db": { "host": "localhost", "user": "postgres", "port" : 5432, "password": "postgres", "database": "
{
"db": {
"host": "localhost",
"user": "postgres",
"port" : 5432,
"password": "postgres",
"database": "5.0RC3"
}
}
关于index.js
const pg = require("pg");
module.exports = (on, config ) => {
on( "task", {
query ({ sql, values }) {
const pool = new pg.Pool(config.db);
try {
return pool.query(sql, values)
} catch (e) {
}
}
});
}
规范文件
/// <reference types="cypress" />
describe('Login', function(){
it('T01 - Failure Fields', function(){
cy.visit('https://localhost:8443/Perfo/#/'); // Visiting the website
cy.task("query", {sql: "SELECT username FROM users "}).then((resp) => {
const username = resp.username;
})
})
})
当我尝试运行spec文件时,我得到了以下错误:
我在cypress.json中提供了正确的用户名和密码,但它显示身份验证错误