Pra*_*any 7 javascript sql database-connection npm cypress
我正在尝试按照NPM 指南使用 cypress 连接 SQL db 。所有的依赖项都和前面提到的完全一样,但是在运行这个的时候
cy.sqlServer('SELECT Email FROM [MyDB].[dbo].[User] WHERE Name ="test"')
Run Code Online (Sandbox Code Playgroud)
运行时出现如下错误。
CypressError: cy.task('sqlServer:execute') 失败,错误如下:
类型错误:未给出连接配置。
虽然我的 cypress.json 文件有我的数据库连接字符串。
Cypress.json
{
"baseUrl": "myurl",
"db": {
"userName": "test",
"password": "test",
"server": "test\\test",
"options": {
"database": "test",
"encrypt": true,
"rowCollectionOnRequestCompletion" : true
}
}
}
Run Code Online (Sandbox Code Playgroud)
下面是我的 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);
}
Run Code Online (Sandbox Code Playgroud)
小智 7
对于任何像我一样寻找如何解决这个问题的人:
由于某种原因,赛普拉斯(我使用的是 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);
}
Run Code Online (Sandbox Code Playgroud)
我猜问题出在"server": "test\\test"你的 Cypress.json 中。它可能应该类似于"server": "localhost","server": "localhost\\SQLExpress"或类似的东西。该值应与您在 Microsoft SQL Server Management Studio 的“连接到服务器”对话框中使用的值相同。