User Agent – Adaptive Web Design

As we previously talked about RWD and AWD, its time to look at how we can simulate different user-agent behaviors using Selenium/Watir. We have to understand how to set preferences in Firefox profile to override user agent and also understand Chrome switches to do the same. There are enough # of posts and articles on how to override browser preferences and this post does NOT cover that. However write to me if you need help.


  • Create a Selenium webdriver profile for firefox
  • Get a random user agent from a list of available user agents (Read my previous post on the list that is available online)
  • Assign to firefox the randomly selected user agent
  • Resize the window with the new user agent
  • Move on with your scripts with the simulated user-agent and window size

Cucumber Scenario (useragent.feature)

Step Definitions (useragent.rb)


Overriding useragent in firefox

Overriding useragent in chrome

Closing Thoughts:

Combine the power of resizing windows with the capability to override user agents, we can simulate a bunch of behaviors, not limited to iphone, android devices too. Because once we identify the user-agent that sits on the device and we identify the resolution on the device, we can pretty much simulate that behavior through webdriver and test Automate. Read more on mobile devices RWD. Happy RWD/AWD Test Automation !