[英]How to Take screenshot using Robot Framework in selenium webdriver
[英]Selenium webdriver: Export screenshot to robot framework log file
我將selenium webdriver與機器人框架一起使用,並且遇到以下問題:
我想在每次測試失敗時制作一個屏幕截圖,然后將此屏幕截圖導出到log.html文件。
使屏幕截圖非常簡單:
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。
在Selenium 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>
Okey,所以我認為這應該很容易實現,並將我的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文件中?
嘗試使用以下示例:
System.out.println("*HTML* <img src=\"testScreenshot.png\" width=\"800px\">");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.