3
1

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.

テスト自動化ツール「selenium webdriver」最初の一歩

3
Last updated at Posted at 2017-12-27

Web開発を行っていると避けては通れないブラウザでのテスト。
Seleniumというツールを使って自動化したいと思います。

今回私はrubyのバージョンを変更したくない等の諸事情により仮想環境を新たに準備してそちらで行うようにしました。

  • ホストOS:Windows7
  • ゲストOS:ubuntu14.04
  • ruby2.1
  • selenium-webdriver 3.8.0

vagrantでubuntu環境を構築

偉大なる諸先輩方の記事を参考にさせていただきます。

最新バージョンとか調べずにやってしまったのでubuntu14を入れてしまいました。
最終的にseleniumさえ動けばいいので特に気にせず進めます。笑

rubyインストール

ruby2.1をインストール

ruby-devがないとgem installでエラーになるので入れる

$ sudo apt-get install ruby2.1-dev

selenium-webdriverインストール

$ sudo gem install selenium-webdriver
$ gem list|grep selenium
selenium-webdriver (3.8.0)

さっそくサンプルを実行してみる

$ vi sample.rb
$ cat sample.rb 
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
# driver.quit
$ ruby sample.rb 
/var/lib/gems/2.1.0/gems/selenium-webdriver-3.8.0/lib/selenium/webdriver/common/service.rb:57:in `binary_path':  Unable to find Mozilla geckodriver. 
Please download the server from https://github.com/mozilla/geckodriver/releases and place it somewhere on your PATH. 
More info at https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver. 
(Selenium::WebDriver::Error::WebDriverError)

はい、怒られました。
指示に従いまして、、、

$ wget https://github.com/mozilla/geckodriver/releases/download/v0.19.1/geckodriver-v0.19.1-linux32.tar.gz
$ tar -zxvf geckodriver-v0.19.1-linux32.tar.gz
$ sudo cp ./geckodriver /usr/local/bin

再チャレンジ

$ ruby sample.rb 

Firefoxが無事起動!\(^o^)/

【おまけ】

デフォルト設定のままだとプロンプトが長すぎるので変更する

$ cd
$ vi .bashrc

追記
export PS1="\u@ubuntu14 \W\$ "

設定変更を反映
$ source .bashrc
3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?