- Watir - Home
- Watir - Overview
- Watir - Introduction
- Watir - Environment Setup
- Watir - Installing Drivers for Browsers
- Watir - Working with Browsers
- Watir - Web Elements
- Watir - Locating Web Elements
- Watir - Working with Iframes
- Watir - Automatic Waits
- Watir - Headless Testing
- Watir - Mobile Testing
- Watir - Capturing Screenshots
- Watir - Page Objects
- Watir - Page Performance
- Watir - Cookies
- Watir - Proxies
- Watir - Alerts
- Watir - Downloads
- Watir - Browser Windows
- Watir Useful Resources
- Watir - Quick Guide
- Watir - Useful Resources
- Watir - Discussion
Watir - 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
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
popupwindowbefore.png
popupwindowafter.png
Advertisements