How to set the user agent in selenium tests


643
1 comment, 643 points
user agent in selenium tests
user agent in selenium tests

How to set the user agent in selenium tests

What is a User Agent?

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.

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 .

Advertisements

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

Happy Testing!


Like it? Share with your friends!

643
1 comment, 643 points
Test engineer

One Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.