Is there a programmatic way to change user agent in Cypress.io?

前端 未结 4 1827
盖世英雄少女心
盖世英雄少女心 2021-01-04 10:34

I have some ad calls that are only made on mobile devices. In Chrome, I can use Device Mode and simulate a mobile device, and the resulting ad call from the server is corre

4条回答
  •  暖寄归人
    2021-01-04 10:58

    Now cypress supports passing user agent in the header for cy.visit as well as cy.request:

    it('Verify Social Sharing Meta Tags', () => {
      cy.visit(portalURL + '/whats_new/140', {
        headers: {
          'user-agent': 'LinkedInBot/1.0 (compatible; Mozilla/5.0; Apache-HttpClient +http://www.linkedin.com)',
        }
      });
    
      cy.document().get('head meta[name="og:type"]')
        .should('have.attr', 'content', 'website');
    });
    

    https://on.cypress.io/changelog#3-3-0

提交回复
热议问题