javascript - 使用 Cypress 连接到 SQL DB
问题描述
我正在尝试按照NPM 指南使用 cypress 连接 SQL db 。所有依赖项都与提到的完全相同,但在运行时
cy.sqlServer('SELECT Email FROM [MyDB].[dbo].[User] WHERE Name ="test"')
我在运行时收到如下错误。
CypressError: cy.task('sqlServer:execute') 失败并出现以下错误:
TypeError:没有给出连接配置。
虽然我的 cypress.json 文件有我的数据库连接字符串。
赛普拉斯.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);
}
解决方案
对于任何像我一样寻找如何解决这个问题的人:
出于某种原因,赛普拉斯(我使用的是 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);
}
推荐阅读
- html - 我如何使 img 的顶部有边界半径,但没有它的底部?
- c - printf("%a"): 十六进制浮点常量的格式和参数如何选择?
- flutter - 如何在颤动中为浮动操作按钮设置自定义位置?
- typescript - 打字稿动态导入打字
- java - SOAPwsdl2java 错误“org.apache.axis2.AxisFault:故障消息的部分‘故障’必须用‘element=QName’而不是‘type=QName’定义”
- django - Django Rest Framework:如何动态返回字段子集
- express - CPanel 上的 Express Rest API
- oracle - 在 Ubuntu 18.04 上安装 Oracle 数据库
- c# - 重用 IAsyncEnumerable 实例而无需再次迭代
- android - 在android中使用firebase DB实现重复电子邮件检查时,条件满足后在哪里调用方法?