watir-classic 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (213) hide show
  1. data/CHANGES +721 -0
  2. data/LICENSE +34 -0
  3. data/README.rdoc +78 -0
  4. data/VERSION +1 -0
  5. data/bin/watir-console +5 -0
  6. data/lib/watir-classic.rb +14 -0
  7. data/lib/watir-classic/IEDialog/Release/IEDialog.dll +0 -0
  8. data/lib/watir-classic/assertions.rb +44 -0
  9. data/lib/watir-classic/browser.rb +149 -0
  10. data/lib/watir-classic/browsers.rb +7 -0
  11. data/lib/watir-classic/close_all.rb +31 -0
  12. data/lib/watir-classic/container.rb +110 -0
  13. data/lib/watir-classic/contrib/enabled_popup.rb +21 -0
  14. data/lib/watir-classic/contrib/ie-new-process.rb +27 -0
  15. data/lib/watir-classic/contrib/page_checker.rb +29 -0
  16. data/lib/watir-classic/cookies.rb +80 -0
  17. data/lib/watir-classic/core.rb +43 -0
  18. data/lib/watir-classic/dialogs/file_field.rb +34 -0
  19. data/lib/watir-classic/dialogs/javascript.rb +43 -0
  20. data/lib/watir-classic/drag_and_drop_helper.rb +68 -0
  21. data/lib/watir-classic/element.rb +438 -0
  22. data/lib/watir-classic/element_collection.rb +109 -0
  23. data/lib/watir-classic/element_extensions.rb +69 -0
  24. data/lib/watir-classic/exceptions.rb +50 -0
  25. data/lib/watir-classic/form.rb +96 -0
  26. data/lib/watir-classic/frame.rb +47 -0
  27. data/lib/watir-classic/ie-class.rb +767 -0
  28. data/lib/watir-classic/ie-process.rb +47 -0
  29. data/lib/watir-classic/ie.rb +20 -0
  30. data/lib/watir-classic/image.rb +111 -0
  31. data/lib/watir-classic/input_elements.rb +480 -0
  32. data/lib/watir-classic/irb-history.rb +31 -0
  33. data/lib/watir-classic/link.rb +46 -0
  34. data/lib/watir-classic/locator.rb +243 -0
  35. data/lib/watir-classic/logger.rb +19 -0
  36. data/lib/watir-classic/matches.rb +23 -0
  37. data/lib/watir-classic/modal_dialog.rb +72 -0
  38. data/lib/watir-classic/module.rb +12 -0
  39. data/lib/watir-classic/non_control_elements.rb +114 -0
  40. data/lib/watir-classic/options.rb +56 -0
  41. data/lib/watir-classic/page-container.rb +114 -0
  42. data/lib/watir-classic/process.rb +20 -0
  43. data/lib/watir-classic/screen_capture.rb +115 -0
  44. data/lib/watir-classic/supported_elements.rb +172 -0
  45. data/lib/watir-classic/table.rb +224 -0
  46. data/lib/watir-classic/testcase.rb +97 -0
  47. data/lib/watir-classic/util.rb +35 -0
  48. data/lib/watir-classic/version.rb +4 -0
  49. data/lib/watir-classic/wait.rb +41 -0
  50. data/lib/watir-classic/wait_helper.rb +12 -0
  51. data/lib/watir-classic/waiter.rb +98 -0
  52. data/lib/watir-classic/win32.rb +40 -0
  53. data/lib/watir-classic/win32ole.rb +16 -0
  54. data/lib/watir-classic/win32ole/1.8.7/win32ole.so +0 -0
  55. data/lib/watir-classic/win32ole/1.9.3/win32ole.so +0 -0
  56. data/lib/watir-classic/window.rb +68 -0
  57. data/lib/watir-classic/xpath_locator.rb +52 -0
  58. data/rakefile.rb +54 -0
  59. data/unittests/all_tests.rb +10 -0
  60. data/unittests/buttons_xpath_test.rb +68 -0
  61. data/unittests/checkbox_test.rb +163 -0
  62. data/unittests/checkbox_xpath_test.rb +106 -0
  63. data/unittests/click_no_wait_test.rb +23 -0
  64. data/unittests/close_all_test.rb +17 -0
  65. data/unittests/core_tests.rb +17 -0
  66. data/unittests/css_selector_test.rb +44 -0
  67. data/unittests/css_test.rb +38 -0
  68. data/unittests/dialog_test.rb +64 -0
  69. data/unittests/div2_xpath_test.rb +21 -0
  70. data/unittests/div_test.rb +170 -0
  71. data/unittests/div_xpath_test.rb +95 -0
  72. data/unittests/document_standards.rb +63 -0
  73. data/unittests/element_collection_indexes_test.rb +57 -0
  74. data/unittests/element_collections_test.rb +100 -0
  75. data/unittests/element_test.rb +47 -0
  76. data/unittests/errorchecker_test.rb +31 -0
  77. data/unittests/filefield_test.rb +43 -0
  78. data/unittests/filefield_xpath_test.rb +35 -0
  79. data/unittests/form_test.rb +282 -0
  80. data/unittests/form_xpath_test.rb +254 -0
  81. data/unittests/frame_test.rb +165 -0
  82. data/unittests/google_form_test.rb +15 -0
  83. data/unittests/html/JavascriptClick.html +39 -0
  84. data/unittests/html/blankpage.html +11 -0
  85. data/unittests/html/buttons1.html +40 -0
  86. data/unittests/html/checkboxes1.html +89 -0
  87. data/unittests/html/click_no_wait.html +14 -0
  88. data/unittests/html/complex_table.html +35 -0
  89. data/unittests/html/cssTest.html +42 -0
  90. data/unittests/html/depot_store.html +59 -0
  91. data/unittests/html/div.html +92 -0
  92. data/unittests/html/div_xml.html +21 -0
  93. data/unittests/html/fileupload.html +44 -0
  94. data/unittests/html/formTest1.html +38 -0
  95. data/unittests/html/forms2.html +44 -0
  96. data/unittests/html/forms3.html +131 -0
  97. data/unittests/html/forms4.html +26 -0
  98. data/unittests/html/frame_buttons.html +4 -0
  99. data/unittests/html/frame_links.html +4 -0
  100. data/unittests/html/frame_multi.html +5 -0
  101. data/unittests/html/google_india.html +119 -0
  102. data/unittests/html/ie7_document_standards.html +9 -0
  103. data/unittests/html/ie8_document_standards.html +9 -0
  104. data/unittests/html/ie9_document_standards.html +9 -0
  105. data/unittests/html/iframe.html +3 -0
  106. data/unittests/html/iframeTest.html +17 -0
  107. data/unittests/html/iframeTest1.html +7 -0
  108. data/unittests/html/iframeTest2.html +5 -0
  109. data/unittests/html/images/1.gif +0 -0
  110. data/unittests/html/images/2.GIF +0 -0
  111. data/unittests/html/images/3.GIF +0 -0
  112. data/unittests/html/images/button.jpg +0 -0
  113. data/unittests/html/images/circle.jpg +0 -0
  114. data/unittests/html/images/map.GIF +0 -0
  115. data/unittests/html/images/map2.gif +0 -0
  116. data/unittests/html/images/minus.GIF +0 -0
  117. data/unittests/html/images/originaltriangle.jpg +0 -0
  118. data/unittests/html/images/plus.gif +0 -0
  119. data/unittests/html/images/square.jpg +0 -0
  120. data/unittests/html/images/triangle.jpg +0 -0
  121. data/unittests/html/images1.html +65 -0
  122. data/unittests/html/javascriptevents.html +33 -0
  123. data/unittests/html/link_pass.html +11 -0
  124. data/unittests/html/links1.html +37 -0
  125. data/unittests/html/links2.html +11 -0
  126. data/unittests/html/links_multi.html +12 -0
  127. data/unittests/html/list_matters.html +720 -0
  128. data/unittests/html/lists.html +18 -0
  129. data/unittests/html/map_test.html +30 -0
  130. data/unittests/html/modal_dialog.html +10 -0
  131. data/unittests/html/modal_dialog_launcher.html +12 -0
  132. data/unittests/html/multiple_specifiers.html +64 -0
  133. data/unittests/html/nestedFrames.html +6 -0
  134. data/unittests/html/new_browser.html +17 -0
  135. data/unittests/html/pass.html +13 -0
  136. data/unittests/html/popups1.html +59 -0
  137. data/unittests/html/pre.html +29 -0
  138. data/unittests/html/quirks_document_standards.html +8 -0
  139. data/unittests/html/radioButtons1.html +71 -0
  140. data/unittests/html/select_tealeaf.html +54 -0
  141. data/unittests/html/selectboxes1.html +52 -0
  142. data/unittests/html/simple_table.html +25 -0
  143. data/unittests/html/simple_table_buttons.html +104 -0
  144. data/unittests/html/simple_table_columns.html +75 -0
  145. data/unittests/html/table1.html +179 -0
  146. data/unittests/html/tableCell_using_xpath.html +19 -0
  147. data/unittests/html/table_and_tablerow_to_a.html +174 -0
  148. data/unittests/html/textarea.html +30 -0
  149. data/unittests/html/textfields1.html +100 -0
  150. data/unittests/html/textsearch.html +44 -0
  151. data/unittests/html/wallofcheckboxes.html +1003 -0
  152. data/unittests/html/xpath_nbsp.html +11 -0
  153. data/unittests/html/zeroindex.html +11 -0
  154. data/unittests/ie_exists_test.rb +16 -0
  155. data/unittests/ie_mock.rb +94 -0
  156. data/unittests/ie_test.rb +54 -0
  157. data/unittests/images_test.rb +156 -0
  158. data/unittests/images_xpath_test.rb +90 -0
  159. data/unittests/index_specifier_test.rb +31 -0
  160. data/unittests/js_events_test.rb +31 -0
  161. data/unittests/links_multi_test.rb +34 -0
  162. data/unittests/links_test.rb +131 -0
  163. data/unittests/links_xpath_test.rb +38 -0
  164. data/unittests/lists_test.rb +23 -0
  165. data/unittests/map_test.rb +98 -0
  166. data/unittests/minmax_test.rb +37 -0
  167. data/unittests/navigate_test.rb +38 -0
  168. data/unittests/nbsp_xpath_test.rb +16 -0
  169. data/unittests/no_wait_test.rb +28 -0
  170. data/unittests/non_core_tests.rb +12 -0
  171. data/unittests/other/all_tests_concurrent.rb +57 -0
  172. data/unittests/other/navigate_exception_test.rb +24 -0
  173. data/unittests/other/rexml_unit_test.rb +27 -0
  174. data/unittests/other/screen_capture_test.rb +53 -0
  175. data/unittests/other/testcase_method_order_test.rb +36 -0
  176. data/unittests/other/testcase_verify_test.rb +25 -0
  177. data/unittests/other/wait_until_test.rb +102 -0
  178. data/unittests/pagecontainstext_test.rb +69 -0
  179. data/unittests/parent_child_test.rb +27 -0
  180. data/unittests/perf_test.rb +20 -0
  181. data/unittests/pre_test.rb +49 -0
  182. data/unittests/radios_test.rb +181 -0
  183. data/unittests/radios_xpath_test.rb +100 -0
  184. data/unittests/security_setting_test.rb +24 -0
  185. data/unittests/selectbox_test.rb +144 -0
  186. data/unittests/selectbox_xpath_test.rb +102 -0
  187. data/unittests/setup.rb +69 -0
  188. data/unittests/speed_settings_test.rb +67 -0
  189. data/unittests/table_cell_using_xpath_test.rb +34 -0
  190. data/unittests/table_test.rb +296 -0
  191. data/unittests/table_xpath_test.rb +109 -0
  192. data/unittests/test_tests.rb +9 -0
  193. data/unittests/textarea_test.rb +92 -0
  194. data/unittests/textarea_xpath_test.rb +77 -0
  195. data/unittests/textfield_for_ch_char_test.rb +32 -0
  196. data/unittests/textfields_test.rb +184 -0
  197. data/unittests/textfields_xpath_test.rb +110 -0
  198. data/unittests/version_test.rb +15 -0
  199. data/unittests/win32ole_so_test.rb +35 -0
  200. data/unittests/window_tests.rb +10 -0
  201. data/unittests/windows/attach_to_existing_window_test.rb +52 -0
  202. data/unittests/windows/attach_to_new_window_test.rb +74 -0
  203. data/unittests/windows/close_window_test.rb +20 -0
  204. data/unittests/windows/frame_links_test.rb +23 -0
  205. data/unittests/windows/ie-each_test.rb +46 -0
  206. data/unittests/windows/modal_dialog_test.rb +95 -0
  207. data/unittests/windows/new_process_test.rb +24 -0
  208. data/unittests/windows/new_test.rb +58 -0
  209. data/unittests/windows/open_close_test.rb +19 -0
  210. data/unittests/windows/send_keys_test.rb +26 -0
  211. data/unittests/xpath_tests.rb +11 -0
  212. data/watir-rdoc.rb +7 -0
  213. metadata +370 -0
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
+ <!doctype html>
3
+ <head>
4
+ <title>Test page for xpath with nbsp</title>
5
+ </head>
6
+ <body>
7
+ <form>
8
+ <div>Hello&nbsp;world</div>
9
+ </form>
10
+ </body>
11
+ </html>
@@ -0,0 +1,11 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2
+ <html>
3
+ <table id="a_table">
4
+ <tr id="first"><td>alt_1 - boring text</td></tr>
5
+ <tr id="second"><td>alt_2 - great text</td></tr>
6
+ <tr id="third"><td>alt_1 - the best text ever<td></tr>
7
+ <tr id="fourth"><td>alt_2 - okay text<td></tr>
8
+ <tr id="fifth"><td>alt_1 - supreme text<td></tr>
9
+ <tr id="sixth"><td>alt_2 - middle of the road text<td></tr>
10
+ </table>
11
+ </html>
@@ -0,0 +1,16 @@
1
+ # test IE#exists?
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+
6
+ class TC_IENotExists < Test::Unit::TestCase
7
+ def setup
8
+ @ie = Watir::IE.new
9
+ end
10
+
11
+ def test_some_one_else_closed_it
12
+ @ie.ie.quit
13
+ sleep 0.3 # give it some time to close
14
+ assert_false(@ie.exists?)
15
+ end
16
+ end
@@ -0,0 +1,94 @@
1
+ # mock library for testing the IE controller
2
+ require 'watir-classic'
3
+
4
+ class FakeFrame
5
+ def length
6
+ return 0
7
+ end
8
+ end
9
+
10
+ class FakeDoc
11
+
12
+ attr_accessor :links, :all
13
+
14
+ def initialize
15
+ @links = ""
16
+ @doc = self
17
+ end
18
+
19
+ def getElementsByTagName(tag)
20
+ @doc.links
21
+ end
22
+
23
+ def frames
24
+ return FakeFrame.new
25
+ end
26
+
27
+ def readyState
28
+ return "complete"
29
+ end
30
+
31
+ def addLink(value)
32
+ if @links.nil?
33
+ @links = value
34
+ else
35
+ @links << value
36
+ end
37
+ end
38
+ def location
39
+ self
40
+ end
41
+ def url
42
+ return "file://fake"
43
+ end
44
+ alias :href :url
45
+ end
46
+
47
+ class StubExplorer
48
+
49
+ attr_accessor :timeToWait
50
+
51
+ def initialize
52
+ @timeToWait = 1
53
+ @visible = $HIDE_IE
54
+ @document = FakeDoc.new
55
+ end
56
+
57
+ def document
58
+ return @document
59
+ end
60
+
61
+ def busy
62
+ sleep @timeToWait
63
+ return FALSE
64
+ end
65
+
66
+ def readyState
67
+ return 4
68
+ end
69
+
70
+ def visible=(value)
71
+ end
72
+
73
+ def visible
74
+ end
75
+
76
+ end
77
+
78
+ class TestIE < Watir::IE
79
+
80
+ def create_browser_window
81
+ @ie = StubExplorer.new
82
+ end
83
+
84
+ def addLink(link)
85
+ @ie.document.addLink(link)
86
+ end
87
+
88
+ def setTimeToWait(time = 1)
89
+ @ie.timeToWait = time
90
+ end
91
+
92
+ def goto(url)
93
+ end
94
+ end
@@ -0,0 +1,54 @@
1
+ # Unit Test for Internet Explorer
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+ require 'unittests/ie_mock'
6
+
7
+ class TC_ie < Test::Unit::TestCase
8
+ include Watir::Exception
9
+
10
+ def setup
11
+ @faked_ie = TestIE.new
12
+ end
13
+
14
+ def test_waitForIE
15
+ wait_time = 1
16
+ # @faked_ie.logger.level = Logger::DEBUG
17
+
18
+ @faked_ie.setTimeToWait wait_time
19
+ begin_time = Time.now
20
+ @faked_ie.wait
21
+ elapsed_time = Time.now - begin_time
22
+ assert_in_delta(wait_time, elapsed_time, 0.5)
23
+ end
24
+
25
+ def test_getLink_ByIndexReturnsNilOnNoLinks
26
+ assert_false(@faked_ie.link(:index, 0).exists?)
27
+ end
28
+
29
+ def test_getLink_ByBadHow
30
+ @faked_ie.addLink "foo"
31
+ assert_raise(UnknownObjectException) do
32
+ @faked_ie.link(:no_such_mechanism, "verifying error handling").click
33
+ end
34
+ end
35
+
36
+ def test_execute_script
37
+ script = %q[
38
+ var x = 'something';
39
+ var y = " else";
40
+ x + y;
41
+ ]
42
+ assert_equal "something else", browser.execute_script(script)
43
+ end
44
+
45
+ def test_getLink_ByUrlReturnsNilOnNoLinks
46
+ assert_false(@faked_ie.link(:url, "whatever").exists?)
47
+ end
48
+
49
+ def test_getLink_ByTextReturnsNilOnNoLinks
50
+ assert_false(@faked_ie.link(:text, "whatever").exists?)
51
+ end
52
+
53
+ end
54
+
@@ -0,0 +1,156 @@
1
+ # feature tests for Images
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+ require 'ftools'
6
+ require 'webrick'
7
+ require 'watir-classic/cookiemanager'
8
+
9
+ class TC_Images < Test::Unit::TestCase
10
+ tags :must_be_visible, :creates_windows
11
+ include Watir
12
+
13
+ def setup
14
+ goto_page "images1.html"
15
+ @saved_img_path = build_path("sample.img.dat");
16
+ clean_saved_image
17
+ end
18
+
19
+ def teardown
20
+ clean_saved_image
21
+ end
22
+
23
+ def test_imageExists
24
+ assert( ! browser.image(:name , "missing_name").exists? )
25
+ assert( browser.image(:name , "circle").exists? )
26
+ assert( browser.image(:name , /circ/ ).exists? )
27
+
28
+ assert( ! browser.image(:id , "missing_id").exists? )
29
+ assert( browser.image(:id , "square").exists? )
30
+ assert( browser.image(:id , /squ/ ).exists? )
31
+
32
+ assert( ! browser.image(:src, "missingsrc.gif").exists? )
33
+
34
+ assert( browser.image(:src, "file:///#{$myDir}/html/images/triangle.jpg").exists? )
35
+ assert( browser.image(:src , /triangle/ ).exists? )
36
+
37
+ assert( browser.image(:alt , "circle" ).exists? )
38
+ assert( browser.image(:alt , /cir/ ).exists? )
39
+
40
+ assert( ! browser.image(:alt , "triangle" ).exists? )
41
+ assert( ! browser.image(:alt , /tri/ ).exists? )
42
+
43
+ assert( browser.image(:title, 'square_image').exists? )
44
+ assert( ! browser.image(:title, 'pentagram').exists? )
45
+ end
46
+
47
+ def test_image_click
48
+ assert_raises(UnknownObjectException) { browser.image(:name, "no_image_with_this").click }
49
+ assert_raises(UnknownObjectException) { browser.image(:id, "no_image_with_this").click }
50
+ assert_raises(UnknownObjectException) { browser.image(:src, "no_image_with_this").click}
51
+ assert_raises(UnknownObjectException) { browser.image(:alt, "no_image_with_this").click}
52
+
53
+ # test for bug 1882
54
+ browser.text_field(:name , "text1").clear
55
+ browser.button(:value , /Pos/ ).click
56
+ assert_equal('clicked' , browser.text_field(:name , "text1" ).value )
57
+
58
+ # test for disabled button
59
+ assert( ! browser.image(:name , 'disabler_test').disabled )
60
+ browser.button(:name , 'disable_img').click
61
+
62
+ assert( browser.image(:name , 'disabler_test').disabled )
63
+ browser.button(:name , 'disable_img').click
64
+
65
+ browser.image(:src, /button/).click
66
+ assert(browser.text.include?("PASS") )
67
+ end
68
+
69
+ def test_imageHasLoaded
70
+ assert_raises(UnknownObjectException) { browser.image(:name, "no_image_with_this").hasLoaded? }
71
+ assert_raises(UnknownObjectException) { browser.image(:id, "no_image_with_this").hasLoaded? }
72
+ assert_raises(UnknownObjectException) { browser.image(:src, "no_image_with_this").hasLoaded? }
73
+ assert_raises(UnknownObjectException) { browser.image(:alt, "no_image_with_this").hasLoaded? }
74
+
75
+ assert( ! browser.image(:name, "themissingimage").hasLoaded? )
76
+ assert( browser.image(:name, "circle").hasLoaded? )
77
+
78
+ assert( browser.image(:alt, "circle").hasLoaded? )
79
+ assert( browser.image(:alt, /cir/ ).hasLoaded? )
80
+ end
81
+
82
+ def test_image_properties
83
+ assert_raises(UnknownObjectException) { browser.image(:name, "no_image_with_this").hasLoaded? }
84
+ assert_raises(UnknownObjectException) { browser.image(:id, "no_image_with_this").hasLoaded? }
85
+ assert_raises(UnknownObjectException) { browser.image(:src, "no_image_with_this").hasLoaded? }
86
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).hasLoaded? }
87
+
88
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).name }
89
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).id }
90
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).src }
91
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).value }
92
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).height }
93
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).width }
94
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).fileCreatedDate }
95
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).fileSize }
96
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).alt}
97
+ assert_raises(UnknownObjectException) { browser.image(:index, 82).title}
98
+
99
+ assert_equal( "" , browser.image(:index, 1).name )
100
+ assert_equal( "square" , browser.image(:index, 1).id )
101
+ assert_match( /square\.jpg/i ,browser.image(:index, 1).src )
102
+ assert_equal( "" , browser.image(:index, 1).value )
103
+ assert_equal( 88 , browser.image(:index, 1).height )
104
+ assert_equal( 88 , browser.image(:index, 1).width )
105
+
106
+ # this line fails, as the date is when it is installed on the local oc, not the date the file was really created
107
+ #assert_equal( "03/10/2005" , browser.image(:index, 2).fileCreatedDate )
108
+ assert_equal( 788, browser.image(:index, 1).fileSize )
109
+
110
+ # tool tips: alt text + title
111
+ assert_equal('circle' , browser.image(:index, 5).alt)
112
+ assert_equal( "" , browser.image(:index, 1).alt)
113
+ assert_equal('square_image', browser.image(:id, 'square').title)
114
+
115
+ # TODO: to string tests -- output should be verified!
116
+ browser.image(:name , "circle").to_s
117
+ browser.image(:index , 1).to_s
118
+ end
119
+
120
+ def test_image_iterator
121
+ assert_equal(6 , browser.images.length)
122
+ assert_equal("" , browser.images[1].name )
123
+ assert_equal("square", browser.images[1].id )
124
+ assert_match(/square/, browser.images[1].src )
125
+
126
+ index = 0
127
+ browser.images.each do |i|
128
+ assert_equal( browser.image(:index, index).id , i.id )
129
+ assert_equal( browser.image(:index, index).name , i.name )
130
+ assert_equal( browser.image(:index, index).src , i.src )
131
+ assert_equal( browser.image(:index, index).height , i.height )
132
+ assert_equal( browser.image(:index, index).width , i.width )
133
+
134
+ index += 1
135
+ end
136
+ assert_equal(index, browser.images.length)
137
+ end
138
+
139
+ def test_save_local_image
140
+ browser.images[1].save(build_windows_path("sample.img.dat"))
141
+ assert(File.compare(@saved_img_path, browser.images[1].src.gsub(/^file:\/\/\//, '')))
142
+ end
143
+
144
+ def clean_saved_image
145
+ File.delete(@saved_img_path) if (File.exists?(@saved_img_path))
146
+ end
147
+
148
+ def build_windows_path(part)
149
+ build_path(part).gsub(/\//, "\\")
150
+ end
151
+
152
+ def build_path(part)
153
+ "#{$myDir}/#{part}"
154
+ end
155
+ end
156
+
@@ -0,0 +1,90 @@
1
+ # feature tests for Images
2
+
3
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
4
+ require 'unittests/setup'
5
+ require 'ftools'
6
+ require 'webrick'
7
+ require 'watir-classic/cookiemanager'
8
+
9
+ class TC_Images_XPath < Test::Unit::TestCase
10
+ include Watir
11
+
12
+ def setup
13
+ gotoImagePage
14
+ end
15
+
16
+ def gotoImagePage
17
+ goto_page "images1.html"
18
+ end
19
+
20
+ def test_imageExists
21
+ assert_false( browser.image(:xpath , "//img[@name='missing_name']/").exists? )
22
+ assert( browser.image(:xpath , "//img[@name='circle']/").exists? )
23
+ # assert( browser.image(:name , /circ/ ).exists? )
24
+
25
+ assert_false( browser.image(:xpath , "//img[@id='missing_id']/").exists? )
26
+ assert( browser.image(:xpath , "//img[@id='square']/").exists? )
27
+ # assert( browser.image(:id , /squ/ ).exists? )
28
+
29
+ assert_false( browser.image(:xpath , "//img[@src='missingsrc.gif']/").exists? )
30
+
31
+ # BP -- This fails for me but not for Paul. It doesn't make sense to me that it should pass.
32
+ # assert( browser.image(:src , "file:///#{$myDir}/html/images/triangle.jpg").exists? )
33
+ # assert( browser.image(:src , /triangle/ ).exists? )
34
+
35
+ assert( browser.image(:alt , "circle" ).exists? )
36
+ # assert( browser.image(:alt , /cir/ ).exists? )
37
+
38
+ assert_false( browser.image(:alt , "triangle" ).exists? )
39
+ # assert_false( browser.image(:alt , /tri/ ).exists? )
40
+ end
41
+
42
+ def test_image_click
43
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']/").click }
44
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']/").click }
45
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']/").click}
46
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@alt='no_image_with_this']/").click}
47
+
48
+ # test for bug 1882
49
+ browser.text_field(:name , "text1").clear
50
+ browser.button(:value , /Pos/ ).click
51
+ assert_equal('clicked' , browser.text_field(:name , "text1" ).value )
52
+
53
+ # test for disabled button
54
+ # assert_false( browser.image(:name , 'disabler_test').disabled )
55
+ # browser.button(:name , 'disable_img').click
56
+
57
+ # assert( browser.image(:name , 'disabler_test').disabled )
58
+ # browser.button(:name , 'disable_img').click
59
+
60
+ # browser.image(:src, /button/).click
61
+ # assert(browser.text.include?("PASS") )
62
+
63
+ end
64
+
65
+
66
+
67
+ def test_imageHasLoaded
68
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']/").hasLoaded? }
69
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']/").hasLoaded? }
70
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']/").hasLoaded? }
71
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@alt='no_image_with_this']/").hasLoaded? }
72
+
73
+ assert_false( browser.image(:xpath , "//img[@name='themissingimage']/").hasLoaded? )
74
+ assert( browser.image(:xpath , "//img[@name='circle']/").hasLoaded? )
75
+
76
+ assert( browser.image(:xpath , "//img[@alt='circle']/").hasLoaded? )
77
+ # assert( browser.image(:alt, /cir/ ).hasLoaded? )
78
+ end
79
+
80
+ def test_image_properties
81
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']/").hasLoaded? }
82
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']/").hasLoaded? }
83
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']/").hasLoaded? }
84
+
85
+ # to string tests -- output should be verified!
86
+ puts browser.image(:xpath , "//img[@name='circle']/").to_s
87
+ end
88
+
89
+ end
90
+
@@ -0,0 +1,31 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
+ require 'unittests/setup'
3
+
4
+ class TC_BaseIndex < Test::Unit::TestCase
5
+ include Watir::Exception
6
+
7
+ def setup
8
+ goto_page "multiple_specifiers.html"
9
+ end
10
+
11
+ def test_default_index
12
+ assert "one", browser.table.row.cell.class_name
13
+ end
14
+
15
+ def test_zero_based_indexing
16
+ assert "one", browser.button(:index => 0).class_name
17
+ assert "two", browser.button(:index => 1).class_name
18
+
19
+ Watir::IE.zero_based_indexing = false
20
+
21
+ assert "one", browser.button(:index => 1).class_name
22
+ assert "two", browser.button(:index => 2).class_name
23
+
24
+ Watir::IE.zero_based_indexing = true
25
+
26
+ assert "one", browser.button(:index => 0).class_name
27
+ assert "two", browser.button(:index => 1).class_name
28
+ end
29
+
30
+ end
31
+