Created
October 22, 2016 23:17
-
-
Save mmmpa/58274d027c7937faad7592fe58923d5d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# chromedriver configuration | |
# chrome の起動オプションが使える http://peter.sh/experiments/chromium-command-line-switches/ | |
default_args = %w( | |
--window-position=2560,0 | |
) | |
# ブラウザの外枠 (スクリーンショット撮って計測しよう) | |
chrome_frame_offset = { | |
w: 10, | |
h: 86 | |
} | |
# プリセットの商品のセッティングを使う場合。 | |
# DevTools で選べるモバイルから必要なものをピックアップ。 | |
[ | |
{name: 'Apple iPhone 6 Plus', w: 414, h: 736}, | |
{name: 'Google Nexus 7', w: 600, h: 960}, | |
].map { |configure| | |
configure[:w] += chrome_frame_offset[:w] | |
configure[:h] += chrome_frame_offset[:h] | |
configure | |
}.each do |configure| | |
Capybara.register_driver configure[:name].gsub(' ', '_').downcase.to_sym do |app| | |
Capybara::Selenium::Driver.new( | |
app, | |
browser: :chrome, | |
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome( | |
'chromeOptions' => { | |
args: [ | |
"--window-size=#{configure[:w]},#{configure[:h]}" | |
] + default_args, | |
mobileEmulation: {deviceName: configure[:name]} | |
} | |
) | |
) | |
end | |
end | |
# 独自のセッティングでモバイルモードを使う場合 | |
Capybara.register_driver :chrome_dummy_mobile do |app| | |
w = 320 | |
h = 1600 | |
Capybara::Selenium::Driver.new( | |
app, | |
browser: :chrome, | |
desired_capabilities: Selenium::WebDriver::Remote::Capabilities.chrome( | |
'chromeOptions' => { | |
args: [ | |
"--window-size=#{w + chrome_frame_offset[:w]},#{h + chrome_frame_offset[:h]}" | |
] + default_args, | |
mobileEmulation: { | |
deviceMetrics: { | |
width: w, | |
height: h, | |
pixelRatio: 2.0 | |
}, | |
userAgent: | |
'Mozilla/5.0 (iPhone; CPU iPhone OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1' | |
} | |
} | |
) | |
) | |
end | |
# 登録しておいた driver から選ぶ | |
Capybara.configure do |config| | |
config.run_server = false | |
config.default_driver = :apple_iphone_6_plus | |
config.app_host = 'http://googole.com/' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment