Watir-capturing-screenshots
提供:Dev Guides
Watir-スクリーンショットのキャプチャ
スクリーンショットをキャプチャする機能は、Watirで利用できる興味深い機能の1つです。 テストの自動化中に、スクリーンショットを取得して画面を保存できます。 ケースでは、エラーが発生した場合、スクリーンショットの助けを借りて同じことが文書化できます。
スクリーンショットを撮ったテストページと一緒の簡単な例を以下に説明します-
構文
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('http://localhost/uitesting/textboxl')
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を使用して撮影したスクリーンショットを次に示します-