如何在赛普拉斯中修改HTTP标头

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

我想修改HTTP标头,例如添加x-MSISDN和用户代理并给出解决方案

我尝试了下面的代码

    describe('The Home Page', function() {


  it('successfully loads', function() {

      cy.server()

      cy.route({
  method: "GET",
  url: "http://localhost:3000/sdp",
  headers: {
     "x-msisdn": "7845851265",
     "User-Agent": "Opera/9.80 (J2ME/MIDP; Opera Mini/8.0.35626/37.8186; U; ru) Presto/2.12.423 Version/12.16"
     }
})

    cy.visit('http://localhost:3000/sdp') // Dev URL 
    cy.get("[class='activateBtn']").click()
    expect('true').to.equal('true')
  })
})```

testing cypress
2个回答
0
投票

您可能想做这样的事情:

cy.server()

cy.route({
  method: [your_method e.g "GET"],
  url: [your_url e.g "/login"],
  headers: {
     'x-msisdn': '7845851265',
   ... etc ...
  }
})

0
投票

您可以使所有请求都添加自定义标头,如

cy.server({
  headers: {
    'x-token': 'abc-123-foo-bar'
  }
});

https://docs.cypress.io/api/commands/server.html#Options

© www.soinside.com 2019 - 2024. All rights reserved.