Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding user-agent when using cy.request #3873

Closed
AbdullahZN opened this issue Apr 3, 2019 · 6 comments
Closed

Overriding user-agent when using cy.request #3873

AbdullahZN opened this issue Apr 3, 2019 · 6 comments

Comments

@AbdullahZN
Copy link
Contributor

@AbdullahZN AbdullahZN commented Apr 3, 2019

Current behavior:

cy.request overrides the user-agent if it is provided in the options.headers object of the request

Desired behavior:

If the User-agent is explicitly set in options.headers object when using cy.request it should not be overwritten with the current browsing session's user-agent.

Steps to reproduce: (app code and test code)

e.g:

This implementation

cy.request({
  url,
  method: 'GET',
  headers: {
    'user-agent': 'test-agent',
  },
}).then(response => {
  expect(response.requestHeaders).to.have.property('user-agent', 'test-agent');
});

leads to:
Screen Shot 2019-04-03 at 17 10 44

Versions

Cypress: 3.1.5
OS: MacOS 10.13.3
Browser: Chrome - Version 73.0.3683.86

@AbdullahZN AbdullahZN changed the title overriding user-agent when using cy.request Overriding user-agent when using cy.request Apr 3, 2019
@AbdullahZN
Copy link
Contributor Author

@AbdullahZN AbdullahZN commented Apr 3, 2019

I already have a working PR to handle this if you guys are ok to integrate the feature.

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Apr 8, 2019

Hey @AbdullahZN, yes we would love an open PR - even one that is a work in progress is fine. Check out our contributing doc and ask us if you get stuck.

Also, you can set the userAgent as a configuration value in your cypress.json file - https://on.cypress.io/configuration#Browser

There's some explanation on why we implemented it this way here: #364

Also relevant issue regarding user-agent here: #3719

@AbdullahZN
Copy link
Contributor Author

@AbdullahZN AbdullahZN commented Apr 9, 2019

Thanks @jennifer-shehane, I just opened the PR for this feature.
Regarding cy.visit issue, it will require more work and I think should be part of another PR.
Does that sound right?

@jennifer-shehane
Copy link
Member

@jennifer-shehane jennifer-shehane commented Apr 24, 2019

Yes, that sounds right

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented May 1, 2019

The code for this is done in cypress-io/cypress#3920, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link

@cypress-bot cypress-bot bot commented May 17, 2019

Released in 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants