Class: Watir::IE

Inherits:
Object
  • Object
show all
Defined in:
lib/watirspec/watir.rb

Overview

:nodoc:all

Instance Method Summary collapse

Instance Method Details

#closeObject

Closes the browser even if #wait throws an exception. It happens mostly when #run_error_checks throws some exception.



69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/watirspec/watir.rb', line 69

def close
  return unless exists?
  @closing = true
  @ie.stop
  begin
    wait
  rescue
  end
  chwnd = @ie.hwnd.to_i
  @ie.quit
  while Win32API.new("user32", "IsWindow", 'L', 'L').Call(chwnd) == 1
    sleep 0.3
  end
end

#wait(no_sleep = false) ⇒ Object

This is Watir’s overriden wait method, which is used in many places for deciding if browser is ready or not. We have to patch one line in it to work properly when file save as dialog has been displayed. For some reason READYSTATE (4) property value will be READYSTATE_INTERACTIVE (3) after file has been downloaded and not 4, thus wait will stay blocking. read more about IE READYSTATE property: msdn.microsoft.com/en-us/library/aa768362(VS.85).aspx



18
19
20
21
22
23
24
25
26
27
28
29
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
# File 'lib/watirspec/watir.rb', line 18

def wait(no_sleep=false)
  @xml_parser_doc = nil
  @down_load_time = 0.0
  a_moment = 0.2 # seconds
  start_load_time = Time.now

  begin
    while @ie.busy # XXX need to add time out
      sleep a_moment
    end
    # this is the line which has been changed to accept also state 3
    until @ie.readyState <= READYSTATE_COMPLETE do
      sleep a_moment
    end
    sleep a_moment
    until @ie.document do
      sleep a_moment
    end

    documents_to_wait_for = [@ie.document]

  rescue WIN32OLERuntimeError # IE window must have been closed
    @down_load_time = Time.now - start_load_time
    sleep @pause_after_wait unless no_sleep
    return @down_load_time
  end

  while doc = documents_to_wait_for.shift
    begin
      until doc.readyState == "complete" do
        sleep a_moment
      end
      @url_list << doc.location.href unless @url_list.include?(doc.location.href)
      doc.frames.length.times do |n|
        begin
          documents_to_wait_for << doc.frames[n.to_s].document
        rescue WIN32OLERuntimeError, NoMethodError
        end
      end
    rescue WIN32OLERuntimeError
    end
  end

  @down_load_time = Time.now - start_load_time
  run_error_checks
  sleep @pause_after_wait unless no_sleep
  @down_load_time
end