在賽普拉斯/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()
CypressIO 使用 cy.wrap() 從 cy.task() 返回字符串值給出錯誤
一只斗牛犬
2022-12-09 18:59:53