0
我使用webdriver的硒連同機器人框架和我有以下問題:硒的webdriver:出口截圖到機器人框架日誌文件
我想製作一個屏幕畫面每一個我的測試中失敗的時間和這張截圖出口log.html文件。
製作截圖quity一件容易的事情:
String path;
try {
WebDriver augmentedDriver = new Augmenter().augment(driver);
File source = ((TakesScreenshot) augmentedDriver)
.getScreenshotAs(OutputType.FILE);
path = "./screenshots/" + source.getName();
FileUtils.copyFile(source, new File(path));
} catch (IOException e) {
path = "Failed to capture screenshot: " + e.getMessage();
}
但問題是截圖導出爲HTML。
在硒RC與截圖HTML部分看起來是這樣的:
<tbody>
<tr>
<td class="time">15:25:44.968</td>
<td class="fail level">FAIL</td>
<td class="message">Value of text field 'xpath=//input' should have been '' but was 'VpomRihh3Xa' Screenshot: </td>
</tr>
<tr>
<td colspan="3">
<img src="./screenshots/screenshot175324738088103861.png">
</td>
</tr>
</tbody>
歐凱,所以我想這應該是一個易於實現和擴展我的captureScreenshot()函數來此:
private String captureScreen() {
String path;
try {
WebDriver augmentedDriver = new Augmenter().augment(driver);
File source = ((TakesScreenshot) augmentedDriver)
.getScreenshotAs(OutputType.FILE);
path = "./screenshots/" + source.getName();
FileUtils.copyFile(source, new File(path));
} catch (IOException e) {
path = "Failed to capture screenshot: " + e.getMessage();
}
StringBuilder builder = new StringBuilder();
builder.append("\n<tr><td colspan=\"3\"><img src=\"").append(path).append("\"></tr></td>");
System.out.println(builder.toString());
return "";
}
但問題是,這種實現不能滿足我的需求。它看起來不錯,但我得到的只是標籤內的一些文字,它不會顯示爲圖像。
爲了更好地理解這裏是從我得到的截圖:
http://gyazo.com/5d7dec1e05443786b5d390054edad3e8 (不能發佈圖像由於低信譽)
所以,問題是 - 如何讓截圖導入到機器人框架log.html文件?
感謝,這對我幫助很大 – Bfcm