Taste of Tech Topics

Acroquest Technology株式会社のエンジニアが書く技術ブログ

Selenium2.6リリース!管理・解析がやりやすくなった!?

こんばんは。kimukimuです。

今日はAndroid・・・ではなく、Selenium2.6がリリースされたので折角なのでそちらを試してみます。
そもそもSeleniumがどんなものか、についてはこれまでの投稿を参照してくださいね。

1.Selenium2.6になって、何が新しいの?

リリース内容としては、主に下記が記述されています。

・ソケットエラー時のハンドリング改善/利用方法改善
・マウス動作エミュレーション改善
・OperaDriverバージョンアップ
・WebDriver例外クラスへ時間情報追加
・ExpectedCondition(結果の検証クラス)の共通実装追加
他、複数マシンでテストケースを分散実行する際のハンドリング改善

新規機能の追加というよりテスト中の状態管理がしやすくなったり、
NGだった場合に情報が追加で出力され、結果がよりわかるようになるという方向性の改修のようです。

2.実際に試してみます

では、実際に何が新しくなったのか試してみます。

・・なんですが、一番目玉となっていそうなExpectedConditionクラスについては
Selenium2.5との違いがわかりませんでした(汗
WaitForConditionの実装サンプルはSelenium2.5にもあって、特に2.6で増えているわけでもないんですよね。。。
念のため添付されているソースを確認しましたが、特に処理内容/記述内容としては差分なし。

なので、明確にわかる「WebDriver例外クラスに時間情報追加」について試してみました。

実際に試したソースは下記です。

package jp.gr.t3.seleniumnew;

import static org.junit.Assert.fail;

import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GoogleTestCase {
	private WebDriver driver;
	private String baseUrl = "http://www.test.jp";
	private StringBuffer verificationErrors = new StringBuffer();

	@Before
	public void setUp() throws Exception {
		driver = new FirefoxDriver();
		driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
	}

	@Test
	public void testCaseSelenium() throws Exception {
		driver.get(baseUrl);
		driver.findElement(By.name("q")).clear();
		driver.findElement(By.name("q")).sendKeys("Selenium 2.0");
		driver.findElement(By.name("btnG")).click();
		// ERROR: Caught exception [ERROR: Unsupported command [isTextPresent]]
	}

	@After
	public void tearDown() throws Exception {
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}

見てわかるとおり、「http://www.test.jp」なんてアドレスは存在しないので、
下記のように失敗します。
失敗する際の出力情報を比較してみよう、、、というものです。

上記のテストコードをSelenium WebDriver2.6と、Selenium WebDriver2.5で
実行して出力エラーを比較します。

出力されるエラー情報は、下記の通り。

■Selenium2.5

org.openqa.selenium.NoSuchElementException: 
Unable to locate element: {"method":"name","selector":"q"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.5.0', revision: '13516', time: '2011-08-23 18:30:44'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: RemoteWebDriver

■Selenium2.6

org.openqa.selenium.NoSuchElementException: 
Unable to locate element: {"method":"name","selector":"q"}; ★duration or timeout: 1.09 seconds★
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.6.0', revision: '13840', time: '2011-09-13 14:56:25'
System info: os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0'
Driver info: driver.version: RemoteWebDriver

実際に、『例外が発生した際の待ち時間』が追加されています。
Webシステムの自動テストで失敗した際のオペレーション時間が
出力されるというのは地味に大きいですよね。

3.何が嬉しくなったのかな?

バグ修正や追加ブラウザ(FireFox6、7)への対応がメインだった
Selenium2.4、Selenium2.5と比べて、
明確に方針が変わって『管理、問題解析用の機能追加』がメインとなっています。

そのため、これまでのバージョン(現状追従)とはちがい、
『より運用で使いやすくするための改修』にシフトしてきたように見えます。

なので、次回以降のバージョンでより使いやすくなることが期待できると考えています。
Selenium WebDriver2系自体新しいプロダクトですが、今後の進化からも目が離せませんね。