
Selenium2 WebDriverを使うとRubyなどでスクリプトを書くことができます。これが結構便利でCIサーバとも相性がいいので、クロスブラウザチェックするときの書き方をメモ。細かい話はWebDriverのドキュメントに書かれています。
IE、FireFoxi、Chromeでテストする場合の書き方
Chromeを動かす場合は、ここからchromedriver.exe を落としてきてPATHを通しておく必要があります。そして、以下を記述すればOK。
https://gist.github.com/daipresents/97509a466788036c908799ab780f31c1.js?file=gistfile1.txt
Proxyを通したい場合の書き方
Proxyを通したい場合は、ブラウザごとにやり方が異なります。
https://gist.github.com/daipresents/97509a466788036c908799ab780f31c1.js?file=gistfile2.txt
古いFireFoxでテストしたい場合の書き方
パスを指定することができるので、直にパスを書き込む。
https://gist.github.com/daipresents/97509a466788036c908799ab780f31c1.js?file=gistfile4.txt
IEが起動しない場合
org.openqa.selenium.WebDriverException: Unexpected error launching Internet Explorer. Protected Mode must be set to the same value (enabled or disabled) for all zones. (WARNING: The server did not provide any stacktrace information)
Selenium2のInternetExplorerDriverでエラーになったにもありますように、セキュリティ設定を揃える必要があります。
画面キャプチャを取得する
画像パスを引数にメソッドを呼び出すだけ。
https://gist.github.com/daipresents/97509a466788036c908799ab780f31c1.js?file=gistfile3.txt