15
15

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.

Ubuntu + Ruby + Watir-webdriver で Google Chrome をエミュレート

Last updated at Posted at 2014-07-09

#概要

VM上でなど、CUI環境でUbuntuを使っている場合のブラウザエミュレーションの方法を紹介します。

#Watir-webdriverとは?

#導入手順

##Google Chromeのインストール

まず、CUIのみで使ってるとGoogle Chromeがないと思うので、入れます。

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
sudo apt-get update
sudo apt-get install -y google-chrome-stable

##chromedriverのインストール
参考:https://code.google.com/p/selenium/wiki/ChromeDriver

sudo apt-get install unzip
wget http://chromedriver.storage.googleapis.com/2.20/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver
rm chromedriver_linux64.zip

ちなみに、Mac OS Xの場合は brew install chromedriver とします

##Xvfbのインストール
ブラウザをエミュレートするために、仮想ディスプレイが必要です。

sudo apt-get install xvfb

##Gems

gem install headless
gem install watir-webdriver

#使い方

require 'headless'
require 'watir-webdriver'

headless = Headless.new
headless.start
browser = Watir::Browser.new :chrome
browser.goto('https://www.google.com')
browser.close
headless.destroy
15
15
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
15
15

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?