LoginSignup
2
2

More than 5 years have passed since last update.

Rspec+SeleniumでChromeを動かしてテストを行う方法(Chromeはcaskでインストール)

Posted at

備忘録として。
Rspec + SeleniumでChromeのWebDriverを用いてテストする。
Chromeは例外的にHomebrew caskでインストールしたものを使っている。

require "selenium-webdriver"

describe "TestSpec" do
    before do
        #chromeのパスを設定
        chrome_path = '/Users/自分のホーム/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome'
        #Selenium::WebDriver::Chrome::Binary.path = chrome_path
        @webdriver = Selenium::WebDriver.for :chrome
    end

    it "GoogleのタイトルがGoogleであること" do
        @webdriver.navigate.to "http://www.google.co.jp"
        @webdriver.title.should == "Google"
    end

    after do
        @webdriver.quit
    end
end

上記のソースだけではWebDriverがないのでエラーになる。WebDriverは以下のページからダウンロードし、Pathを通すことでテスト可能になる。
https://sites.google.com/a/chromium.org/chromedriver/

caskでインストールしたfirefoxでもおそらく同じことができるはず(試していない)。safariは手続きが面倒そうなので試していない。

2
2
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
2
2