-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
modify user-agent on each call #364
Comments
We can add
Another option is to set userAgent headers at the network proxy layer. This would set it for all requests going to the current domain / origin under test but would not affect other traffic. Once we finish #684 users will be able to change the flags if we haven't finished implementing this yet. |
I really need this feature. My website varies based on user agent. |
Understood. You could achieve this right now by booting your server in that specific user agent mode so it serves all requests as if they all shared the same user agent. Also now that Cypress is open source you are welcome to submit a PR to add this functionality. |
@brian-mann I'd be willing to try my hand at a PR if you could please point me in the right direction in terms of where in the code should I be doing it. I see that Chrome/Chromium has a |
The problem is that you have to normalize this behavior across all browsers we support (or intend to support). For instance exposing the command line would work for Chrome but instantly fail for Electron. This issue has gained a lot of traction recently so I'll look to see if I can implement it in the next few days. Regarding exposing the flags - we plan on doing that with the Plugins API which is almost done. #684 If you did want to poke around it would be in |
Being able to specify user agent would also allow testing Ionic based projects in mobile mode. Ionic uses userAgent string and sets different styles and behavior for on Android/iOS projects. Does anyone have workarounds for the time being? |
Seems like the proposed implementation would set the user agent for all tests via the command line or configuration file (correct me if I'm wrong). I would need to set this dynamically for different tests in the suite. Would that be possible? |
The problem is that we could allow you to change the user agent dynamically (inside of tests) for Chrome and Electron, but it would not be possible to do this for the rest of the browsers. An alternative is if we did user agent modification at the network layer (outside of the browser) we could do this for all traffic coming from the origin under test - but other network requests (other than to origin) would not have their user agent set properly. Also the Dev Tools network panel would always indicate the wrong user agent (since it would be modified outside the browser in flight). The upside to this is that it would work on all browsers. I'm more in favor of not doing it at the network layer. I don't see needing to switch user agents within the same spec file very valuable. Instead you could simply partition your tests into mobile + non-mobile specs and then specifically run one or the other. Yes you wouldn't be able to run them all in one shot, but I don't see another solution that covers all the bases here. |
That makes sense. Thanks for the info @brian-mann! |
I personally wouldn't mind if only Chrome is supported. The main purpose for me is to test integration between our web application and hybrid mobile application (both running on different ports on localhost), as it is very time consuming to test. A simplified example could look like this: describe('change username', () => {
let userName = 'MyNewUser';
it('should change user name on web app', () => {
cy.visit(config.webAppUrl + '/profile');
cy.get('#new-username')
.type(userName);
});
it('should check if username was updated correctly', () => {
// for Ionic projects, this should change user agent too,
// because Ionic relies on it to detect correct platform.
cy.viewport('iphone-6');
cy.visit(config.mobileAppUrl + '/profile');
cy.get('#username')
.should('have.value', userName);
});
}); |
Requires documentation: cypress-io/cypress-documentation#328 |
Released in |
Should be able to modify user-agent string on each request.
This would give us more flexibility to work on apps that are modified version of chrome.
The text was updated successfully, but these errors were encountered: