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

Configuring User Agents with Capybara + Selenium Webdriver

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.

 So now, how do we make use of that new driver in our specs? Here comes a simple example:
Specs example:
scenario 'access info using modal', :driver => :iphone do
  visit /

  page.should have_no_css "#fwrapper"
  page.should have_no_content "34343 3343"

  within("header") { click_link "Phone" }

  within("#fwrapper") do
    page.should have_content "123455 33333"
  end
end

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

Share the post

Configuring User Agents with Capybara + Selenium Webdriver

×

Subscribe to Testing Repository - Creating Testing

Get updates delivered right to your inbox!

Thank you for your subscription

×