Configuring User Agents with Capybara
You might end up working on apps that the entire version has really have UI features iPhone specific.
If you don’t have a native mobile infrastructure setup in place or services from a third party provided , what do you doto guarantee that you would also be testing the mobile version, we would have to simulate an iPhone user agent accessing the application.
You might be thinking that we are not able to change browser headers while dealing with Selenium. Capybara has a nice API to define new drivers and Selenium allows us to define different profiles with custom configurations for each Driver. Lets see how we can put all this together to handle that:
How to instantiate the browser:
Capybara.register_driver :iphone do |app|
require 'selenium/webdriver'
profile = Selenium::WebDriver::Firefox::Profile.new
profile['general.useragent.override'] = "iPhone"
Capybara::Selenium::Driver.new
(app, :profile => profile) end
We are just passing the :driver => :iphone
option to our scenario. Remember that the latest Capybara versions use RSpec metadata options and will apply the :driver
option automatically, changing the current driver to our registered :iphone
in this case. For more info please refer to Capybara’s README.
Specs example:
More about how to set an user agent in Selenium Webdriver you can check it out here or how to simulate mobile device with selenium webdriver using chrome driver.
Happy Testing!
The post Configuring User Agents with Capybara + Selenium Webdriver appeared first on TestingRepository.
This post first appeared on Testing Repository - Creating Testing, please read the originial post: here