LocalPC(WindowsXP) から Selenium でWebアプリケーションのテストを自動化する
Webアプリケーションの再帰テスト(リグレッションテスト)を自動化してコストを削減することと、
LocalPC(WindowsXP)内でテストが完結する環境を構築することを目的として本エントリーを記述します。
- 前準備
Webアプリケーションを構築済み。 Webアプリケーションに対する(シナリオ)テスト項目表を用意済み。
フォルダのパスに半角(全角も?)スペースが入らないように注意! 良い例) C:\tmp\SeleniumTest\source
-
-
- Selenium Core ダウンロード/配置
-
http://www.openqa.org/selenium-core/download.action の Selenium core を適当なフォルダにダウンロードする。 展開して、selenium-server.jar を 1-2. の SeleniumTestフォルダにコピーする。 ex) C:\tmp\SeleniumTest\selenium-server.jar
- テスト(シナリオ)ファイル作成
- インデックスファイル
- C:\tmp\SeleniumTest\source\index.html
- インデックスファイル
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>TestSuite</title> </head> <body> <table border="1"> <tr><td>Selenium test</td></tr> <tr><td><a href="test1.html">test1</a></td></tr> </table> </body> </html>
-
- テストシナリオファイル
http://wiki.openqa.org/display/SEL/Selenium+0.7+Reference+%28Japanese%29 http://www.thinkit.co.jp/cert/article/0705/2/5/Selenium_com.pdf を参考にしてゴリゴリ書いていきます。 このとき、ページをロードするアクションを記述する際に、HTMLのタグに id, name, link がないと、DOM, xpathで記述する必要が出てきて手間が掛かります。 C:\tmp\SeleniumTest\source\test1.html <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>test case1</title> </head> <body> <table cellpadding="1" cellspacing="1" border="1"> <thead> <tr><td rowspan="1" colspan="3">test case1</td></tr> </thead><tbody> <tr> <td>open</td> <td>http://hogehoge/ <td></td> </tr> <tr> <td>assertTitle</td> <td>title: hogehoge</td> <td></td> </tr> <tr> <td>clickAndWait</td> <td>id=list</td> <td></td> </tr> <tr> <td>assertTitle</td> <td>title: list</td> <td></td> </tr> </tbody> </table> </body> </html>
rem --------------------------------------------------- rem Selenium RC - execute testsuite bat file rem --------------------------------------------------- rem ***** プロキシを使用している場合、アドレス(IP又はドメイン)とポートを指定する ***** #set PROXY_OPTION=-Dhttp.proxyHost=proxy-server-name -Dhttp.proxyPort=port-number rem ***** selenium-serverディレクトリを指定する ****** set SELSERV_DIR=%CD% rem ***** ブラウザを指定 ***** set BROWSER="*iexplore" #set BROWSER="*firefox" rem ***** テスト対象のドメイン(ベースURL) ***** set TESTDOMAIN="http://hogehoge/" rem ***** TestSuiteファイルを指定する ***** set TESTSUITE=%SELSERV_DIR%\source%\index.html rem ***** 結果出力ファイルを指定する ***** set RESULTFILE=%SELSERV_DIR%\TestResult_iexplore.html set TIMEOUT="60000" rem ***** execute test ******************************************************** cd %SELSERV_DIR% java %PROXY_OPTION% -jar selenium-server.jar -htmlSuite %BROWSER% %TESTDOMAIN% %TESTSUITE% %RESULTFILE% -timeout %TIMEOUT% ★ ThinkITさん++w
- テスト実行
- 参考サイト
http://www.thinkit.co.jp/free/article/0705/2/1/ http://www.openqa.org/selenium/ http://wiki.openqa.org/display/SEL/Selenium+0.7+Reference+%28Japanese%29 http://itpro.nikkeibp.co.jp/article/COLUMN/20071011/284284/ http://www.thinkit.co.jp/cert/article/0705/2/5/Selenium_com.pdf http://labs.gree.jp/presentation/20060824/slides/selenium.html