module RWebSpec::Popup
Public Instance Methods
check_for_popups()
click to toggle source
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-common/popup.rb, line 11 def check_for_popups autoit = WIN32OLE.new('AutoItX3.Control') # # Do forever - assumes popups could occur anywhere/anytime in your # application. loop do # Look for window with given title. Give up after 1 second. ret = autoit.WinWait('Windows Internet Explorer', '', 1) # # If window found, send appropriate keystroke (e.g. {enter}, {Y}, {N}). if (ret==1) then autoit.Send('{enter}') end # # Take a rest to avoid chewing up cycles and give another thread a go. # Then resume the loop. sleep(3) end end
check_for_security_alerts()
click to toggle source
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-common/popup.rb, line 50 def check_for_security_alerts autoit = WIN32OLE.new('AutoItX3.Control') loop do ["Security Alert", "Security Information"].each do |win_title| ret = autoit.WinWait(win_title, '', 1) if (ret==1) then autoit.Send('{Y}') end end sleep(3) end end
click_popup_window(button, wait_time= 9, user_input=nil )
click to toggle source
# File lib/rwebspec-common/popup.rb, line 105 def click_popup_window(button, wait_time= 9, user_input=nil ) @web_browser.start_clicker(button, wait_time, user_input) sleep 0.5 end
click_security_information_popup(button = "&Yes")
Alias for: click_button_in_security_information_popup
ie_popup_clicker(button_name = "OK", max_wait = 15)
click to toggle source
This only works for IEs
Cons: - Slow - only works in IE - does not work for security alert ?
# File lib/rwebspec-common/popup.rb, line 92 def ie_popup_clicker(button_name = "OK", max_wait = 15) require 'watir/contrib/enabled_popup' require 'win32ole' hwnd = ie.enabled_popup(15) if (hwnd) #yeah! a popup popup = WinClicker.new popup.makeWindowActive(hwnd) #Activate the window. popup.clickWindowsButton_hwnd(hwnd, button_name) #Click the button #popup.clickWindowsButton(/Internet/,button_name,30) popup = nil end end
start_checking_js_dialog(button = "OK", wait_time = 3)
click to toggle source
Start a background process to click the button on a javascript popup window
# File lib/rwebspec-common/popup.rb, line 123 def start_checking_js_dialog(button = "OK", wait_time = 3) w = WinClicker.new longName = File.expand_path(File.dirname(__FILE__)).gsub("/", "\\" ) shortName = w.getShortFileName(longName) c = "start ruby #{shortName}\\clickJSDialog.rb #{button} #{wait_time} " w.winsystem(c) w = nil end
verify_alert(title = "Microsoft Internet Explorer", button = "OK")
click to toggle source
# File lib/rwebspec-common/popup.rb, line 63 def verify_alert(title = "Microsoft Internet Explorer", button = "OK") if is_windows? && !is_firefox? WIN32OLE.new('AutoItX3.Control').ControlClick(title, '', button) else raise "This function only supports IE" end end