commonwatir 1.6.5 → 1.6.6.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (56) hide show
  1. data/CHANGES +461 -0
  2. data/{README.txt → LICENSE} +22 -48
  3. data/Rakefile +13 -11
  4. data/VERSION +1 -0
  5. data/lib/commonwatir.rb +3 -3
  6. data/lib/watir.rb +7 -6
  7. data/lib/watir/assertions.rb +44 -44
  8. data/lib/watir/browser.rb +149 -149
  9. data/lib/watir/browsers.rb +13 -12
  10. data/lib/watir/exceptions.rb +47 -47
  11. data/lib/watir/matches.rb +17 -17
  12. data/lib/watir/options.rb +53 -52
  13. data/lib/watir/testcase.rb +97 -58
  14. data/lib/watir/waiter.rb +91 -91
  15. data/unittests/attach_to_existing_window_test.rb +71 -0
  16. data/unittests/browser_test.rb +18 -0
  17. data/unittests/buttons_test.rb +224 -0
  18. data/unittests/dd_test.rb +70 -0
  19. data/unittests/dl_test.rb +68 -0
  20. data/unittests/dt_test.rb +68 -0
  21. data/unittests/element_collections_test.rb +22 -0
  22. data/unittests/em_test.rb +67 -0
  23. data/unittests/form2_test.rb +22 -0
  24. data/unittests/html/blankpage.html +12 -0
  25. data/unittests/html/buttons1.html +41 -0
  26. data/unittests/html/buttons2.html +61 -0
  27. data/unittests/html/definition_lists.html +48 -0
  28. data/unittests/html/emphasis.html +12 -0
  29. data/unittests/html/entertainment_com.html +668 -0
  30. data/unittests/html/frame_buttons.html +4 -0
  31. data/unittests/html/images/button.jpg +0 -0
  32. data/unittests/html/pass.html +10 -0
  33. data/unittests/html/phrase_elements.html +15 -0
  34. data/unittests/html/select_lists.html +18 -0
  35. data/unittests/html/utf8.html +12 -0
  36. data/unittests/html/visibility.html +90 -0
  37. data/unittests/html/watir_unit_tests.css +64 -0
  38. data/unittests/html/whitespace.html +29 -0
  39. data/unittests/inspect_test.rb +29 -0
  40. data/unittests/options.yml.example +13 -0
  41. data/unittests/select_list_test.rb +19 -0
  42. data/unittests/setup.rb +17 -0
  43. data/unittests/setup/browser.rb +14 -0
  44. data/unittests/setup/capture_io_helper.rb +17 -0
  45. data/unittests/setup/filter.rb +24 -0
  46. data/unittests/setup/lib.rb +22 -0
  47. data/unittests/setup/options.rb +29 -0
  48. data/unittests/setup/testUnitAddons.rb +8 -0
  49. data/unittests/setup/watir-unittest.rb +74 -0
  50. data/unittests/strong_test.rb +32 -0
  51. data/unittests/utf8_test.rb +24 -0
  52. data/unittests/visibility_test.rb +47 -0
  53. data/unittests/whitespace_test.rb +40 -0
  54. metadata +121 -39
  55. data/History.txt +0 -5
  56. data/Manifest.txt +0 -14
@@ -0,0 +1,71 @@
1
+ # feature tests for attaching to existing IE windows
2
+ # revision: $Revision: 1417 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
+ require 'unittests/setup'
6
+
7
+ class TC_ExistingWindow < Test::Unit::TestCase
8
+ location __FILE__
9
+ include Watir
10
+
11
+ def setup
12
+ @original_timeout = Browser.options[:attach_timeout]
13
+ @browsers = []
14
+ uses_page "pass.html"
15
+ end
16
+
17
+ def teardown
18
+ Browser.set_options :attach_timeout => @original_timeout
19
+ @browsers.each {|x| x.close}
20
+ end
21
+
22
+ def test_missing_window
23
+ Browser.set_options :attach_timeout => 0.1
24
+ assert_raises(NoMatchingWindowFoundException) { Browser.attach(:title, "missing") }
25
+ assert_raises(NoMatchingWindowFoundException) { Browser.attach(:title, /missing/) }
26
+ assert_raises(NoMatchingWindowFoundException) { Browser.attach(:url, "missing") }
27
+ assert_raises(NoMatchingWindowFoundException) { Browser.attach(:url, /missing/) }
28
+ end
29
+
30
+ # Open a few browsers so that the test has a few windows to choose
31
+ # from. The test harness has already opened a window that we won't
32
+ # use.
33
+ def open_several_windows
34
+ ["buttons1.html", "whitespace.html"].each do |file|
35
+ @browsers << Browser.start(self.class.html_root + file)
36
+ end
37
+ end
38
+
39
+ def test_existing_window
40
+ open_several_windows
41
+
42
+ b1 = Browser.attach(:title , /buttons/i)
43
+ assert_equal("Test page for buttons", b1.title)
44
+
45
+ b2 = Browser.attach(:title , "Test page for buttons")
46
+ assert_equal("Test page for buttons", b2.title)
47
+
48
+ b3 = Browser.attach(:url, /buttons1.html/)
49
+ assert_equal("Test page for buttons", b3.title)
50
+ end
51
+
52
+ def test_title_and_url_are_correct_after_reload
53
+ uses_page "whitespace.html"
54
+ assert_equal 'Test page for whitespace', browser.title
55
+ assert_match /whitespace.html/, browser.url
56
+ browser.link(:text, 'Login').click
57
+ assert_equal 'Pass Page', browser.title
58
+ assert_match /pass.html/, browser.url
59
+ end
60
+
61
+ tag_method :test_working_back_and_forth, :fails_on_firefox
62
+ def test_working_back_and_forth
63
+ open_several_windows
64
+ buttons = Browser.attach(:url, /buttons1.html/)
65
+ whitespace = Browser.attach(:url, /whitespace.html/)
66
+ assert_match /This button is a submit/, buttons.text
67
+ whitespace.link(:text, 'Login').click
68
+ assert_match /pass/i, whitespace.text
69
+ end
70
+ end
71
+
@@ -0,0 +1,18 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
+ require 'unittests/setup'
3
+
4
+ class TC_Browser < Test::Unit::TestCase
5
+ location __FILE__
6
+
7
+ def setup
8
+ uses_page "utf8.html" # could be any page really
9
+ end
10
+
11
+ def test_status_returns_window_status
12
+ browser.execute_script "window.status = 'All done!'"
13
+ assert_match /done/i, browser.status
14
+ end
15
+
16
+ end
17
+
18
+
@@ -0,0 +1,224 @@
1
+ # feature tests for Buttons
2
+ # revision: $Revision$
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
+ require 'unittests/setup'
6
+
7
+ class TC_Button < Test::Unit::TestCase
8
+ location __FILE__
9
+
10
+ def setup
11
+ uses_page "buttons1.html"
12
+ end
13
+
14
+ def test_exceptions_on_methods
15
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").id }
16
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").name }
17
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").disabled }
18
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").type }
19
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").value }
20
+ end
21
+
22
+ def test_exception_when_one_argument
23
+ assert_raises(UnknownObjectException) { browser.button( "Missing Caption").click }
24
+ end
25
+
26
+ def test_exceptions_with_click
27
+ assert_raises(UnknownObjectException) { browser.button(:caption, "Missing Caption").click }
28
+ assert_raises(UnknownObjectException) { browser.button(:id, "missingID").click }
29
+ end
30
+
31
+ def test_disabled_exception
32
+ assert_raises(ObjectDisabledException) { browser.button(:caption, "Disabled Button").click }
33
+ end
34
+
35
+ def test_exception_with_enabled
36
+ assert_raises(UnknownObjectException) { browser.button(:name, "noName").enabled? }
37
+ end
38
+
39
+ def test_properties
40
+ assert_equal("b1", browser.button(:index, 1).name)
41
+ assert_equal("b2", browser.button(:index, 1).id)
42
+ assert_equal("button", browser.button(:index, 1).type)
43
+ assert_equal("Click Me", browser.button(:index, 1).value)
44
+ assert_equal(false, browser.button(:index, 1).disabled)
45
+ assert_equal("italic_button", browser.button(:name, "b1").class_name)
46
+ assert_equal("", browser.button(:name , "b4").class_name)
47
+
48
+ assert_equal("b1", browser.button(:id, "b2").name)
49
+ assert_equal("b2", browser.button(:id, "b2").id)
50
+ assert_equal("button", browser.button(:id, "b2").type)
51
+
52
+ assert_equal("b4", browser.button(:index, 2).name)
53
+ assert_equal("b5", browser.button(:index, 2).id)
54
+ assert_equal("button", browser.button(:index, 2).type)
55
+ assert_equal("Disabled Button", browser.button(:index, 2).value)
56
+ assert_equal(true, browser.button(:index, 2).disabled)
57
+
58
+ assert_equal("", browser.button(:index, 2).title)
59
+ assert_equal("this is button1", browser.button(:index, 1).title)
60
+ end
61
+
62
+ def test_default_how
63
+ browser.button("Click Me").click
64
+ assert(browser.text.include?("PASS"))
65
+ end
66
+
67
+ def test_click_and_caption
68
+ browser.button(:caption, "Click Me").click
69
+ assert(browser.text.include?("PASS") )
70
+ end
71
+
72
+ def test_access_by_class
73
+ assert_equal('b1', browser.button(:class, 'italic_button').name)
74
+ end
75
+
76
+ def test_access_by_class_name
77
+ assert_equal('b1', browser.button(:class_name, 'italic_button').name)
78
+ end
79
+
80
+ def test_exists
81
+ assert(browser.button(:caption, "Click Me").exists?)
82
+ assert(browser.button(:caption, "Submit").exists?)
83
+ assert(browser.button(:name, "b1").exists?)
84
+ assert(browser.button(:id, "b2").exists?)
85
+ assert(browser.button(:caption, /sub/i).exists?)
86
+
87
+ assert_false(browser.button(:caption, "missingcaption").exists?)
88
+ assert_false(browser.button(:name, "missingname").exists?)
89
+ assert_false(browser.button(:id, "missingid").exists?)
90
+ assert_false(browser.button(:caption, /missing/i).exists?)
91
+ end
92
+
93
+ def test_enabled
94
+ assert(browser.button(:caption, "Click Me").enabled?)
95
+ assert_false(browser.button(:caption, "Disabled Button").enabled?)
96
+ assert_false(browser.button(:name, "b4").enabled?)
97
+ assert_false(browser.button(:id, "b5").enabled?)
98
+ end
99
+
100
+ end
101
+
102
+ class TC_Button2 < Test::Unit::TestCase
103
+ location __FILE__
104
+
105
+ def setup
106
+ uses_page "buttons2.html"
107
+ end
108
+
109
+ def test_exists
110
+ assert(browser.button(:caption, "Click Me2").exists?)
111
+ assert(browser.button(:caption, "Disabled Button2").exists?)
112
+ assert(browser.button(:caption, "Sign In").exists?)
113
+ end
114
+
115
+ def test_button2
116
+ assert_equal("b6", browser.button(:id, "b7").name)
117
+ assert_equal("b7", browser.button(:name, "b6").id)
118
+ assert_equal("Click Me2", browser.button(:id, "b7").value)
119
+ assert_equal(false, browser.button(:id, "b7").disabled)
120
+ assert_equal("italic_button", browser.button(:name, "b6").class_name )
121
+
122
+ assert_equal("b8", browser.button(:id, "b9").name)
123
+ assert_equal("b9", browser.button(:name, "b8").id)
124
+ assert_equal("Disabled Button2", browser.button(:id, "b9").value)
125
+ assert_equal(false, browser.button(:id, "b9").enabled?)
126
+ assert_equal("", browser.button(:name, "b8").class_name)
127
+ assert_equal("Sign In", browser.button(:caption, "Sign In").value)
128
+
129
+ assert(browser.button(:caption, "Click Me").enabled?)
130
+
131
+ assert_false(browser.button(:caption, "Disabled Button2").enabled?)
132
+
133
+ assert_raises(ObjectDisabledException) { browser.button(:caption, "Disabled Button2").click }
134
+
135
+ browser.button(:caption, "Click Me2").click
136
+ assert(browser.text.include?("PASS"))
137
+ end
138
+
139
+ tag_method :test_buttons_length, :fails_on_ie
140
+ def test_buttons_length
141
+ arrButtons = browser.buttons
142
+ assert_equal(7, arrButtons.length)
143
+ end
144
+
145
+ def test_buttons
146
+ arrButtons = browser.buttons
147
+ assert_equal("b2", arrButtons[1].id)
148
+ assert_equal("b5", arrButtons[2].id)
149
+ assert_equal("Submit", arrButtons[3].value)
150
+ assert_equal("sub3", arrButtons[4].name)
151
+ assert_equal("b7", arrButtons[5].id)
152
+ assert_equal("b9", arrButtons[6].id)
153
+ assert_equal("Sign In", arrButtons[7].value)
154
+ end
155
+
156
+ # Tests collection class
157
+ def test_class_buttons
158
+ arr_buttons = browser.buttons
159
+ arr_buttons.each do |b|
160
+ assert_class b, 'Button'
161
+ end
162
+ # test properties
163
+ assert_equal("b2", arr_buttons[1].id)
164
+ assert_equal("b1", arr_buttons[1].name)
165
+ assert_equal("button", arr_buttons[1].type)
166
+ assert_equal("Click Me", arr_buttons[1].value)
167
+ assert_equal(false, arr_buttons[1].disabled)
168
+ assert_equal("italic_button", arr_buttons[1].class_name)
169
+ assert_equal( "this is button1", arr_buttons[1].title)
170
+
171
+ assert_equal("b5", arr_buttons[2].id)
172
+ assert_equal("b4", arr_buttons[2].name)
173
+ assert_equal("button", arr_buttons[2].type)
174
+ assert_equal("Disabled Button", arr_buttons[2].value)
175
+ assert_equal(true, arr_buttons[2].disabled)
176
+ assert_equal( "", arr_buttons[2].title)
177
+ assert_equal("", arr_buttons[2].class_name)
178
+
179
+ assert_equal("Submit", arr_buttons[3].value)
180
+ assert_equal("sub3", arr_buttons[4].name)
181
+ assert_equal("b7", arr_buttons[5].id)
182
+ assert_equal("b9", arr_buttons[6].id)
183
+ assert_equal("Sign In", arr_buttons[7].value)
184
+ end
185
+
186
+ def test_hash_syntax
187
+ assert_equal('Click Me2', browser.button(:id => 'b7').value)
188
+ end
189
+
190
+ def test_class_and_index
191
+ assert_equal('Click Me2',
192
+ browser.button(:class => 'italic_button', :index => 2).value)
193
+ end
194
+
195
+ def test_name_and_id #sick, but what the hell
196
+ assert_equal('Disabled Button2',
197
+ browser.button(:name => 'b8', :id => 'b9').value)
198
+ end
199
+
200
+ def test_not_found_with_multi
201
+ exception = assert_raise(UnknownObjectException) do
202
+ browser.button(:value => 'Click Me', :index => 2).name
203
+ end
204
+ # can't assume hash ordering
205
+ assert_match(/Unable to locate element, using \{(:index=>2, :value=>"Click Me"|:value=>"Click Me", :index=>2)\}/, exception.message)
206
+ end
207
+ end
208
+
209
+ class TC_Button_Frame < Test::Unit::TestCase
210
+ location __FILE__
211
+
212
+ def setup
213
+ goto_page "frame_buttons.html"
214
+ end
215
+
216
+ def test_in_frame
217
+ assert(browser.frame("buttonFrame").button(:caption, "Click Me").enabled?)
218
+ end
219
+
220
+ def test_error_in_frame
221
+ assert_raises(UnknownObjectException) { browser.button(:caption, "Disabled Button").enabled?}
222
+ end
223
+ end
224
+
@@ -0,0 +1,70 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
+ require 'unittests/setup'
3
+
4
+ class TC_Dd < Test::Unit::TestCase
5
+ include Watir::Exception
6
+ location __FILE__
7
+
8
+ def setup
9
+ uses_page "definition_lists.html"
10
+ end
11
+
12
+ def test_exists
13
+ assert browser.dd(:id, "someone").exists?, "Could not find <dd> by :id"
14
+ assert browser.dd(:class, "name").exists?, "Could not find <dd> by :class"
15
+ assert_nothing_raised do
16
+ browser.dd(:xpath, "//dd[@id='someone']").locate
17
+ end
18
+ assert browser.dd(:xpath, "//dd[@id='someone']").exists?, "Could not find <dd> by :xpath"
19
+ assert browser.dd(:index, 1).exists?, "Could not find <dd> by :index"
20
+ end
21
+
22
+ def test_does_not_exist
23
+ assert !browser.dd(:id, 'no_such_id').exists?, "Found non-existing <dd>"
24
+ end
25
+
26
+ def test_attribute_class_name
27
+ assert_equal "name", browser.dd(:id, "someone").class_name
28
+ assert_equal "", browser.dd(:id, 'city').class_name
29
+ assert_raises(UnknownObjectException) do
30
+ browser.dd(:id, 'no_such_id').class_name
31
+ end
32
+ end
33
+
34
+ def test_attribute_id
35
+ assert_equal "someone", browser.dd(:class, 'name').id
36
+ assert_equal "", browser.dd(:class, 'address').id
37
+ assert_raises(UnknownObjectException) do
38
+ browser.dd(:id, 'no_such_id').id
39
+ end
40
+ end
41
+
42
+ def test_attribute_title
43
+ assert_equal "someone", browser.dd(:class, 'name').title
44
+ assert_equal "", browser.dd(:class, 'noop').title
45
+ assert_raises(UnknownObjectException) do
46
+ browser.dd(:id, 'no_such_id').title
47
+ end
48
+ end
49
+
50
+ def test_attribute_text
51
+ assert_equal "John Doe", browser.dd(:id, "someone").text
52
+ assert_equal "", browser.dd(:class, 'noop').text
53
+ assert_raises(UnknownObjectException) do
54
+ browser.dd(:id, 'no_such_id').text
55
+ end
56
+ end
57
+
58
+ def test_dd_iterator
59
+ assert_equal(11, browser.dds.length)
60
+ assert_equal("education", browser.dds[2].title)
61
+
62
+ browser.dds.each_with_index do |dd, idx|
63
+ assert_equal(browser.dd(:index,idx+1).text, dd.text)
64
+ assert_equal(browser.dd(:index,idx+1).id, dd.id)
65
+ assert_equal(browser.dd(:index,idx+1).class_name , dd.class_name)
66
+ assert_equal(browser.dd(:index,idx+1).title, dd.title)
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,68 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
+ require 'unittests/setup'
3
+
4
+ class TC_Dl < Test::Unit::TestCase
5
+ include Watir::Exception
6
+ location __FILE__
7
+
8
+ def setup
9
+ @html_dir = "#{File.dirname(__FILE__)}/html"
10
+ uses_page "definition_lists.html"
11
+ end
12
+
13
+ def test_exists
14
+ assert browser.dl(:id, "experience-list").exists?, "Could not find <dl> by :id"
15
+ assert browser.dl(:class, "list").exists?, "Could not find <dl> by :class"
16
+ assert browser.dl(:xpath, "//dl[@id='experience-list']").exists?, "Could not find <dl> by :xpath"
17
+ assert browser.dl(:index, 1).exists?, "Could not find <dl> by :index"
18
+ end
19
+
20
+ def test_does_not_exist
21
+ assert !browser.dl(:id, 'no_such_id').exists?, "Found non-existing <dl>"
22
+ end
23
+
24
+ def test_attribute_class_name
25
+ assert_equal "list", browser.dl(:id, "experience-list").class_name
26
+ assert_equal "", browser.dl(:id, 'noop').class_name
27
+ assert_raises(UnknownObjectException) do
28
+ browser.dl(:id, 'no_such_id').class_name
29
+ end
30
+ end
31
+
32
+ def test_attribute_id
33
+ assert_equal "experience-list", browser.dl(:class, 'list').id
34
+ assert_equal "", browser.dl(:class, 'personalia').id
35
+ assert_raises(UnknownObjectException) do
36
+ browser.dl(:id, 'no_such_id').id
37
+ end
38
+ end
39
+
40
+ def test_attribute_title
41
+ assert_equal "experience", browser.dl(:class, 'list').title
42
+ assert_equal "", browser.dl(:id, 'noop').title
43
+ assert_raises(UnknownObjectException) do
44
+ browser.dl(:id, 'no_such_id').title
45
+ end
46
+ end
47
+
48
+ def test_attribute_text
49
+ assert_match /11 years/, browser.dl(:id, "experience-list").text
50
+ assert_equal "", browser.dl(:id, 'noop').text
51
+ assert_raises(UnknownObjectException) do
52
+ browser.dl(:id, 'no_such_id').text
53
+ end
54
+ end
55
+
56
+ def test_dls_iterator
57
+ assert_equal(3, browser.dls.length)
58
+ assert_equal("experience-list", browser.dls[1].id)
59
+
60
+ browser.dls.each_with_index do |dl, idx|
61
+ assert_equal(browser.dl(:index,idx+1).text, dl.text)
62
+ assert_equal(browser.dl(:index,idx+1).id, dl.id)
63
+ assert_equal(browser.dl(:index,idx+1).class_name , dl.class_name)
64
+ assert_equal(browser.dl(:index,idx+1).title, dl.title)
65
+ end
66
+ end
67
+
68
+ end