Skip to content

Instantly share code, notes, and snippets.

@codenamev
Forked from anonymous/mobile_capybara.rb
Created December 20, 2012 16:20
Show Gist options
  • Save codenamev/4346353 to your computer and use it in GitHub Desktop.
Save codenamev/4346353 to your computer and use it in GitHub Desktop.
Capybara view as iphone helper. Change the user agent string to be whatever device you'd like. It's also possible to add view-port dimensions.
# 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