So I needed to test a redirect that only happened for IOS devices. I had no idea how to accomplish this with a specific cucumber scenario. So I did what any good developer would do. I figured it out.
Here is how:
make a new file features/support/custom_user_agents.rb
Capybara.register_driver :iphone do |app| require 'selenium/webdriver' profile = Selenium::WebDriver::Firefox::Profile.new #Change the line below to change the user agent profile['general.useragent.override'] = "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A535b Safari/419.3" Capybara::Selenium::Driver.new(app, :profile => profile) end Capybara.use_default_driver
then tag your scenario with @iphone and it will automatically use the new selenium driver we just created! Other scenarios will still use the default driver. Hope this helps save someone some time.
Adam has worked with Isotope 11 for 4 years and has been a professional software developer for over 12 years. He has been lead developer on multiple Fortune 500 projects. He is the author of "Beginning Rails 4" which was published by Apress in September 2013.