JUnit Selenium テストで作成された画面キャプチャーを実行結果に追加

JUnit Selenium テストでは、実行時に、エラー状態を示すためにブラウザー・セッションの画面キャプチャーを作成することができます。 これらの画面キャプチャーは、テスト・ケースまたはテスト・スイートの実行の実行結果に組み込んで、後で参照できます。

このタスクについて

JUnit Selenium アダプターはテストを実行する際に、 JUnit Selenium テストを実行する JVM で「selenium.screenshot.dir」という Java™ システム・プロパティーを設定します。この Java システム・プロパティーの値は、アダプターを実行するマシン上のディレクトリーの絶対パスです。 実行された各 JUnit Selenium テストの終了時に、 「selenium.screenshot.dir」に指定されたディレクトリーでイメージ・ファイル (.png、.jpg、.jpeg、.gif、.tif、.bmp) が検索されます。 イメージ・ファイルが見つかると、 品質管理サーバーに添付ファイルが作成され、それらの添付ファイルへの参照が実行結果に組み込まれます。

例

次のサンプルの JUnit コードでは、ブラウザーの現行状況の画面キャプチャーを取得して、 「selenium.screenshot.dir」で指定されたディレクトリーに画面キャプチャー・ファイルを配置する方法を示しています。
	@Test
	public void testWikipediaJUnit4_test1() throws Exception {
		driver.get(baseUrl + "/");
		driver.findElement(By.id("searchInput")).clear();
		driver.findElement(By.id("searchInput")).sendKeys("blueberries");
		takeScreenShot("blueberry2.png");	// Capture screenshot of current state
		driver.findElement(By.name("go")).click();
		driver.findElement(By.cssSelector("p > i > a[title=¥"Vaccinium¥"]")).click();
		takeScreenShot("vaccinium2.png");	// Capture screenshot of current state
		driver.findElement(By.linkText("huckleberry")).click();
		takeScreenShot("huckleberry2.png");	// Capture screenshot of current state
	}

	private void takeScreenShot(String fname) throws Exception {
	    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
	    String imageFileDir = System.getProperty("selenium.screenshot.dir");
	    if (imageFileDir == null)
	    	imageFileDir = System.getProperty("java.io.tmpdir");
    	    FileUtils.copyFile(scrFile, new File(imageFileDir, fname));
	}

ビデオ・アイコン ビデオを見る

CLM 再生リスト
Jazz.net チャンネル
User Education チャンネル

学習アイコン 詳細情報

CLM Learning Circle
Agile Learning Circle
Learning circles

質問アイコン 質問する

Jazz.net フォーラム
developerWorks フォーラム

サポート・アイコン サポートを受ける

サポート・ポータル
Deployment Wiki
サポートのブログ