Skip to content

Instantly share code, notes, and snippets.

Created December 20, 2012 16:05
Show Gist options
  • Save anonymous/4346203 to your computer and use it in GitHub Desktop.
Save anonymous/4346203 to your computer and use it in GitHub Desktop.
Mock the user agent with Cucumber and Capybara using chrome
# put this in `features/support/env.rb`
Capybara.register_driver :chrome do |app|
args = []
args << "--user-agent='Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile /9A334 Safari/7534.48.3'"
Capybara::Selenium::Driver.new(app, {:browser => :chrome, :args => args})
end
Before('@mobile') do
Capybara.current_driver = :chrome
end
After('@mobile') do
Capybara.use_default_driver
end
# or you can set it in a step
# `features/step_definitions/mobile_steps.rb`
Given /^I use a mobile device$/ do
Capybara.current_driver = :chrome
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment