我正在尝试使用 cypress 连接 SQL 数据库,然后是 NPM guide .所有依赖项都完全如前所述,但在运行时
cy.sqlServer('SELECT Email FROM [MyDB].[dbo].[User] WHERE Name ="test"')
运行时出现如下错误。
CypressError: cy.task('sqlServer:execute') failed with the following error:
TypeError: No connection configuration given.
虽然我的 cypress.json 文件有我的数据库连接字符串。
Cypress .json
{
"baseUrl": "myurl",
"db": {
"userName": "test",
"password": "test",
"server": "test\\test",
"options": {
"database": "test",
"encrypt": true,
"rowCollectionOnRequestCompletion" : true
}
}
}
下面是我的plugins/index.js文件
const sqlServer = require('cypress-sql-server');
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
tasks = sqlServer.loadDBPlugin(config.db);
on('task', tasks);
}
最佳答案
对于任何像我一样寻找解决方法的人:
出于某种原因,Cypress(我使用的是 3.8.2,我不确定 cypress-sql-server 作者使用的是哪个版本)看不到“db”的自定义属性。
一种方法(您可以通过多种方式实现)是只需要插件文件中的 cypress 配置并从那里引用您的自定义属性。
要做到这一点,只需将 plugins/index.js 更改为如下所示:
const sqlServer = require('cypress-sql-server');
const dbConfig = require('../../cypress.json');
module.exports = (on, config) => {
tasks = sqlServer.loadDBPlugin(dbConfig.db);
on('task', tasks);
}
关于javascript - 使用 Cypress 连接到 SQL DB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57431534/