我正在尝试使用NPM指南后面的柏树连接SQL。所有依赖项都与前面提到的完全相同,但在运行以下操作时
cy.sqlServer('SELECT Email FROM [MyDB].[dbo].[User] WHERE Name ="test"')在运行过程中,我得到了如下错误。
CypressError: cy.task('sqlServer:execute')失败,出现以下错误: TypeError:没有提供连接配置。
虽然我的cypress.json文件有我的数据库连接字符串。
Cypress.json
{
"baseUrl": "myurl",
"db": {
"userName": "test",
"password": "test",
"server": "test\\test",
"options": {
"database": "test",
"encrypt": true,
"rowCollectionOnRequestCompletion" : true
}
}
}下面是我的插件/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);
}发布于 2020-04-10 20:36:37
对任何想要解决这个问题的人来说,就像我一样:
由于某种原因,cypress(我正在使用3.8.2,我不知道cypress-sql-server author使用的是哪个版本)没有看到“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);
}发布于 2019-08-13 07:41:16
我猜问题在你的Cypress.json中的Cypress.json中。它可能应该类似于"server": "localhost"、"server": "localhost\\SQLExpress"或类似的东西。该值应与中“连接到服务器”对话框中使用的值相同。
发布于 2022-05-09 13:41:33
我通过将配置移动到cypress.json中的env来修正它:
{
"env": {
"db": {
"host": "localhost",
"user": "sa",
"password": "xxxx",
"database": "CollateralSystem",
"port": 1433
}
}
}然后在plugins\index.js中:
module.exports = (on, config) => {
tasks = sqlServer.loadDBPlugin(config.env.db);
on('task', tasks);
};https://stackoverflow.com/questions/57431534
复制相似问题