English 中文(简体)
Watir - Headless Testing
  • 时间:2024-03-18 23:04:05

Watir - Headless Testing


Previous Page Next Page  

在这一章中,我们将学会如何利用Watir网络用户的无头选择来测试该网页。

Syntax

Browser = Watir::Browser.new :chrome, headless: true

我们将要测试的试验页在这里显示:

<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>

Output

Using ID Element

Watir code

require  watir 
b = Watir::Browser.new :chrome, headless: true
b.goto( http://localhost/uitesting/textbox.html )
t = b.text_field(name:  firstname )
t.exists?
t.set  Riya Kapoor 
t.value
t.fire_event( onchange )
b.screenshot.save  headless.png 

我们增加了以下选择: 确实是Watir chrome browser。 当你执行鲁比方案时,不会打开浏览器,一切都会在指挥线上执行——

DevTools pstening on ws://127.0.0.1:53973/devtools/browser/b4127866-afb8-4c74-b967-5bacb3354b19
[0505/144843.905:INFO:CONSOLE(8)] "inside wsentered", source: http://localhost/uitesting/textbox.html (8)

我们在指挥线上添加了ole语和同样的文字。

头盔检查。 页: 1

Using ID Element

In Firefox

The watir Code for > is reflected here -

require  watir 
b = Watir::Browser.new :firefox, headless: true
b.goto( http://localhost/uitesting/textbox.html )
t = b.text_field(name:  firstname )
t.exists?
t.set  Riya Kapoor 
t.value
t.fire_event( onchange )
b.screenshot.save  headlessfirefox.png 

这里显示的是无脊椎动物的屏幕。

Using ID Element

Advertisements