firewatir 1.6.2 → 1.6.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. data/LICENSE +32 -0
  2. data/lib/firewatir.rb +40 -50
  3. data/lib/firewatir/container.rb +491 -534
  4. data/lib/firewatir/document.rb +239 -0
  5. data/lib/firewatir/element.rb +1365 -0
  6. data/lib/firewatir/element_collections.rb +314 -0
  7. data/lib/firewatir/elements/button.rb +15 -0
  8. data/lib/firewatir/elements/file_field.rb +29 -0
  9. data/lib/firewatir/elements/form.rb +40 -0
  10. data/lib/firewatir/elements/frame.rb +55 -0
  11. data/lib/firewatir/elements/hidden.rb +56 -0
  12. data/lib/firewatir/elements/image.rb +139 -0
  13. data/lib/firewatir/elements/input_element.rb +44 -0
  14. data/lib/firewatir/elements/link.rb +76 -0
  15. data/lib/firewatir/elements/non_control_element.rb +53 -0
  16. data/lib/firewatir/elements/non_control_elements.rb +108 -0
  17. data/lib/firewatir/elements/not_used.rb +278 -0
  18. data/lib/firewatir/elements/option.rb +131 -0
  19. data/lib/firewatir/elements/radio_check_common.rb +163 -0
  20. data/lib/firewatir/elements/select_list.rb +188 -0
  21. data/lib/firewatir/elements/table.rb +218 -0
  22. data/lib/firewatir/elements/table_cell.rb +54 -0
  23. data/lib/firewatir/elements/table_row.rb +100 -0
  24. data/lib/firewatir/elements/text_field.rb +218 -0
  25. data/lib/firewatir/exceptions.rb +10 -10
  26. data/lib/firewatir/firefox.rb +1040 -1127
  27. data/lib/firewatir/jssh_socket.rb +101 -0
  28. data/lib/firewatir/version.rb +5 -5
  29. data/unittests/attach_to_new_window_test.rb +49 -42
  30. data/unittests/bug_fixes_test.rb +195 -198
  31. data/unittests/buttons_xpath_test.rb +88 -88
  32. data/unittests/checkbox_test.rb +158 -155
  33. data/unittests/checkbox_xpath_test.rb +107 -107
  34. data/unittests/div_test.rb +275 -276
  35. data/unittests/filefield_test.rb +49 -45
  36. data/unittests/filefield_xpath_test.rb +35 -35
  37. data/unittests/form_test.rb +296 -308
  38. data/unittests/frame_test.rb +159 -152
  39. data/unittests/hidden_test.rb +85 -85
  40. data/unittests/hidden_xpath_test.rb +72 -72
  41. data/unittests/html/blankpage.html +11 -11
  42. data/unittests/html/buttons1.html +61 -61
  43. data/unittests/html/cssTest.html +42 -42
  44. data/unittests/html/div.html +72 -72
  45. data/unittests/html/fileupload.html +45 -45
  46. data/unittests/html/formTest1.html +38 -38
  47. data/unittests/html/forms2.html +45 -45
  48. data/unittests/html/frame_buttons.html +3 -3
  49. data/unittests/html/iframeTest.html +14 -14
  50. data/unittests/html/iframeTest1.html +13 -13
  51. data/unittests/html/iframeTest2.html +5 -5
  52. data/unittests/html/links1.html +42 -42
  53. data/unittests/html/nestedFrames.html +6 -6
  54. data/unittests/html/new_browser.html +1 -0
  55. data/unittests/html/new_browser_popup.html +8 -0
  56. data/unittests/html/pass.html +9 -9
  57. data/unittests/html/pre.html +27 -27
  58. data/unittests/html/redirect.html +10 -10
  59. data/unittests/html/redirect1.html +8 -8
  60. data/unittests/html/redirect2.html +8 -8
  61. data/unittests/html/redirect3.html +8 -8
  62. data/unittests/html/simple_table_columns.html +74 -74
  63. data/unittests/html/table1.html +165 -165
  64. data/unittests/html/textfields1.html +62 -62
  65. data/unittests/images_test.rb +198 -205
  66. data/unittests/images_xpath_test.rb +118 -119
  67. data/unittests/javascript_test.rb +75 -75
  68. data/unittests/links_test.rb +231 -232
  69. data/unittests/links_xpath_test.rb +79 -79
  70. data/unittests/mozilla_all_tests.rb +7 -7
  71. data/unittests/pre_test.rb +75 -76
  72. data/unittests/radios_xpath_test.rb +101 -101
  73. data/unittests/redirect_test.rb +41 -41
  74. data/unittests/selectbox_test.rb +142 -142
  75. data/unittests/selectbox_xpath_test.rb +129 -129
  76. data/unittests/setup.rb +29 -30
  77. data/unittests/table_test.rb +385 -373
  78. data/unittests/table_xpath_test.rb +185 -185
  79. data/unittests/textfields_test.rb +234 -233
  80. data/unittests/textfields_xpath_test.rb +113 -113
  81. metadata +33 -11
  82. data/lib/firewatir/MozillaBaseElement.rb +0 -1863
  83. data/lib/firewatir/htmlelements.rb +0 -1911
  84. data/unittests/iostring.rb +0 -30
  85. data/unittests/iostring_test.rb +0 -48
@@ -1,119 +1,118 @@
1
- # feature tests for Images
2
- # revision: $Revision: 1.0 $
3
-
4
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
- require 'unittests/setup'
6
- require 'ftools'
7
- require 'webrick'
8
-
9
- class TC_Images_XPath < Test::Unit::TestCase
10
-
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(:xpath , "//img[contains(@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(:xpath , "//img[contains(@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(:xpath , "//img[contains(@src , 'triangle')]" ).exists? )
34
-
35
- assert( browser.image(:alt , "circle" ).exists? )
36
- assert( browser.image(:xpath , "//img[contains(@alt , 'cir')]" ).exists? )
37
-
38
- assert_false( browser.image(:alt , "triangle" ).exists? )
39
- assert_false( browser.image(:xpath , "//img[contains(@alt , 'tri')]" ).exists? )
40
- end
41
-
42
- tag_method :test_element_by_xpath_class, :fails_on_ie
43
- def test_element_by_xpath_class
44
- # FIXME getting HTMLAnchorElement instead of HTMLImageElement
45
- # TODO: This should return null if object is not there.
46
- #element = browser.element_by_xpath("//img[@name='missing_name']")
47
- #assert(element.instance_of?(Image),"element class should be #{Image}; got #{element.class}")
48
- element = browser.element_by_xpath("//img[@name='circle']")
49
- assert_class(element, 'Image')
50
- element = browser.element_by_xpath("//img[contains(@name , 'circ')]")
51
- assert_class(element, 'Image')
52
- # TODO: This should return null if object is not there.
53
- #element = browser.element_by_xpath("//img[@id='missing_id']")
54
- #assert(element.instance_of?(Image),"element class should be #{Image}; got #{element.class}")
55
- element = browser.element_by_xpath("//img[@id='square']")
56
- assert_class(element, 'Image')
57
- element = browser.element_by_xpath("//img[contains(@id, 'squ')]")
58
- assert_class(element, 'Image')
59
- element = browser.element_by_xpath("//img[contains(@src , 'triangle')]")
60
- assert_class(element, 'Image')
61
- element = browser.element_by_xpath("//img[contains(@alt , 'cir')]")
62
- assert_class(element, 'Image')
63
- # TODO: This should return null if object is not there.
64
- #element = browser.element_by_xpath("//img[contains(@alt , 'tri')]")
65
- #assert(element.instance_of?(Image),"element class should be #{Image}; got #{element.class}")
66
- end
67
-
68
- def test_image_click
69
- assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']").click }
70
- assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']").click }
71
- assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']").click}
72
- assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@alt='no_image_with_this']").click}
73
-
74
- # test for bug 1882
75
- browser.text_field(:name , "text1").clear
76
- browser.button(:value , /Pos/ ).click
77
- assert_equal('clicked' , browser.text_field(:name , "text1" ).value )
78
-
79
-
80
- # test for disabled button. Click the button to make it disabled
81
- browser.button(:name , 'disable_img').click
82
- assert( browser.image(:name , 'disabler_test').disabled )
83
-
84
- # Click button again to make it enabled.
85
- browser.button(:name , 'disable_img').click
86
- assert( ! browser.image(:name , 'disabler_test').disabled )
87
-
88
- browser.image(:src, /button/).click
89
- assert(browser.text.include?("PASS") )
90
-
91
- end
92
-
93
-
94
- # TODO: Need to see alternative for this in Mozilla
95
- #def test_imageHasLoaded
96
- # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']").hasLoaded? }
97
- # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']").hasLoaded? }
98
- # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']").hasLoaded? }
99
- # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@alt='no_image_with_this']").hasLoaded? }
100
- #
101
- # assert_false( browser.image(:xpath , "//img[@name='themissingimage']").hasLoaded? )
102
- # assert( browser.image(:xpath , "//img[@name='circle']").hasLoaded? )
103
- #
104
- # assert( browser.image(:xpath , "//img[@alt='circle']").hasLoaded? )
105
- # # assert( browser.image(:alt, /cir/ ).hasLoaded? )
106
- #end
107
-
108
- def test_image_properties
109
- # TODO: Need to see alternative for this in Mozilla
110
- #assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']").hasLoaded? }
111
- #assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']").hasLoaded? }
112
- #assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']").hasLoaded? }
113
-
114
- # to string tests -- output should be verified!
115
- puts browser.image(:xpath , "//img[@name='circle']").to_s
116
- end
117
-
118
- end
119
-
1
+ # feature tests for Images
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
+ require 'unittests/setup'
6
+ require 'webrick'
7
+
8
+ class TC_Images_XPath < Test::Unit::TestCase
9
+
10
+
11
+ def setup
12
+ gotoImagePage
13
+ end
14
+
15
+ def gotoImagePage()
16
+ goto_page("images1.html")
17
+ end
18
+
19
+ def test_imageExists
20
+ assert_false( browser.image(:xpath , "//img[@name='missing_name']").exists? )
21
+ assert( browser.image(:xpath , "//img[@name='circle']").exists? )
22
+ assert( browser.image(:xpath , "//img[contains(@name , 'circ')]" ).exists? )
23
+
24
+ assert_false( browser.image(:xpath , "//img[@id='missing_id']").exists? )
25
+ assert( browser.image(:xpath , "//img[@id='square']").exists? )
26
+ assert( browser.image(:xpath , "//img[contains(@id, 'squ')]" ).exists? )
27
+
28
+ assert_false( browser.image(:xpath , "//img[@src='missingsrc.gif']").exists? )
29
+
30
+ # BP -- This fails for me but not for Paul. It doesn't make sense to me that it should pass.
31
+ # assert( browser.image(:src , "file:///#{$myDir}/html/images/triangle.jpg").exists? )
32
+ assert( browser.image(:xpath , "//img[contains(@src , 'triangle')]" ).exists? )
33
+
34
+ assert( browser.image(:alt , "circle" ).exists? )
35
+ assert( browser.image(:xpath , "//img[contains(@alt , 'cir')]" ).exists? )
36
+
37
+ assert_false( browser.image(:alt , "triangle" ).exists? )
38
+ assert_false( browser.image(:xpath , "//img[contains(@alt , 'tri')]" ).exists? )
39
+ end
40
+
41
+ tag_method :test_element_by_xpath_class, :fails_on_ie
42
+ def test_element_by_xpath_class
43
+ # FIXME getting HTMLAnchorElement instead of HTMLImageElement
44
+ # TODO: This should return null if object is not there.
45
+ #element = browser.element_by_xpath("//img[@name='missing_name']")
46
+ #assert(element.instance_of?(Image),"element class should be #{Image}; got #{element.class}")
47
+ element = browser.element_by_xpath("//img[@name='circle']")
48
+ assert_class(element, 'Image')
49
+ element = browser.element_by_xpath("//img[contains(@name , 'circ')]")
50
+ assert_class(element, 'Image')
51
+ # TODO: This should return null if object is not there.
52
+ #element = browser.element_by_xpath("//img[@id='missing_id']")
53
+ #assert(element.instance_of?(Image),"element class should be #{Image}; got #{element.class}")
54
+ element = browser.element_by_xpath("//img[@id='square']")
55
+ assert_class(element, 'Image')
56
+ element = browser.element_by_xpath("//img[contains(@id, 'squ')]")
57
+ assert_class(element, 'Image')
58
+ element = browser.element_by_xpath("//img[contains(@src , 'triangle')]")
59
+ assert_class(element, 'Image')
60
+ element = browser.element_by_xpath("//img[contains(@alt , 'cir')]")
61
+ assert_class(element, 'Image')
62
+ # TODO: This should return null if object is not there.
63
+ #element = browser.element_by_xpath("//img[contains(@alt , 'tri')]")
64
+ #assert(element.instance_of?(Image),"element class should be #{Image}; got #{element.class}")
65
+ end
66
+
67
+ def test_image_click
68
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']").click }
69
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']").click }
70
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']").click}
71
+ assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@alt='no_image_with_this']").click}
72
+
73
+ # test for bug 1882
74
+ browser.text_field(:name , "text1").clear
75
+ browser.button(:value , /Pos/ ).click
76
+ assert_equal('clicked' , browser.text_field(:name , "text1" ).value )
77
+
78
+
79
+ # test for disabled button. Click the button to make it disabled
80
+ browser.button(:name , 'disable_img').click
81
+ assert( browser.image(:name , 'disabler_test').disabled )
82
+
83
+ # Click button again to make it enabled.
84
+ browser.button(:name , 'disable_img').click
85
+ assert( ! browser.image(:name , 'disabler_test').disabled )
86
+
87
+ browser.image(:src, /button/).click
88
+ assert(browser.text.include?("PASS") )
89
+
90
+ end
91
+
92
+
93
+ # TODO: Need to see alternative for this in Mozilla
94
+ #def test_imageHasLoaded
95
+ # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']").hasLoaded? }
96
+ # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']").hasLoaded? }
97
+ # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']").hasLoaded? }
98
+ # assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@alt='no_image_with_this']").hasLoaded? }
99
+ #
100
+ # assert_false( browser.image(:xpath , "//img[@name='themissingimage']").hasLoaded? )
101
+ # assert( browser.image(:xpath , "//img[@name='circle']").hasLoaded? )
102
+ #
103
+ # assert( browser.image(:xpath , "//img[@alt='circle']").hasLoaded? )
104
+ # # assert( browser.image(:alt, /cir/ ).hasLoaded? )
105
+ #end
106
+
107
+ def test_image_properties
108
+ # TODO: Need to see alternative for this in Mozilla
109
+ #assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@name='no_image_with_this']").hasLoaded? }
110
+ #assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@id='no_image_with_this']").hasLoaded? }
111
+ #assert_raises(UnknownObjectException ) { browser.image(:xpath , "//img[@src='no_image_with_this']").hasLoaded? }
112
+
113
+ # to string tests -- output should be verified!
114
+ puts browser.image(:xpath , "//img[@name='circle']").to_s
115
+ end
116
+
117
+ end
118
+
@@ -1,75 +1,75 @@
1
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
- require 'unittests/setup'
3
-
4
- class TC_JavaScript_Test < Test::Unit::TestCase
5
-
6
- # include FireWatir::Dialog
7
-
8
- def setup
9
- goto_page 'JavascriptClick.html'
10
- end
11
-
12
- tag_method :test_alert, :fails_on_ie
13
- def test_alert
14
- #browser.button(:id, "btnAlert").click_no_wait()
15
-
16
- #browser.click_jspopup_button("OK")
17
- browser.startClicker("ok", 1, '', "Press OK")
18
- browser.button(:id, "btnAlert").click
19
-
20
- assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Alert button!")
21
- assert_equal("Press OK", browser.get_popup_text)
22
-
23
- browser.startClicker("ok")
24
- browser.button(:id, "btnAlert").click
25
-
26
- assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Alert button!")
27
- assert_equal("Press OK", browser.get_popup_text)
28
- end
29
-
30
- tag_method :test_confirm_ok, :fails_on_ie
31
- def test_confirm_ok
32
- #browser.button(:id, "btnConfirm").click_no_wait()
33
-
34
- #browser.click_jspopup_button("OK")
35
- browser.startClicker("ok", 1, '', "Press a button")
36
- browser.button(:id, "btnConfirm").click
37
-
38
- assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Confirm and OK button!")
39
- assert_equal("Press a button", browser.get_popup_text)
40
-
41
- browser.startClicker("ok")
42
- browser.button(:id, "btnConfirm").click
43
-
44
- assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Confirm and OK button!")
45
- assert_equal("Press a button", browser.get_popup_text)
46
- end
47
-
48
- tag_method :test_confirm_cancel, :fails_on_ie
49
- def test_confirm_cancel
50
- #browser.button(:id, "btnConfirm").click_no_wait()
51
-
52
- #browser.click_jspopup_button("Cancel")
53
- browser.startClicker("cancel", 1, '', "Press a button")
54
- browser.button(:id, "btnConfirm").click
55
-
56
- assert_equal(browser.text_field(:id, "testResult").value, "You pressed the Confirm and Cancel button!")
57
- assert_equal("Press a button", browser.get_popup_text)
58
-
59
- browser.startClicker("cancel")
60
- browser.button(:id, "btnConfirm").click
61
-
62
- assert_equal(browser.text_field(:id, "testResult").value, "You pressed the Confirm and Cancel button!")
63
- assert_equal("Press a button", browser.get_popup_text)
64
- end
65
-
66
- tag_method :test_ok_selectbox, :fails_on_ie
67
- def test_ok_selectbox
68
- goto_page("selectboxes1.html")
69
- browser.startClicker("ok")
70
- browser.select_list(:id , "selectbox_5").select_value(/2/)
71
-
72
- assert_equal(browser.text_field(:id, "txtAlert").value , "You pressed OK button")
73
- assert_equal("Press OK", browser.get_popup_text)
74
- end
75
- end
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
2
+ require 'unittests/setup'
3
+
4
+ class TC_JavaScript_Test < Test::Unit::TestCase
5
+
6
+ # include FireWatir::Dialog
7
+
8
+ def setup
9
+ goto_page 'JavascriptClick.html'
10
+ end
11
+
12
+ tag_method :test_alert, :fails_on_ie
13
+ def test_alert
14
+ #browser.button(:id, "btnAlert").click_no_wait()
15
+
16
+ #browser.click_jspopup_button("OK")
17
+ browser.startClicker("ok", 1, '', "Press OK")
18
+ browser.button(:id, "btnAlert").click
19
+
20
+ assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Alert button!")
21
+ assert_equal("Press OK", browser.get_popup_text)
22
+
23
+ browser.startClicker("ok")
24
+ browser.button(:id, "btnAlert").click
25
+
26
+ assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Alert button!")
27
+ assert_equal("Press OK", browser.get_popup_text)
28
+ end
29
+
30
+ tag_method :test_confirm_ok, :fails_on_ie
31
+ def test_confirm_ok
32
+ #browser.button(:id, "btnConfirm").click_no_wait()
33
+
34
+ #browser.click_jspopup_button("OK")
35
+ browser.startClicker("ok", 1, '', "Press a button")
36
+ browser.button(:id, "btnConfirm").click
37
+
38
+ assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Confirm and OK button!")
39
+ assert_equal("Press a button", browser.get_popup_text)
40
+
41
+ browser.startClicker("ok")
42
+ browser.button(:id, "btnConfirm").click
43
+
44
+ assert_equal(browser.text_field(:id, "testResult").value , "You pressed the Confirm and OK button!")
45
+ assert_equal("Press a button", browser.get_popup_text)
46
+ end
47
+
48
+ tag_method :test_confirm_cancel, :fails_on_ie
49
+ def test_confirm_cancel
50
+ #browser.button(:id, "btnConfirm").click_no_wait()
51
+
52
+ #browser.click_jspopup_button("Cancel")
53
+ browser.startClicker("cancel", 1, '', "Press a button")
54
+ browser.button(:id, "btnConfirm").click
55
+
56
+ assert_equal(browser.text_field(:id, "testResult").value, "You pressed the Confirm and Cancel button!")
57
+ assert_equal("Press a button", browser.get_popup_text)
58
+
59
+ browser.startClicker("cancel")
60
+ browser.button(:id, "btnConfirm").click
61
+
62
+ assert_equal(browser.text_field(:id, "testResult").value, "You pressed the Confirm and Cancel button!")
63
+ assert_equal("Press a button", browser.get_popup_text)
64
+ end
65
+
66
+ tag_method :test_ok_selectbox, :fails_on_ie
67
+ def test_ok_selectbox
68
+ goto_page("selectboxes1.html")
69
+ browser.startClicker("ok")
70
+ browser.select_list(:id , "selectbox_5").select_value(/2/)
71
+
72
+ assert_equal(browser.text_field(:id, "txtAlert").value , "You pressed OK button")
73
+ assert_equal("Press OK", browser.get_popup_text)
74
+ end
75
+ end
@@ -1,232 +1,231 @@
1
- # feature tests for Links
2
- # revision: $Revision: 1.0 $
3
-
4
- $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
- require 'unittests/setup'
6
-
7
- class TC_Links < Test::Unit::TestCase
8
-
9
-
10
- def setup()
11
- goto_page("links1.html")
12
- end
13
-
14
- def test_new_link_exists
15
- assert(browser.link(:text, "test1").exists?)
16
- assert(browser.link(:text, /TEST/i).exists?)
17
- end
18
-
19
- # In current implementation, method_missing catches all the methods that are not defined
20
- # for the element. So there is no way to find out about missinwayoffindingobject exp.
21
- tag_method :test_bad_attribute, :fails_on_ie
22
- def test_bad_attribute
23
- assert_raises(UnknownObjectException) { browser.link(:bad_attribute, 199).click }
24
- begin
25
- browser.link(:bad_attribute, 199).click
26
- rescue UnknownObjectException => e
27
- assert_equal "Unable to locate element, using :bad_attribute, 199", e.to_s
28
- end
29
- end
30
-
31
- def test_missing_links_dont_exist
32
- assert_false(browser.link(:text, "missing").exists?)
33
- assert_false(browser.link(:text, /miss/).exists?)
34
- end
35
-
36
- def test_link_Exists
37
- assert(browser.link(:text, "test1").exists?)
38
- assert(browser.link(:text, /TEST/i).exists?)
39
- assert_false(browser.link(:text, "missing").exists?)
40
- assert_false(browser.link(:text, /miss/).exists?)
41
-
42
- # this assert we have to build up the path
43
- # this is what it looks like if you do a to_s on the link file:///C:/watir_bonus/unitTests/html/links1.HTML
44
- # but what we get back from $htmlRoot is a mixed case, so its almost impossible for use to test this correctly
45
- # assert(browser.link(:url,'file:///C:/watir_bonus/unitTests/html/links1.HTML' ).exists?)
46
-
47
- assert(browser.link(:url, /link_pass.html/).exists?)
48
- assert_false(browser.link(:url, "alsomissing.html").exists?)
49
-
50
- assert(browser.link(:id, "link_id").exists?)
51
- assert_false(browser.link(:id, "alsomissing").exists?)
52
-
53
- assert(browser.link(:id, /_id/).exists?)
54
- assert_false(browser.link(:id, /alsomissing/).exists?)
55
-
56
- assert(browser.link(:name, "link_name").exists?)
57
- assert_false(browser.link(:name, "alsomissing").exists?)
58
-
59
- assert(browser.link(:name, /_n/).exists?)
60
- assert_false(browser.link(:name, /missing/).exists?)
61
-
62
- assert(browser.link(:title, /ti/).exists?)
63
- assert(browser.link(:title, "link_title").exists?)
64
-
65
- assert_false(browser.link(:title, /missing/).exists?)
66
-
67
- assert(browser.link(:url, /_pass/).exists?)
68
- assert_false(browser.link(:url, /dont_exist/).exists?)
69
- end
70
-
71
- def test_link_click
72
- browser.link(:text, "test1").click
73
- assert( browser.text.include?("Links2-Pass") )
74
- end
75
- def test_link2_click
76
- browser.link(:url, /link_pass.html/).click
77
- assert( browser.text.include?("Links3-Pass") )
78
- end
79
- def test_link3_click
80
- browser.link(:index, 1).click
81
- assert( browser.text.include?("Links2-Pass") )
82
- end
83
- def test_link4_click
84
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).click }
85
- end
86
-
87
- def test_link_properties
88
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).href }
89
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).value}
90
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).text }
91
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).name }
92
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).id }
93
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).disabled }
94
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).type }
95
- assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).class_name }
96
-
97
- assert_match( /links2/ ,browser.link(:index, 1).href )
98
- assert_equal( "" , browser.link(:index, 1).value)
99
- assert_equal( "test1" , browser.link(:index, 1).text )
100
- assert_equal( "" , browser.link(:index, 1).name )
101
- assert_equal( "" , browser.link(:index, 1).id )
102
- assert_equal( false , browser.link(:index, 1).disabled )
103
- assert_equal( "" , browser.link(:index, 1).class_name)
104
- assert_equal( "link_class_1" , browser.link(:index, 2).class_name)
105
-
106
- assert_equal( "link_id" , browser.link(:index, 6).id )
107
- assert_equal( "link_name" , browser.link(:index, 7).name )
108
-
109
- assert_equal( "" , browser.link(:index, 7).title)
110
-
111
- assert_equal( "link_title" , browser.link(:index, 8).title)
112
- end
113
-
114
- def test_text_attribute
115
- arr1 = browser.link(:text, "nameDelet").to_s
116
- arr2 = browser.link(:text, /Delet/).to_s
117
- assert_equal(arr1, arr2)
118
-
119
- end
120
-
121
- def test_link_iterator
122
- assert_equal(11, browser.links.length )
123
- assert_equal("Link Using a name" , browser.links[7].text)
124
-
125
- index = 1
126
- browser.links.each do |link|
127
- assert_equal( browser.link(:index, index).href , link.href )
128
- assert_equal( browser.link(:index, index).id , link.id )
129
- assert_equal( browser.link(:index, index).name , link.name )
130
- assert_equal( browser.link(:index, index).innerText , link.text )
131
- index+=1
132
- end
133
- end
134
-
135
- def test_div_xml_bug
136
- goto_page("div_xml.html")
137
- assert_nothing_raised {browser.link(:text, 'Create').exists? }
138
- end
139
- def test_link_to_s
140
- puts browser.link(:id,"linktos").to_s
141
- end
142
- end
143
-
144
- class TC_Frame_Links < Test::Unit::TestCase
145
-
146
-
147
- def setup()
148
- goto_page("frame_links.html")
149
- end
150
-
151
- def test_new_frame_link_exists
152
- assert(browser.frame("buttonFrame").link(:text, "test1").exists?)
153
- end
154
- def test_missing_frame_links_dont_exist
155
- assert_false(browser.frame("buttonFrame").link(:text, "missing").exists?)
156
- assert_raise(UnknownFrameException, "UnknownFrameException was supposed to be thrown"){browser.frame("missing").link(:text, "test1").exists?}
157
- end
158
-
159
- def test_links_in_frames
160
- assert(browser.frame("buttonFrame").link(:text, "test1").exists?)
161
- assert_false(browser.frame("buttonFrame").link(:text, "missing").exists?)
162
-
163
- assert_raises(UnknownObjectException, "UnknownObjectException was supposed to be thrown" ) { browser.frame("buttonFrame").link(:index, 199).href }
164
- assert_match(/links2/, browser.frame("buttonFrame").link(:index, 1).href)
165
-
166
- count =0
167
- browser.frame("buttonFrame").links.each do |l|
168
- count+=1
169
- end
170
-
171
- assert_equal(11 , count)
172
- end
173
- end
174
-
175
- class TC_Links_Display < Test::Unit::TestCase
176
-
177
- include MockStdoutTestCase
178
-
179
- tag_method :test_showLinks, :fails_on_ie
180
- def test_showLinks
181
- goto_page("links1.html")
182
- $stdout = @mockout
183
- browser.showLinks
184
- assert_equal(<<END_OF_MESSAGE, @mockout)
185
- There are 11 links
186
- link: name:
187
- id:
188
- href: links2.html
189
- index: 1
190
- link: name:
191
- id:
192
- href: link_pass.html
193
- index: 2
194
- link: name:
195
- id:
196
- href: pass3.html
197
- index: 3
198
- link: name:
199
- id:
200
- href: textarea.html
201
- index: 4
202
- link: name:
203
- id:
204
- href: textarea.html
205
- index: 5
206
- link: name:
207
- id: link_id
208
- href: links1.HTML
209
- index: 6
210
- link: name: link_name
211
- id:
212
- href: links1.HTML
213
- index: 7
214
- link: name:
215
- id:
216
- href: links1.HTML
217
- index: 8
218
- link: name:
219
- id:
220
- href: pass.html
221
- index: 9
222
- link: name:
223
- id: linktos
224
- href: link_pass.html
225
- index: 10
226
- link: name: test_link
227
- id:
228
- href: link1.html
229
- index: 11
230
- END_OF_MESSAGE
231
- end
232
- end
1
+ # feature tests for Links
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
5
+ require 'unittests/setup'
6
+
7
+ class TC_Links < Test::Unit::TestCase
8
+
9
+
10
+ def setup()
11
+ goto_page("links1.html")
12
+ end
13
+
14
+ def test_new_link_exists
15
+ assert(browser.link(:text, "test1").exists?)
16
+ assert(browser.link(:text, /TEST/i).exists?)
17
+ end
18
+
19
+ # In current implementation, method_missing catches all the methods that are not defined
20
+ # for the element. So there is no way to find out about missinwayoffindingobject exp.
21
+ tag_method :test_bad_attribute, :fails_on_ie
22
+ def test_bad_attribute
23
+ assert_raises(UnknownObjectException) { browser.link(:bad_attribute, 199).click }
24
+ begin
25
+ browser.link(:bad_attribute, 199).click
26
+ rescue UnknownObjectException => e
27
+ assert_equal "Unable to locate element, using :bad_attribute, 199", e.to_s
28
+ end
29
+ end
30
+
31
+ def test_missing_links_dont_exist
32
+ assert_false(browser.link(:text, "missing").exists?)
33
+ assert_false(browser.link(:text, /miss/).exists?)
34
+ end
35
+
36
+ def test_link_Exists
37
+ assert(browser.link(:text, "test1").exists?)
38
+ assert(browser.link(:text, /TEST/i).exists?)
39
+ assert_false(browser.link(:text, "missing").exists?)
40
+ assert_false(browser.link(:text, /miss/).exists?)
41
+
42
+ # this assert we have to build up the path
43
+ # this is what it looks like if you do a to_s on the link file:///C:/watir_bonus/unitTests/html/links1.HTML
44
+ # but what we get back from $htmlRoot is a mixed case, so its almost impossible for use to test this correctly
45
+ # assert(browser.link(:url,'file:///C:/watir_bonus/unitTests/html/links1.HTML' ).exists?)
46
+
47
+ assert(browser.link(:url, /link_pass.html/).exists?)
48
+ assert_false(browser.link(:url, "alsomissing.html").exists?)
49
+
50
+ assert(browser.link(:id, "link_id").exists?)
51
+ assert_false(browser.link(:id, "alsomissing").exists?)
52
+
53
+ assert(browser.link(:id, /_id/).exists?)
54
+ assert_false(browser.link(:id, /alsomissing/).exists?)
55
+
56
+ assert(browser.link(:name, "link_name").exists?)
57
+ assert_false(browser.link(:name, "alsomissing").exists?)
58
+
59
+ assert(browser.link(:name, /_n/).exists?)
60
+ assert_false(browser.link(:name, /missing/).exists?)
61
+
62
+ assert(browser.link(:title, /ti/).exists?)
63
+ assert(browser.link(:title, "link_title").exists?)
64
+
65
+ assert_false(browser.link(:title, /missing/).exists?)
66
+
67
+ assert(browser.link(:url, /_pass/).exists?)
68
+ assert_false(browser.link(:url, /dont_exist/).exists?)
69
+ end
70
+
71
+ def test_link_click
72
+ browser.link(:text, "test1").click
73
+ assert( browser.text.include?("Links2-Pass") )
74
+ end
75
+ def test_link2_click
76
+ browser.link(:url, /link_pass.html/).click
77
+ assert( browser.text.include?("Links3-Pass") )
78
+ end
79
+ def test_link3_click
80
+ browser.link(:index, 1).click
81
+ assert( browser.text.include?("Links2-Pass") )
82
+ end
83
+ def test_link4_click
84
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).click }
85
+ end
86
+
87
+ def test_link_properties
88
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).href }
89
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).value}
90
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).text }
91
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).name }
92
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).id }
93
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).disabled }
94
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).type }
95
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { browser.link(:index, 199).class_name }
96
+
97
+ assert_match( /links2/ ,browser.link(:index, 1).href )
98
+ assert_equal( "" , browser.link(:index, 1).value)
99
+ assert_equal( "test1" , browser.link(:index, 1).text )
100
+ assert_equal( "" , browser.link(:index, 1).name )
101
+ assert_equal( "" , browser.link(:index, 1).id )
102
+ assert_equal( false , browser.link(:index, 1).disabled )
103
+ assert_equal( "" , browser.link(:index, 1).class_name)
104
+ assert_equal( "link_class_1" , browser.link(:index, 2).class_name)
105
+
106
+ assert_equal( "link_id" , browser.link(:index, 6).id )
107
+ assert_equal( "link_name" , browser.link(:index, 7).name )
108
+
109
+ assert_equal( "" , browser.link(:index, 7).title)
110
+
111
+ assert_equal( "link_title" , browser.link(:index, 8).title)
112
+ end
113
+
114
+ def test_text_attribute
115
+ arr1 = browser.link(:text, "nameDelet").to_s
116
+ arr2 = browser.link(:text, /Delet/).to_s
117
+ assert_equal(arr1, arr2)
118
+
119
+ end
120
+
121
+ def test_link_iterator
122
+ assert_equal(11, browser.links.length )
123
+ assert_equal("Link Using a name" , browser.links[7].text)
124
+
125
+ index = 1
126
+ browser.links.each do |link|
127
+ assert_equal( browser.link(:index, index).href , link.href )
128
+ assert_equal( browser.link(:index, index).id , link.id )
129
+ assert_equal( browser.link(:index, index).name , link.name )
130
+ assert_equal( browser.link(:index, index).innerText , link.text )
131
+ index+=1
132
+ end
133
+ end
134
+
135
+ def test_div_xml_bug
136
+ goto_page("div_xml.html")
137
+ assert_nothing_raised {browser.link(:text, 'Create').exists? }
138
+ end
139
+ def test_link_to_s
140
+ puts browser.link(:id,"linktos").to_s
141
+ end
142
+ end
143
+
144
+ class TC_Frame_Links < Test::Unit::TestCase
145
+
146
+
147
+ def setup()
148
+ goto_page("frame_links.html")
149
+ end
150
+
151
+ def test_new_frame_link_exists
152
+ assert(browser.frame("buttonFrame").link(:text, "test1").exists?)
153
+ end
154
+ def test_missing_frame_links_dont_exist
155
+ assert_false(browser.frame("buttonFrame").link(:text, "missing").exists?)
156
+ assert_raise(UnknownFrameException, "UnknownFrameException was supposed to be thrown"){browser.frame("missing").link(:text, "test1").exists?}
157
+ end
158
+
159
+ def test_links_in_frames
160
+ assert(browser.frame("buttonFrame").link(:text, "test1").exists?)
161
+ assert_false(browser.frame("buttonFrame").link(:text, "missing").exists?)
162
+
163
+ assert_raises(UnknownObjectException, "UnknownObjectException was supposed to be thrown" ) { browser.frame("buttonFrame").link(:index, 199).href }
164
+ assert_match(/links2/, browser.frame("buttonFrame").link(:index, 1).href)
165
+
166
+ count =0
167
+ browser.frame("buttonFrame").links.each do |l|
168
+ count+=1
169
+ end
170
+
171
+ assert_equal(11 , count)
172
+ end
173
+ end
174
+
175
+ class TC_Links_Display < Test::Unit::TestCase
176
+
177
+ include CaptureIOHelper
178
+
179
+ tag_method :test_showLinks, :fails_on_ie
180
+ def test_showLinks
181
+ goto_page("links1.html")
182
+ actual = capture_stdout { browser.showLinks }
183
+ assert_equal(<<END_OF_MESSAGE, actual)
184
+ There are 11 links
185
+ link: name:
186
+ id:
187
+ href: links2.html
188
+ index: 1
189
+ link: name:
190
+ id:
191
+ href: link_pass.html
192
+ index: 2
193
+ link: name:
194
+ id:
195
+ href: pass3.html
196
+ index: 3
197
+ link: name:
198
+ id:
199
+ href: textarea.html
200
+ index: 4
201
+ link: name:
202
+ id:
203
+ href: textarea.html
204
+ index: 5
205
+ link: name:
206
+ id: link_id
207
+ href: links1.HTML
208
+ index: 6
209
+ link: name: link_name
210
+ id:
211
+ href: links1.HTML
212
+ index: 7
213
+ link: name:
214
+ id:
215
+ href: links1.HTML
216
+ index: 8
217
+ link: name:
218
+ id:
219
+ href: pass.html
220
+ index: 9
221
+ link: name:
222
+ id: linktos
223
+ href: link_pass.html
224
+ index: 10
225
+ link: name: test_link
226
+ id:
227
+ href: link1.html
228
+ index: 11
229
+ END_OF_MESSAGE
230
+ end
231
+ end