在赛普拉斯/plugins/index.js我有代码来查询 oracleDBmodule.exports = (on, config) => { on('task', { 'registration': async (email) => { const oracledb = require('oracledb'); oracledb.initOracleClient({libDir: './oracleClient'}); let result; let connection; connection = await oracledb.getConnection( { user : process.env.ORACLEDB_USER, password : process.env.ORACLEDB_PASSWORD, connectString : "localhost/STORE" }); result = await connection.execute( "select ..." ); console.log(result.rows) var extractedUrlText = JSON.stringify((await result).rows).extract('/VerifiedRegistrationFormView','\"'); console.log('Extracted URL: \r\n' + extractedUrlText); return cy.wrap(extractedUrlText); } });}这会在 Node 终端中返回正确提取的 URL。但是在我的赛普拉斯测试中,当我尝试使用那个 extractedUrlText 字符串值时,我得到了错误cy is not defined:it('Register a new user', () => { cy.task('registration', emailAddress, { timeout: 10000 }).then(value => cy.log(value)) // cy is not defined })我使用类似的方法来使用返回值并且support/commands.js Cypress.Commands.add()它在那里工作,但不是来自 cy.task() 使用 cy.wrap()
1 回答

慕尼黑8549860
TA贡献1818条经验 获得超11个赞
我的工作解决方案:
/plugins/index.js从上面的代码扩展:
var extractedUrlText = JSON.stringify((await result).rows).extract('/VerifiedRegistrationFormView','\"');
console.log('Extracted NODE URL: \r\n' + extractedUrlText);
return extractedUrlText
}
在规范文件中:
let extractedUrl;
cy.task('registration', emailAddress).then(value => {
extractedUrl = value;
cy.log('Extracted CY URL: ' + extractedUrl)
})
结果:
添加回答
举报
0/150
提交
取消