Start background thread to click popup windows
Warning: Make browser window active Don't mouse your mouse to focus other window during test execution
# File lib/rwebspec/popup.rb, line 11
11: def check_for_popups
12: autoit = WIN32OLE.new('AutoItX3.Control')
13: #
14: # Do forever - assumes popups could occur anywhere/anytime in your
15: # application.
16: loop do
17: # Look for window with given title. Give up after 1 second.
18: ret = autoit.WinWait('Windows Internet Explorer', '', 1)
19: #
20: # If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}).
21: if (ret==1) then
22: autoit.Send('{enter}')
23: end
24: #
25: # Take a rest to avoid chewing up cycles and give another thread a go.
26: # Then resume the loop.
27: sleep(3)
28: end
29: end
Check for "Security Information" and "Security Alert" alert popup, click 'Yes'
Usage: For individual test suite
before(:all) do
$popup = Thread.new { check_for_alerts }
open_in_browser
...
end
after(:all) do
close_browser Thread.kill($popup)
end
or for all tests,
$popup = Thread.new { check_for_alerts }
at_exit{ Thread.kill($popup) }
# File lib/rwebspec/popup.rb, line 50
50: def check_for_security_alerts
51: autoit = WIN32OLE.new('AutoItX3.Control')
52: loop do
53: ["Security Alert", "Security Information"].each do |win_title|
54: ret = autoit.WinWait(win_title, '', 1)
55: if (ret==1) then
56: autoit.Send('{Y}')
57: end
58: end
59: sleep(3)
60: end
61: end
Alias for #click_button_in_javascript_popup
(Not documented)
# File lib/rwebspec/popup.rb, line 105
105: def click_popup_window(button, wait_time= 9, user_input=nil )
106: @web_browser.start_clicker(button, wait_time, user_input)
107: sleep 0.5
108: end
Alias for #click_button_in_security_alert_popup
This only works for IEs
Cons:
- Slow
- only works in IE
- does not work for security alert ?
# File lib/rwebspec/popup.rb, line 92
92: def ie_popup_clicker(button_name = "OK", max_wait = 15)
93: require 'watir/contrib/enabled_popup'
94: require 'win32ole'
95: hwnd = ie.enabled_popup(15)
96: if (hwnd) #yeah! a popup
97: popup = WinClicker.new
98: popup.makeWindowActive(hwnd) #Activate the window.
99: popup.clickWindowsButton_hwnd(hwnd, button_name) #Click the button
100: #popup.clickWindowsButton(/Internet/,button_name,30)
101: popup = nil
102: end
103: end
Start a background process to click the button on a javascript popup window
# File lib/rwebspec/popup.rb, line 123
123: def start_checking_js_dialog(button = "OK", wait_time = 3)
124: w = WinClicker.new
125: longName = File.expand_path(File.dirname(__FILE__)).gsub("/", "\\" )
126: shortName = w.getShortFileName(longName)
127: c = "start ruby #{shortName}\\clickJSDialog.rb #{button} #{wait_time} "
128: w.winsystem(c)
129: w = nil
130: end
(Not documented)
# File lib/rwebspec/popup.rb, line 63
63: def verify_alert(title = "Microsoft Internet Explorer", button = "OK")
64: if is_windows? && !is_firefox?
65: WIN32OLE.new('AutoItX3.Control').ControlClick(title, '', button)
66: else
67: raise "This function only supports IE"
68: end
69: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.