Seleniumを使用した自動シナリオテスト †前準備 †ライブラリのダウンロード †・http://seleniumhq.org/download/ から以下のライブラリをダウンロードする
テスト用プロジェクトの作成 †eclipseでSeleniumテスト用のJavaプロジェクトを作成し、下記の通り設定する。
・ビルドパスに JUnit4 ライブラリを追加する。 テストコードの作成 †シナリオの作成(実際の操作からテストコードを自動生成する場合) †SeleniumIDEを使用して生成したテストコードをJavaソースに変換する事ができる。 (1) ダウンロードした selenium-ide-X.X.X.xpi をFireFoxにインストールする。 シナリオの作成(手入力する場合) †package tests;
import com.thoughtworks.selenium.*;
@SuppressWarnings("deprecation")
public class TestGoogle extends SeleneseTestCase {
public void setUp() throws Exception {
setUp("http://www.google.co.jp", "*safari"); //iexplore, chrome
}
public void testUntitled() throws Exception {
selenium.windowMaximize();
selenium.open("/");
selenium.type("q", "selenium");
selenium.submit("xpath=//form[1]");
//selenium.waitForPageToLoad("10000");
selenium.click("link=*selenium*");
//selenium.waitForPageToLoad("10000");
}
}
テストの実行 †中継サーバの起動 †テストの実行前に RCテスト用の中継サーバを実行しておく。
java -jar /path/to/selenium-server-standalone-X.XX.X.jar
テストの実行 †・作成したテストクラスを右クリック→[Junitテスト]でテスト実行。 |