watir 1.9.0.rc4 → 1.9.0.rc5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/watir/close_all.rb +1 -8
- data/lib/watir/container.rb +1 -1
- data/lib/watir/core.rb +3 -0
- data/lib/watir/modal_dialog.rb +29 -78
- data/rakefile.rb +7 -0
- data/unittests/windows/modal_dialog_test.rb +19 -51
- metadata +10 -10
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.0.
|
1
|
+
1.9.0.rc5
|
data/lib/watir/close_all.rb
CHANGED
@@ -23,15 +23,8 @@ module Watir
|
|
23
23
|
# to appear and does not raise exception if no window is found.
|
24
24
|
# returns true if modal was found and close, otherwise false
|
25
25
|
def close_modal
|
26
|
-
|
27
|
-
original_attach_timeout = IE.attach_timeout
|
28
|
-
IE.attach_timeout = 0
|
26
|
+
while self.modal_dialog.exists?(0) do
|
29
27
|
self.modal_dialog.close
|
30
|
-
true
|
31
|
-
rescue NoMatchingWindowFoundException, Wait::TimeoutError
|
32
|
-
false
|
33
|
-
ensure
|
34
|
-
IE.attach_timeout = original_attach_timeout
|
35
28
|
end
|
36
29
|
end
|
37
30
|
end
|
data/lib/watir/container.rb
CHANGED
@@ -209,7 +209,7 @@ module Watir
|
|
209
209
|
# loaded.
|
210
210
|
|
211
211
|
def modal_dialog(how=nil, what=nil)
|
212
|
-
ModalDialog.new(self
|
212
|
+
ModalDialog.new(self)
|
213
213
|
end
|
214
214
|
|
215
215
|
# This is the main method for accessing a button. Often declared as an <tt><input type = submit></tt> tag.
|
data/lib/watir/core.rb
CHANGED
data/lib/watir/modal_dialog.rb
CHANGED
@@ -10,100 +10,33 @@ module Watir
|
|
10
10
|
include PageContainer
|
11
11
|
include Win32
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def find_modal_from_window
|
17
|
-
# Use handle of our parent window to see if we have any currently
|
18
|
-
# enabled popup.
|
19
|
-
hwnd = @container.hwnd
|
20
|
-
hwnd_modal = 0
|
21
|
-
begin
|
22
|
-
Watir::until_with_timeout do
|
23
|
-
hwnd_modal, arr = GetWindow.call(hwnd, GW_ENABLEDPOPUP) # GW_ENABLEDPOPUP = 6
|
24
|
-
hwnd_modal > 0
|
25
|
-
end
|
26
|
-
rescue Wait::TimeoutError
|
27
|
-
return nil
|
28
|
-
end
|
29
|
-
if hwnd_modal == hwnd || hwnd_modal == 0
|
30
|
-
hwnd_modal = nil
|
31
|
-
end
|
32
|
-
@hwnd = hwnd_modal
|
13
|
+
def initialize(container)
|
14
|
+
set_container container
|
15
|
+
@modal = ::RAutomation::Window.new(:hwnd=>@container.hwnd).child(:class => 'Internet Explorer_TridentDlgFrame')
|
33
16
|
end
|
34
|
-
private :find_modal_from_window
|
35
17
|
|
36
18
|
def locate
|
37
|
-
how = @how
|
38
|
-
what = @what
|
39
|
-
|
40
|
-
case how
|
41
|
-
when nil
|
42
|
-
unless find_modal_from_window
|
43
|
-
raise NoMatchingWindowFoundException,
|
44
|
-
"Modal Dialog not found. Timeout = #{Watir::IE.attach_timeout}"
|
45
|
-
end
|
46
|
-
when :title
|
47
|
-
case what.class.to_s
|
48
|
-
# TODO: re-write like WET's so we can select on regular expressions too.
|
49
|
-
when "String"
|
50
|
-
begin
|
51
|
-
Watir::until_with_timeout do
|
52
|
-
title = "#{what} -- Web Page Dialog"
|
53
|
-
@hwnd, arr = FindWindowEx.call(0, 0, nil, title)
|
54
|
-
@hwnd > 0
|
55
|
-
end
|
56
|
-
rescue Wait::TimeoutError
|
57
|
-
raise NoMatchingWindowFoundException,
|
58
|
-
"Modal Dialog with title #{what} not found. Timeout = #{Watir::IE.attach_timeout}"
|
59
|
-
end
|
60
|
-
else
|
61
|
-
raise ArgumentError, "Title value must be String"
|
62
|
-
end
|
63
|
-
else
|
64
|
-
raise ArgumentError, "Only null and :title methods are supported"
|
65
|
-
end
|
66
|
-
|
67
19
|
intUnknown = 0
|
68
20
|
begin
|
69
21
|
Watir::until_with_timeout do
|
70
22
|
intPointer = " " * 4 # will contain the int value of the IUnknown*
|
71
|
-
GetUnknown.call(
|
23
|
+
GetUnknown.call(hwnd, intPointer)
|
72
24
|
intArray = intPointer.unpack('L')
|
73
25
|
intUnknown = intArray.first
|
74
26
|
intUnknown > 0
|
75
27
|
end
|
76
28
|
rescue Wait::TimeoutError => e
|
77
|
-
raise NoMatchingWindowFoundException,
|
78
|
-
"Unable to attach to Modal Window
|
29
|
+
raise NoMatchingWindowFoundException,
|
30
|
+
"Unable to attach to Modal Window after #{e.duration} seconds."
|
79
31
|
end
|
80
|
-
|
81
|
-
copy_test_config @parent_container
|
82
32
|
@document = WIN32OLE.connect_unknown(intUnknown)
|
83
33
|
end
|
84
34
|
|
85
|
-
def initialize(container, how, what=nil)
|
86
|
-
set_container container
|
87
|
-
@how = how
|
88
|
-
@what = what
|
89
|
-
@parent_container = container
|
90
|
-
# locate our modal dialog's Document object and save it
|
91
|
-
begin
|
92
|
-
locate
|
93
|
-
rescue NoMethodError => e
|
94
|
-
message =
|
95
|
-
"IE#modal_dialog not supported with the current version of Ruby (#{RUBY_VERSION}).\n" +
|
96
|
-
"See http://jira.openqa.org/browse/WTR-2 for details.\n" +
|
97
|
-
e.message
|
98
|
-
raise NoMethodError.new(message)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
35
|
def document
|
36
|
+
locate
|
103
37
|
@document
|
104
38
|
end
|
105
39
|
|
106
|
-
# Return the title of the document
|
107
40
|
def title
|
108
41
|
document.title
|
109
42
|
end
|
@@ -117,12 +50,30 @@ module Watir
|
|
117
50
|
end
|
118
51
|
|
119
52
|
def wait(no_sleep=false)
|
53
|
+
sleep 1
|
54
|
+
if exists?
|
55
|
+
# do nothing
|
56
|
+
else
|
57
|
+
@container.page_container.wait
|
58
|
+
end
|
120
59
|
end
|
121
60
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
61
|
+
def hwnd
|
62
|
+
@modal.hwnd
|
63
|
+
end
|
64
|
+
|
65
|
+
def active?
|
66
|
+
@modal.active?
|
67
|
+
end
|
68
|
+
|
69
|
+
# When checking to see if the modal exists we give it some time to
|
70
|
+
# find it. So if it does see a modal it returns immediately, otherwise it waits and checks
|
71
|
+
def exists?(timeout=5)
|
72
|
+
begin
|
73
|
+
Watir::Wait.until(timeout) {@modal.exists?}
|
74
|
+
rescue Watir::Wait::TimeoutError
|
75
|
+
end
|
76
|
+
return @modal.exists?
|
126
77
|
end
|
127
78
|
alias :exist? :exists?
|
128
79
|
end
|
data/rakefile.rb
CHANGED
@@ -30,6 +30,12 @@ end
|
|
30
30
|
|
31
31
|
CLEAN << 'pkg' << 'rdoc'
|
32
32
|
|
33
|
+
|
34
|
+
desc 'Attach to an active IE window'
|
35
|
+
task :attach do
|
36
|
+
sh "irb.bat -r attach.rb"
|
37
|
+
end
|
38
|
+
|
33
39
|
task :default => :package
|
34
40
|
|
35
41
|
if defined? Rake::GemPackageTask
|
@@ -45,3 +51,4 @@ if defined? Rake::GemPackageTask
|
|
45
51
|
else
|
46
52
|
puts 'Warning: without Rubygems packaging tasks are not available'
|
47
53
|
end
|
54
|
+
|
@@ -13,25 +13,16 @@ class TC_ModalDialog < Watir::TestCase
|
|
13
13
|
IE.attach_timeout = 10.0
|
14
14
|
end
|
15
15
|
|
16
|
-
def teardown
|
17
|
-
if browser
|
18
|
-
while browser.
|
16
|
+
def teardown
|
17
|
+
if browser
|
18
|
+
while browser.modal_dialog.exists?(0) do
|
19
|
+
browser.modal_dialog.close
|
20
|
+
sleep 0.5
|
21
|
+
end
|
19
22
|
end
|
20
|
-
sleep 0.1
|
21
|
-
IE.attach_timeout = @original_timeout
|
22
23
|
end
|
23
24
|
|
24
|
-
|
25
|
-
IE.attach_timeout = 0.2
|
26
|
-
begin
|
27
|
-
assert_raises(NoMatchingWindowFoundException) do
|
28
|
-
browser.modal_dialog
|
29
|
-
end
|
30
|
-
ensure
|
31
|
-
IE.attach_timeout = @original_timeout
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
25
|
+
|
35
26
|
def test_modal_simple_use_case
|
36
27
|
browser.button(:value, 'Launch Dialog').click_no_wait
|
37
28
|
modal = browser.modal_dialog(:title, 'Modal Dialog')
|
@@ -68,60 +59,37 @@ class TC_ModalDialog < Watir::TestCase
|
|
68
59
|
modal.text_field(:name, 'modal_text').set('hello')
|
69
60
|
modal.button(:value, 'Close').click
|
70
61
|
|
71
|
-
|
62
|
+
assert !browser.modal_dialog.exists?
|
72
63
|
assert_equal('hello', browser.text_field(:name, 'modaloutput').value)
|
73
64
|
end
|
74
65
|
|
75
|
-
# Now explicitly supply the :title parameter.
|
76
|
-
def test_modal_dialog_use_case_title
|
77
|
-
browser.button(:value, 'Launch Dialog').click_no_wait
|
78
|
-
|
79
|
-
modal = browser.modal_dialog(:title, 'Modal Dialog')
|
80
|
-
assert_not_equal(browser.hwnd, modal.hwnd)
|
81
|
-
|
82
|
-
assert_equal('Modal Dialog', modal.title)
|
83
|
-
|
84
|
-
assert(modal.text.include?('Enter some text:'))
|
85
|
-
modal.button(:value, 'Close').click
|
86
|
-
end
|
87
|
-
|
88
|
-
# Now explicitly supply the :title parameter with regexp match
|
89
|
-
def test_modal_dialog_use_case_title_regexp
|
90
|
-
assert_raises(ArgumentError){browser.modal_dialog(:title, /dal Dia/)}
|
91
|
-
end
|
92
|
-
|
93
|
-
# Now explicitly supply an invalid "how" value
|
94
|
-
def test_modal_dialog_use_case_invalid
|
95
|
-
assert_raise(ArgumentError) { browser.modal_dialog(:esp) }
|
96
|
-
end
|
97
|
-
|
98
66
|
def test_double_modal
|
99
67
|
browser.button(:value, 'Launch Dialog').click_no_wait
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
68
|
+
browser.modal_dialog.button(:text, 'Another Modal').click_no_wait
|
69
|
+
assert_nothing_raised {
|
70
|
+
Watir::Wait.until {browser.modal_dialog.title == 'Pass Page'}
|
71
|
+
}
|
72
|
+
browser.modal_dialog.close
|
73
|
+
browser.modal_dialog.close
|
106
74
|
end
|
107
|
-
|
75
|
+
|
108
76
|
def xtest_modal_with_frames
|
109
77
|
browser.button(:value, 'Launch Dialog').click_no_wait
|
110
78
|
modal1 = browser.modal_dialog
|
111
79
|
modal1.button(:value, 'Modal with Frames').click_no_wait
|
112
80
|
modal2 = browser.modal_dialog
|
113
81
|
modal2.frame('buttonFrame').button(:value, 'Click Me').click
|
114
|
-
assert(modal2.frame('buttonFrame').text.include?('PASS'))
|
82
|
+
assert(modal2.frame('buttonFrame').text.include?('PASS'))
|
115
83
|
modal2.frame('buttonFrame').button(:value, 'Close Window').click
|
116
84
|
modal1.close
|
117
85
|
end
|
118
|
-
|
86
|
+
|
119
87
|
def test_modal_exists
|
120
88
|
browser.button(:value, 'Launch Dialog').click_no_wait
|
121
|
-
modal = browser.modal_dialog
|
89
|
+
modal = browser.modal_dialog
|
122
90
|
assert(modal.exists?)
|
123
91
|
modal.button(:value, 'Close').click
|
124
92
|
assert_false(modal.exists?)
|
125
93
|
end
|
126
|
-
|
94
|
+
|
127
95
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watir
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424175
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 9
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 1.9.0.
|
11
|
+
- 5
|
12
|
+
version: 1.9.0.rc5
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Bret Pettichord
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2011-06-
|
20
|
+
date: 2011-06-10 00:00:00 Z
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
23
|
name: win32-process
|
@@ -59,14 +59,14 @@ dependencies:
|
|
59
59
|
requirements:
|
60
60
|
- - "="
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
hash:
|
62
|
+
hash: 15424175
|
63
63
|
segments:
|
64
64
|
- 1
|
65
65
|
- 9
|
66
66
|
- 0
|
67
67
|
- rc
|
68
|
-
-
|
69
|
-
version: 1.9.0.
|
68
|
+
- 5
|
69
|
+
version: 1.9.0.rc5
|
70
70
|
type: :runtime
|
71
71
|
version_requirements: *id003
|
72
72
|
- !ruby/object:Gem::Dependency
|
@@ -77,14 +77,14 @@ dependencies:
|
|
77
77
|
requirements:
|
78
78
|
- - "="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
hash:
|
80
|
+
hash: 15424175
|
81
81
|
segments:
|
82
82
|
- 1
|
83
83
|
- 9
|
84
84
|
- 0
|
85
85
|
- rc
|
86
|
-
-
|
87
|
-
version: 1.9.0.
|
86
|
+
- 5
|
87
|
+
version: 1.9.0.rc5
|
88
88
|
type: :runtime
|
89
89
|
version_requirements: *id004
|
90
90
|
- !ruby/object:Gem::Dependency
|