任何人都可以帮助我解决以下情况吗?
我必须执行一条select
语句并将查询结果存储在使用 Cypress 的变量中。
下面是我试过的代码。我想存储查询的结果
select id from invoices where INumber = '.invoiceNumber.'
到变量rec
。
请帮助我实现这一目标。
cy.task('sqlServer:execute',"select id from invoices where INumber = '.invoiceNumber.'")
.then(function (recordset) {
var rec = recordset
})
Run Code Online (Sandbox Code Playgroud)
小智 5
我可以给你举个例子。在测试 sepc.js
describe('test', () => {
it("test", () => {
cy.task("query", {
sql: `
select
id
from
invoice
`
}).then((resp) => {
console.log(resp.rows)
});
Run Code Online (Sandbox Code Playgroud)
在 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) {
}
}
});
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4564 次 |
最近记录: |