CypressIO 使用 cy.wrap() 从 cy.task() 返回字符串值给出错误

在赛普拉斯/plugins/index.js我有代码来查询 oracleDB


module.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()

http://img4.mukewang.com/639315450001cd2d12660579.jpg

一只斗牛犬
浏览 117回答 1
1回答

慕尼黑8549860

我的工作解决方案:/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)        })结果:
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript