ひとまず、CC.rbでSelenium実行結果を見るところまで。
Seleniumrc_fuを使ったRailsアプリケーションのCIを、CC.rbを使って運用するための下準備についてのメモです。パス等は適当に読み替えてください。
サンプルアプリケーションでSeleniumrc_fu
- サンプルのRailsアプリを用意
- Seleniumrc_fuプラグインをインストール
- マルチスレッドでスポーンがどうたららしいので設定追加
- Seleniumテストを置くディレクトリを作成
- サンプルのスイートとテストケースとヘルパをコピー
- サンプルテストケースをリネーム
~$ rails test ~$ cd test ~$ script/plugin install svn://rubyforge.org/var/svn/pivotalrb/seleniumrc_fu/trunk ~$ echo "ActiveRecord::Base.allow_concurrency = true" >> config/environments/test.rb ~$ mkdir -p test/selenium ~$ cp vendor/plugins/seleniumrc_fu/example/test/selenium/* test/selenium/ ~$ mv test/selenium/characterization_test.rb test/selenium/sample_test.rb
- テストケースとヘルパを適当に(サンプル用に)修正
test/selenium/selenium_helper.rb
dir = File.dirname(__FILE__) require dir + "/../test_helper" require "seleniumrc_fu/selenium_helper" module Sample class SeleniumTestCase < SeleniumrcFu::SeleniumTestCase def silly_helper click_and_wait("link=About your application’s environment") end end end
test/selenium/sample_test.rb
require File.dirname(__FILE__) + "/selenium_helper" module SampleTest class IndexTest < Sample::SeleniumTestCase def test_index open_and_wait('/') assert_text_present("Welcome aboard") end end end
- ブラウザのパスをPATHに追加しながらテスト実行(Seleniumサーバーも自動で起動)
- Seleniumサーバーを終了
~$ PATH=/Applications/BonEcho.app/Contents/MacOS:$PATH rake selenium:test ... Running *firefox... Started . Finished in 5.259988 seconds. 1 tests, 1 assertions, 0 failures, 0 errors ~$ rake selenium:stop_servant
- 最後にリポジトリにコミット
~$ cd ~/tmp ~$ svnadmin create svn ~$ svn import test/ file:///Users/koshigoe/tmp/svn/test/trunk
CC.rbでビルド&チェック
- CC.rbを設置
- CC.rbにプロジェクト追加
~$ cd ~/tmp ~$ wget http://rubyforge.org/frs/download.php/27495/cruisecontrolrb-1.2.1.tgz ~$ tar xvzf cruisecontrolrb-1.2.1.tgz ~$ cd cruisecontrolrb-1.2.1 ~$ ./cruise add test --url file:///Users/koshigoe/tmp/svn/test/trunk
- カスタムビルドできる様にビルド設定を修正
- カスタムビルドのスクリプトを追加してコミット
projects/test/cruise_config.rb
... project.build_command = 'build_my_app.sh' ...
~$ cd ~/tmp ~$ rm -rf test ~$ svn co file:///Users/koshigoe/tmp/svn/test/trunk test ~$ cd test
test/build_my_app.sh
#!/bin/sh PATH=/Applications/BonEcho.app/Contents/MacOS:$PATH rake selenium:test
~$ svn add build_my_app.sh ~$ svn ps svn:executable on build_my_app.sh ~$ svn ci
- CC.rbのBuilder起動
- CC.rbのDashboardで結果を見る
~$ cd ~/tmp/cruisecontrolrb-1.2.1 ~$ ./cruise start
ブラウザで"http://localhost:3333/"にアクセスして、結果を眺める。
補足
selenium-serverが止められない
Seleniumテスト後に、付属の(?)"rake selenium:stop_servant"で止めようとすると、CC.rbのBuilderも落ちるらしい。selenium-serverをどうやって止めているかは、見てない。
まだ道半ば
実際にやりたい事が出来ているわけでもない。以下、TODOメモ。
- CC.rbのビルドスクリプトをきれいに書く
- CC.rbの通知の仕組みを有効活用
- Seleniumテストの書き方を把握しきれてない
- 本番等でのリリーステストにどうやって(RC用の)Seleniumテストを使うか
- Firefox以外のブラウザでのテスト
- selenium-serverの安定運用(動かし続けてどこまでもつか)
- リモートのGUI環境でテスト実行
- Seleniumrc_fuの設定パラメータを外でいじる方法
- 本当に問題なくSeleniumテストが出来ているのか(なんか沢山実行されてない?)
- Railsっぽく
- Rubyっぽく
- ほか、多数
次回があるかは不明です。会社のブログで(運用実績が出来るのを待ってから)まとめるかも?