【问题标题】:How can I test the data in the request that is sent during cypress test?如何测试 cypress 测试期间发送的请求中的数据?
【发布时间】:2021-06-29 13:59:12
【问题描述】:

我有一个使用 mongodb 和 flask 作为后端的 Vue 应用程序。我正在尝试按如下方式测试代码。

如上图所示,有一个表格。当我输入 URL、令牌、密码、ssh 和项目名称并单击“创建”按钮时,我将它们添加到对象并在请求中将它们发送到数据库。

我想在 Cypress.js 中写入这些值(这部分已完成),然后单击创建按钮。单击创建按钮后,我想测试作为请求发送的数据。如何在柏树的请求中到达正文?

【问题讨论】:

    标签: vue.js cypress


    【解决方案1】:

    您可以使用cy.intercept() 查看出站请求。 Request object documentation here.

    cy.intercept('/some/url', (req) => {
        // whatever you need to do with the request object
        // for example, validating the request body has a name field
        expect(req.body.name).to.equal('My Body Object Name');
    
        // req.continue() tells the request to continue!
        req.continue()
    });
    

    【讨论】:

    • 非常感谢 :)
    猜你喜欢
    • 2021-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多