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/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_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/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
click_button_in_javascript_popup(button = "OK") click to toggle source

(Not documented)

    # File lib/rwebspec/popup.rb, line 81
81:     def click_button_in_javascript_popup(button = "OK")
82:       verify_alert()
83:     end
Also aliased as: click_javascript_popup
click_button_in_popup_after(options = {:button => "OK", :wait_time => 3}, &block) click to toggle source

Click the button in javascript popup dialog Usage:

  click_button_in_popup_after { click_link('Cancel')}
  click_button_in_popup_after("OK") { click_link('Cancel')}
     # File lib/rwebspec/popup.rb, line 137
137:     def click_button_in_popup_after(options = {:button => "OK", :wait_time => 3}, &block)
138:       if is_windows?  then
139:         start_checking_js_dialog(options[:button], options[:wait_time])
140:         yield
141:       else
142:         raise "this only support on Windows and on IE"
143:       end
144:     end
click_button_in_security_alert_popup(button = "&Yes") click to toggle source

(Not documented)

    # File lib/rwebspec/popup.rb, line 76
76:     def click_button_in_security_alert_popup(button = "&Yes")
77:       verify_alert("Security Alert", "", button)
78:     end
Also aliased as: click_security_alert_popup
click_button_in_security_information_popup(button = "&Yes") click to toggle source

(Not documented)

    # File lib/rwebspec/popup.rb, line 71
71:     def click_button_in_security_information_popup(button = "&Yes")
72:       verify_alert("Security Information", "", button)
73:     end
click_javascript_popup(button = "OK") click to toggle source
click_popup_window(button, wait_time= 9, user_input=nil ) click to toggle source

(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
click_security_alert_popup(button = "&Yes") click to toggle source
click_security_information_popup(button = "&Yes") click to toggle source
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/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
prepare_to_click_button_in_popup(button = "OK", wait_time = 3) click to toggle source

run a separate process waiting for the popup window to click

     # File lib/rwebspec/popup.rb, line 112
112:     def prepare_to_click_button_in_popup(button = "OK", wait_time = 3)
113:       #  !@web_browser.is_firefox?
114:       # TODO: firefox is OK
115:       if RUBY_PLATFORM =~ /mswin/  then
116:         start_checking_js_dialog(button, wait_time)
117:       else
118:         raise "this only support on Windows and on IE"
119:       end
120:     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/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
verify_alert(title = "Microsoft Internet Explorer", button = "OK") click to toggle source

(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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.