我是否可以记录在运行赛普拉斯测试期间的所有响应?

问题描述 投票:0回答:2

[当我运行cypress e2e测试时,应用程序发出XHR请求。如何记录所有这些请求和响应?我不想打扰这些要求。我要获得一个工件,其中包含测试期间做出的所有请求和响应。 Gitlab用作CI。

主测试代码如下所示。所有这些都是用户定义的命令,可与应用程序交互。与应用程序进行交互会导致提出不同的请求(例如,我单击一个按钮,这会导致请求)。

it('Make payment', () => {
       cy.login(login_name, pass)
       cy.typeOTPpinpad(secret)
       cy.makePayment('Currency', 'amount')
       cy.typeToken(secret)
       cy.logout()
     })

这是我尝试使用正则表达式来捕获请求的方式(id是唯一的,我需要使用正则表达式)。

https://<mysite>/home/payments/<currency>/confirm/* - asterisk is payment id.
cypress
2个回答
0
投票

Testrunner拥有以下信息:[“


0
投票

您可以抓住requestresponse并写到如下位置。我已将请求和响应写到fixture文件夹,如下所示:尝试以下操作,让我知道

it('Log request to a file',function(){
        cy.request({
            method: 'GET',
            url: 'url_here',
            headers: {
                'Content-Type': 'application/json',
            },
            body: {},
        }).then((request)=>{
        const someRequest =  JSON.stringify(request);
        console.log("hhhh"+someRequest);
        cy.writeFile('cypress/fixtures/testRequest.json', someRequest);
        })
    })

//以下是回应:

it('Log response to a file',function(){
        cy.request({
            method: 'GET',
            url: 'url_here',
            headers: {
                'Content-Type': 'application/json',
            },
            body: {},
        }).then((response)=>{
        const someResponse =  response.body;
        console.log("hhhh"+someResponse);
        cy.writeFile('cypress/fixtures/testResponse.json', someResponse);
        })
    })
© www.soinside.com 2019 - 2024. All rights reserved.