Watir - 浏览器窗口



我们会遇到必须使用弹出窗口或打开新浏览器窗口的情况。在本章中,我们将讨论如何使用 Watir 测试此类情况。

语法

browser.window

下面给出了我们要测试的工作示例 −

<html>
   <head>
      <title>Testing UI using Watir</title>
   </head>
   
   <body>
      <script type = "text/javascript">
         function wsclick() {
            var myWindow = window.open(
               "https://www.google.com/", "mywindow", "width = 1000,height = 500");
         }
      </script>
      
      <form name = "myform" method = "POST">
         <div>
            <br>
            <input type = "button" id = "btnsubmit" name = "btnsubmit" value = "submit" onclick = "wsclick()"/>
            <br>
         </div>
      </form>
      <br/>
   </body>
</html>

输出

Browser Windows

单击“打开窗口”按钮后,将打开弹出窗口。此处,我们给出的 URL 为 www.google.com。现在,让我们使用 Watir/对其进行测试

示例

require 'watir'
b = Watir::Browser.new :chrome
b.goto('https://127.0.0.1/uitesting/windowpopup.html')
b.button(id: 'btnsubmit').click
b.window(title: 'Google').use do
   b.screenshot.save 'popupwindow.png'
   t = b.text_field(class: 'gLFyf')
   t.set 'Watir'
   b.screenshot.save 'popupwindowbefore.png'
   b.button(name: 'btnK').click
   b.screenshot.save 'popupwindowafter.png'
end

下面给出了我们拍摄的屏幕截图 −

popupwindow.png

Working With Links Outputs

popupwindowbefore.png

Popupwindowbefore

popupwindowafter.png

Popupwindowafter

广告