Watir-browser-windows

提供:Dev Guides
移動先:案内検索

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>

出力

ブラウザウィンドウ

[ウィンドウを開く]ボタンをクリックすると、ポップアップウィンドウが開きます。 ここで、指定したURLはhttps://www.google.com/[www.google.com]です。 次に、Watir/

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

リンク出力の操作

popupwindowbefore.png

Popupwindowbefore

popupwindowafter.png

Popupwindowafter