seleniumbase / SeleniumBase

📊 Python's all-in-one framework for web crawling, scraping, testing, and reporting. Supports pytest. UC Mode provides stealth. Includes many tools.
https://seleniumbase.io
MIT License
5.05k stars 946 forks source link

Ability to set user agent before test case #287

Closed cgpacifico closed 5 years ago

cgpacifico commented 5 years ago

I would like to be able to set the user agent for a given browser session (in this case, to verify that a mobile user agent receives a different version of the site.)

It is unclear if/how configurations set in browser_launcher could be adjusted on a per-case basis.

If this functionality exists, is it documented somewhere? For future development, a single driver-agnostic method to make this adjustment would be ideal.

mdmintz commented 5 years ago

Hi @cgpacifico , this functionality already exists. Please see the ReadMe file located in the following directory for capabilities details: https://github.com/seleniumbase/SeleniumBase/tree/master/examples/capabilities It will show you how to run any test with any user agent on any remote Selenium Grid, such as BrowserStack or Sauce Labs, which gives you the widest range of options for this.

mdmintz commented 5 years ago

As of seleniumbase v1.21.0, https://github.com/seleniumbase/SeleniumBase/releases/tag/v1.21.0, you can now pass a User-Agent string on the command line when running your tests to fake the User-Agent for the browser.

Example:

pytest user_agent_test.py --agent="Mozilla/5.0 (Nintendo 3DS; U; ; en) Version/1.7412.EU"
mdmintz commented 5 years ago

Closing this ticket as resolved!