Selenium RCを使ってみる
- ダウンロード
- アーカイブファイル展開
- 起動・停止
- 実行
1.ダウンロード
次のサイトからSeleniumRCのアーカイブファイルをダウンロードします。
・Downloadサイト
Selenium Remote Control: Downloads
http://www.openqa.org/selenium-rc/download.action
・ダウンロードしたアーカイブ
selenium-remote-control-0.9.2-dist.zip
2.アーカイブファイル展開
適当なところにアーカイブファイルを展開します。
3.起動・停止
一旦、動作確認をしてみます。
DOSプロンプトを開き、上記2で展開したフォルダに移動し、次のコマンドでサーバを起動します。停止は、Ctrl+Cのようです。
問題なければ、動作環境が一通りそろった事になります。
4.テストケース実行
では、テストケースを自動実行してみます。次のコマンドで実行できます。
なお、事前にテストスイートファイルとテストケースファイルを用意しておきます。(今回使用したファイルは、下記の補足に記述しておきます。)
ここでは、ブラウザにFirefox、基準ディレクトリに"http://www.google.co.jp"、結果出力ファイルとして"result.html"を指定しています。
java -jar selenium-server-0.9.2\selenium-server.jar -htmlSuite "*firefox" "http://www.google.co.jp" "C:\Documents and Settings\hiro\デスクトップ\selenium-remote-control-0.9.2\testsuite.html" result.html
ブラウザ指定には、次の値が使用できるようです。
*iexplore
*konqueror
*firefox
*mock
*pifirefox
*piiexplore
*chrome
*safari
*opera
*iehta
*custom
注意
テストスイートファイルの指定では、絶対パスで指定する必要があるようです。相対パスだと、selenium-server.jarの中を検索してしまうようです。
補足2.今回使用したテストスイートファイル・テストケースファイル
テストスイートファイル(testsuite.html)
<html> <body> <table border="1"> <tr> <td>TestSuite</td> </tr> <tr> <td><a href="testcase001.html">testcase001</a></td> </tr> </table> </body> </html>
テストケースファイル(testcase001.html)
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>testcase</title> </head> <body> <table cellpadding="1" cellspacing="1" border="1"> <thead> <tr><td rowspan="1" colspan="3">testcase</td></tr> </thead><tbody> <tr> <td>open</td> <td>/</td> <td></td> </tr> <tr> <td>assertTitle</td> <td>Google</td> <td></td> </tr> <tr> <td>type</td> <td>q</td> <td>selenium</td> </tr> <tr> <td>clickAndWait</td> <td>btnG</td> <td></td> </tr> <tr> <td>assertTitle</td> <td>selenium - Google 検索</td> <td></td> </tr> </tbody></table> </body> </html>
私の動作環境
- OS: Windows XP
- Java Runtime Environment Version: 1.6.0_02