Standing on the Shoulder of Linus

Home / 2013 / 5月 / 23 / casperjs を用いて結合テスト( Novius OS をインストール)

casperjs を用いて結合テスト( Novius OS をインストール)

casperjs を用いて Novius OS をインストールする方法です。

casperjs は、自動テストやスクレイピングを行うツールです。コマンドラインから実行すると、ブラウザをエミュレートして、予め指定した操作を行います。casperjs 実行するには phantomjs も必要らしいです。

Novius OS では、https://github.com/novius-os/ci に、継続的インテグレーションツールが公開されています。この中に、casperjs を使用した結合テストが書かれています。

casperjs を使用してインストールする方法を試してみました。

まず、http://docs.novius-os.org/en/0.2/install/install.html#quick-installation に従って Novius OS のコードを取得します。

cd /var/www
sudo wget http://raw.github.com/novius-os/ci/master/0.2/tools/install.sh && sh install.sh

その後、Novius OS のルートフォルダに、https://github.com/novius-os/ci をコピーします。

下記のコードを実行します。なおドメインは http://novius-os/ と仮定しています。またデータベースのユーザー名/パスワード、Novius OS インストール時に登録するユーザーのユーザー名/パスワードは、./ci/tests/casperjs/install.js で指定してください。

DISPLAY=:99.0 ./ci/casperjs/bin/casperjs test ./ci/tests/casperjs/install.js --direct --log-level=info --fail-fast --includes=./ci/tests/casperjs/pre.js --base_url='http://novius-os/'

成功すると、下記のようになります。

install-travis

コマンドラインに表示されたログです。

[info] [phantom] Starting...
Test file: ./ci/tests/casperjs/install.js                                       
[info] [phantom] Starting...
[info] [phantom] Running suite: 7 steps
[info] [phantom] Step 2/7 http://novius-os/install.php (HTTP 200)
[info] [phantom] Step 2/7: done in 304ms.
[info] [phantom] Step 3/8 http://novius-os/install.php (HTTP 200)
[info] [phantom] Step 3/8: done in 405ms.
[info] [phantom] waitFor() finished in 200ms.
[info] [phantom] Step 4/9 http://novius-os/install.php (HTTP 200)
PASS Move on to the next step is found
[info] [phantom] Step 4/9: done in 715ms.
[info] [phantom] Step 5/9 http://novius-os/install.php?step=2 (HTTP 302)
[info] [phantom] Step 5/9: done in 906ms.
[info] [phantom] Step 6/10 http://novius-os/install.php?step=2 (HTTP 302)
[info] [phantom] Step 6/10: done in 1005ms.
[info] [phantom] waitFor() finished in 200ms.
[info] [phantom] Step 7/11 http://novius-os/install.php?step=2 (HTTP 302)
PASS Step 2 loaded
[info] [remote] attempting to fetch form element from selector: 'form'
[info] [remote] submitting form to unknown, HTTP POST
[info] [phantom] Step 7/11: done in 1330ms.
[info] [phantom] Step 8/11 http://novius-os/install.php?step=3 (HTTP 302)
[info] [phantom] Step 8/11: done in 3107ms.
[info] [phantom] Step 9/12 http://novius-os/install.php?step=3 (HTTP 302)
[info] [phantom] Step 9/12: done in 3206ms.
[info] [phantom] waitFor() finished in 200ms.
[info] [phantom] Step 10/13 http://novius-os/install.php?step=3 (HTTP 302)
PASS Step 3 loaded
[info] [remote] attempting to fetch form element from selector: 'form'
[info] [remote] submitting form to unknown, HTTP POST
[info] [phantom] Step 10/13: done in 3530ms.
[info] [phantom] Step 11/13 http://novius-os/install.php?step=4 (HTTP 302)
[info] [phantom] Step 11/13: done in 4106ms.
[info] [phantom] Step 12/14 http://novius-os/install.php?step=4 (HTTP 302)
[info] [phantom] Step 12/14: done in 4205ms.
[info] [phantom] waitFor() finished in 201ms.
[info] [phantom] Step 13/15 http://novius-os/install.php?step=4 (HTTP 302)
PASS Step 4 loaded
[info] [phantom] Step 13/15: done in 4525ms.
[info] [phantom] Step 14/15 http://novius-os/admin/nos/login?redirect=admin/?tab=admin/noviusos_appmanager/appmanager (HTTP 302)
[info] [phantom] Step 14/15: done in 5015ms.
[info] [phantom] Step 15/16 http://novius-os/admin/nos/login?redirect=admin/?tab=admin/noviusos_appmanager/appmanager (HTTP 302)
[info] [phantom] Step 15/16: done in 5119ms.
[info] [phantom] waitFor() finished in 200ms.
[info] [phantom] Step 16/17 http://novius-os/admin/nos/login?redirect=admin/?tab=admin/noviusos_appmanager/appmanager (HTTP 302)
PASS Login form is found
[info] [remote] attempting to fetch form element from selector: '#login form'
[info] [remote] submitting form to unknown, HTTP POST
[info] [phantom] Step 16/17: done in 5439ms.
[info] [phantom] Step 17/17 http://novius-os/admin/?tab=admin/noviusos_appmanager/appmanager (HTTP 302)
[info] [phantom] Step 17/17: done in 6196ms.
[info] [phantom] Step 18/18 http://novius-os/admin/?tab=admin/noviusos_appmanager/appmanager (HTTP 302)
[info] [phantom] Step 18/18: done in 6490ms.
[info] [phantom] waitFor() finished in 685ms.
[info] [phantom] Step 19/19 http://novius-os/admin/?tab=admin/noviusos_appmanager/appmanager (HTTP 302)
PASS Applications manager is loaded
[info] [phantom] Step 19/19: done in 7283ms.
[info] [phantom] Done 19 steps in 7375ms
PASS 6 tests executed in 7.385s, 6 passed, 0 failed. 

インストール作業は、画面遷移もあるのですが、きちんと処理して、インストール作業を行ってくれます。

作業途中で失敗した場合は、失敗した時点のスクリーンショットを自動生成し、画像を保存してくれます。

関連

Posted in cms | Tagged cms, 継続的インテグレーション, 自動テスト
← AGPL ライセンス(GPLとは似ているが違いもある) FuelPHP 1.6 翻訳ウィーク →

アーカイブ

人気の投稿とページ

  • キンドル本を印刷する(PDFに変換する)方法
  • 名古屋駅から国際センターまでの道のり(徒歩)
  • AGPL ライセンス(GPLとは似ているが違いもある)
  • 6年使ったイーモバイル(Y!mobile)を解約手続。店頭でSIM返却
  • JP-Secure SiteGuard WP Pluginは不正ログイン防止に役立つか

プロフィール

水野史土:月70万PVホームページ制作会社のレスキューワーク株式会社で、PHPソフトウェアのサポートを行っている。concrete5コミュニティリーダー、Novius OSコアコード貢献者でもある。 詳しくは管理者詳細参照。
大好評WordPress書籍「WordPressユーザーのためのPHP入門 はじめから、ていねいに。」サポートページ

Copyright © 2015 Standing on the Shoulder of Linus.