使用cypress从数据库检索值 [英] Retrieve value from Database using cypress
本文介绍了使用cypress从数据库检索值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以在以下情况下为我提供帮助吗?
Can anyone help me with the below scenario?
我必须执行 select
语句并存储
下面是我尝试的代码。我想存储查询结果
Below is the code I tried. I want to store the result of the query
从INumber ='.invoiceNumber。'
的发票中选择ID变量 rec
。
select id from invoices where INumber = '.invoiceNumber.'
to variable rec
.
请帮助我实现这一目标。
Please help me to achive this.
cy.task('sqlServer:execute',"select id from invoices where INumber = '.invoiceNumber.'")
.then(function (recordset) {
var rec = recordset
})
推荐答案
我可以举一个例子。
在测试sepc.js中
I can give you an example. in test sepc.js
describe('test', () => {
it("test", () => {
cy.task("query", {
sql: `
select
id
from
invoice
`
}).then((resp) => {
console.log(resp.rows)
});
in index.js
in 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) {
}
}
});
}
这篇关于使用cypress从数据库检索值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文