7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

RSpec + Capybara + Selenium でUserAgent設定 備忘録

Posted at

設定

Gemfile
gem 'selenium-webdriver'
spec/rails_helper.rb

require 'selenium-webdriver'


# それぞれのUserAgentを持ったドライバを定義しておく
Capybara.register_driver :piyo_driver do |app|
  useragent = "piyo"
  capabilities = Selenium::WebDriver::Remote::Capabilities.chrome(
    chrome_options: {
      args: %W(headless disable-gpu window-size=1680,1050 user-agent=#{useragent})
    }
  )
  Capybara::Selenium::Driver.new(app, browser: :chrome, desired_capabilities: capabilities)
end

spec/features/piyo_spec.rb
require 'rails_helper'

# System Spec ができるようにまだしてない... :cry:

describe 'サンプルテスト' do
  it 'piyoというUserAgentでアクセスする', driver: :piyo_driver do
    # piyoというUserAgentが設定された状態でのテストができる
  end
end

参考

7
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?