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 · Fixed by #3920
Closed

Overriding user-agent when using cy.request #3873

AbdullahZN opened this issue Apr 3, 2019 · 6 comments · Fixed by #3920

Comments

@AbdullahZN
Copy link
Contributor

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

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 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

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?

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review stage: work in progress and removed stage: work in progress stage: needs review The PR code is done & tested, needs review labels Apr 10, 2019
@jennifer-shehane
Copy link
Member

Yes, that sounds right

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: work in progress labels Apr 30, 2019
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels May 1, 2019
@cypress-bot
Copy link
Contributor

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
Contributor

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
Development

Successfully merging a pull request may close this issue.

2 participants