English 中文(简体)
Watir - Capturing Screenshots
  • 时间:2024-03-18 23:02:40

Watir - Capturing Screenshots


Previous Page Next Page  

掌握屏幕照片的能力是Watir的有趣特征之一。 在测试自动化期间,你可以抽取屏幕并节省屏幕。 如果发生任何错误,可在屏幕上加以记录。

下文将讨论一个简单的例子,以及测试页,我们在那里进行了筛选。

Syntax

browser.screenshot.save  nameofimage.png 

Test page

<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>
      <span id = "spanfirstname">
         Enter First Name :
         <input type = "text" id = "firstname" name = "firstname" onchange = "wsentered()" />
      </span>
      <br/>
      <br/>
      <span style = "display:none;" id = "displayfirstname"></span>
   </body>
</html>

Example

require  watir 
b = Watir::Browser.new :chrome
b.goto( http://localhost/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

Using ID

textboxafter.png

Using ID Element

Advertisements