Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to set the user agent in selenium tests

How to set the user agent in selenium tests

What is a User Agent?

Everyone that is browsing the web right now has a user Agent. It’s the software that acts as the bridge between you, the user, and the internet. It’s easiest to understand user agents if we backtrack and look at the evolution of the web, so we can understand the benefits of user agents. You might have to set different type of user agents , so today we will cover how to set the user agent in selenium tests.

The User-Agent HTTP header identifies the client and is sent by “regular” browsers, search engine crawlers, or other web client software.

User Agent Types

Here’s a list of some of the user agents you’ll encounter:

  • Browsers: Including Internet Explorer, Firefox, Safari, Chrome, Edge, BlackBerry, Opera, Minimo, Beonex and the AOL browser.
  • Crawlers: Google, Google Images, Yahoo! Slurp, and hundreds more.
  • Consoles: PlayStation 3, Wii, PlayStation Portable and Bunjalloo — the Nintendo DS’ built-in browser.
  • Legacy operating systems (for example, AmigaVoyager).
  • Offline browsers and similar (for example, Wget and Offline Explorer).
  • Link checkers (for example, W3C-checklink).
  • Plus a whole range of feed readers, validators, cloud platforms, media players, email libraries, and scripts.
Given /^my user agent is "(.+)"$/ do |agent|
  page.driver.browser.header('User-Agent', agent)
end

If you want to use firefox you should check first this stackoverflow article .

When you are using Chrome, you can spawn a new Chrome using the --user-agent command line switch.

Happy Testing!

The post How to set the user agent in selenium tests appeared first on TestingRepository.



This post first appeared on Testing Repository - Creating Testing, please read the originial post: here

Share the post

How to set the user agent in selenium tests

×

Subscribe to Testing Repository - Creating Testing

Get updates delivered right to your inbox!

Thank you for your subscription

×