- Watir 教程
- Watir - 主頁
- Watir - 概述
- Watir - 簡介
- Watir - 環境設定
- Watir - 為瀏覽器安裝驅動程式
- Watir - 使用瀏覽器
- Watir - Web 元素
- Watir - 定位 Web 元素
- Watir - 使用 Iframe
- Watir - 自動等待
- Watir - 無介面測試
- Watir - 移動裝置測試
- Watir - 捕獲螢幕截圖
- Watir - 頁面物件
- Watir - 頁面效能
- Watir - Cookie
- Watir - 代理
- Watir - 警告
- Watir - 下載
- Watir - 瀏覽器視窗
- Watir 有用資源
- Watir - 快速指南
- Watir - 有用資源
- Watir - 討論
Watir - 捕獲螢幕截圖
捕獲螢幕截圖的功能是 Watir 提供的一項有趣的功能。測試自動化期間,使用者可以捕獲螢幕截圖並儲存螢幕。如果發生任何錯誤,可以藉助螢幕截圖記錄錯誤。
下面將討論一個簡單的示例以及我們捕獲螢幕截圖的測試頁面 −
語法
browser.screenshot.save 'nameofimage.png'
測試頁面
<html>
<head>
<title>Testing UI using Watir</title>
</head>
<body>
<script type = "text/javascript">
function wsentered() {
console.log("inside wsentered");
var firstname = document.getElementById("firstname");
if (firstname.value != "") {
document.getElementById("displayfirstname").innerHTML =
"The name entered is : " + firstname.value;
document.getElementById("displayfirstname").style.display = "";
}
}
</script>
<div id = "divfirstname">
Enter First Name :
<input type = "text" id = "firstname" name = "firstname" onchange = "wsentered()" />
</div>
<br/>
<br/>
<div style = "display:none;" id = "displayfirstname"></div>
</body>
</html>
示例
require 'watir'
b = Watir::Browser.new :chrome
b.goto('https:///uitesting/textbox.html')
t = b.text_field(id: 'firstname') // using the id of the textbox to locate the textbox
t.exists?
t.set 'Riya Kapoor'
b.screenshot.save 'textboxbefore.png'
t.value
t.fire_event('onchange')
b.screenshot.save 'textboxafter.png'
這裡展示了我們使用 Watir 捕獲的螢幕截圖 −
textboxbefore.png
textboxafter.png
廣告