Class: Watir::ModalDialog

Inherits:
Object
  • Object
show all
Includes:
Container, PageContainer, Win32
Defined in:
lib/watir/modal_dialog.rb

Constant Summary

Constants included from Win32

Win32::FindWindowEx, Win32::GW_CHILD, Win32::GW_ENABLEDPOPUP, Win32::GW_HWNDFIRST, Win32::GW_HWNDLAST, Win32::GW_HWNDNEXT, Win32::GW_HWNDPREV, Win32::GW_MAX, Win32::GW_OWNER, Win32::GetUnknown, Win32::GetWindow, Win32::IsWindow, Win32::User32

Instance Attribute Summary collapse

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Instance Method Summary collapse

Methods included from Win32

window_exists?

Methods included from PageContainer

#check_for_http_error, #contains_text, #enabled_popup, #html, #set_container, #show_frames, #text, #url

Methods included from Container

#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #hidden, #hiddens, #image, #images, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #log, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields

Constructor Details

#initialize(container, how, what = nil) ⇒ ModalDialog

Returns a new instance of ModalDialog.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/watir/modal_dialog.rb', line 79

def initialize(container, how, what=nil)
  set_container container
  @how = how
  @what = what
  @parent_container = container
  # locate our modal dialog's Document object and save it
  begin
    locate
  rescue NoMethodError => e
    message = 
      "IE#modal_dialog not supported with the current version of Ruby (#{RUBY_VERSION}).\n" + 
      "See http://jira.openqa.org/browse/WTR-2 for details.\n" +
        e.message
    raise NoMethodError.new(message)
  end
end

Instance Attribute Details

#hwndObject (readonly)

Return the current window handle



8
9
10
# File 'lib/watir/modal_dialog.rb', line 8

def hwnd
  @hwnd
end

Instance Method Details

#attach_commandObject



109
110
111
# File 'lib/watir/modal_dialog.rb', line 109

def attach_command
  "Watir::IE.find(:hwnd, #{@container.hwnd}).modal_dialog"
end

#closeObject



105
106
107
# File 'lib/watir/modal_dialog.rb', line 105

def close
  document.parentWindow.close
end

#documentObject



96
97
98
# File 'lib/watir/modal_dialog.rb', line 96

def document
  @document
end

#exists?Boolean Also known as: exist?

Return true if the modal exists. Mostly this is useful for testing whether a modal has closed.

Returns:

  • (Boolean)


118
119
120
# File 'lib/watir/modal_dialog.rb', line 118

def exists?
  Watir::Win32::window_exists? @hwnd
end

#locateObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/watir/modal_dialog.rb', line 30

def locate
  how = @how
  what = @what

  case how
  when nil
    unless find_modal_from_window
      raise NoMatchingWindowFoundException, 
        "Modal Dialog not found. Timeout = #{Watir::IE.attach_timeout}"
    end
  when :title
    case what.class.to_s
    # TODO: re-write like WET's so we can select on regular expressions too.
    when "String"
      begin
        Watir::until_with_timeout do
          title = "#{what} -- Web Page Dialog"
          @hwnd, arr = FindWindowEx.call(0, 0, nil, title)
          @hwnd > 0
        end
      rescue TimeOutException
        raise NoMatchingWindowFoundException, 
          "Modal Dialog with title #{what} not found. Timeout = #{Watir::IE.attach_timeout}"
      end
    else
      raise ArgumentError, "Title value must be String"
    end
  else
    raise ArgumentError, "Only null and :title methods are supported"
  end

  intUnknown = 0
  begin
    Watir::until_with_timeout do
      intPointer = " " * 4 # will contain the int value of the IUnknown*
      GetUnknown.call(@hwnd, intPointer)
      intArray = intPointer.unpack('L')
      intUnknown = intArray.first
      intUnknown > 0
    end
  rescue TimeOutException => e        
    raise NoMatchingWindowFoundException, 
      "Unable to attach to Modal Window #{what.inspect} after #{e.duration} seconds."
  end
  
  copy_test_config @parent_container
  @document = WIN32OLE.connect_unknown(intUnknown)
end

#titleObject

Return the title of the document



101
102
103
# File 'lib/watir/modal_dialog.rb', line 101

def title
  document.title
end

#wait(no_sleep = false) ⇒ Object



113
114
# File 'lib/watir/modal_dialog.rb', line 113

def wait(no_sleep=false)
end