Browser Windows

You will come across cases where we have to use popup window or opening of a new browser window. In this chapter, we will discuss how to test such cases using Watir.

Syntax

browser.window

A working example that we are going to test is given here −<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>

Output

Browser Windows

On-click of button Open Window, the popup window opens up. Here, the url we have given is www.google.com. Now let us test the same using Watir/

Example

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

The screenshots that we have taken are given below −

popupwindow.png

Working With Links Outputs

popupwindowbefore.png

Popupwindowbefore

popupwindowafter.png

Popupwindowafter

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *