Handling popup window in watir

Source: Internet
Author: User
Handling popup window in testing browser based applications is always an annoying problem. watir provides a good solution for this, here is what I learned from the watir mail list and share it here to everyone else.

You will need newest watir (build late than 1.5.1.1079) to do it.

Here is the ruby scripts to handle popup windows:

# Des
Require 'watir' # The Controller
Require 'watir \ contrib \ enabled_popup'
Include watir

# Test: unit nodes des
Require 'test/unit'

Class tc_dimensionnet_login <test: Unit: testcase

Def test_window_popup

Testsite = "http: // localhost/test.htm"

$ Ie = watir: IE. New

$ Ie. Goto (testsite)

$ Ie. Button (: ID, "btnpopup"). Click
Startclicker ("OK", 5)
End

# Function click buttons on a popup window
Def startclicker (button, waittime = 9, user_input = nil)

Hwnd = $ ie. enabled_popup (waittime) # Get a handle if one exists

If (hwnd) # yes there is a popup
Puts hwnd
W = winclicker. New

If (user_input)
W. settextvalueforfilenamefield (hwnd, "# {user_input }")
End

Sleep 3 # I put this in to see the text being input it is not necessary to work
W. clickwindowsbutton_hwnd (hwnd, "# {button}") # "OK" or whatever the name on the button is
W = nil # This is just cleanup

End

End

End

Powered by scribefire.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.