firewatir 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/MozillaBaseElement.rb +1778 -0
  2. data/container.rb +889 -0
  3. data/firewatir/exceptions.rb +44 -0
  4. data/firewatir/testUnitAddons.rb +8 -0
  5. data/firewatir.rb +1130 -0
  6. data/htmlelements.rb +2277 -0
  7. data/unittests/attach_to_new_window_test.rb +34 -0
  8. data/unittests/bug_fixes_test.rb +188 -0
  9. data/unittests/buttons_test.rb +215 -0
  10. data/unittests/buttons_xpath_test.rb +87 -0
  11. data/unittests/checkbox_test.rb +154 -0
  12. data/unittests/checkbox_xpath_test.rb +107 -0
  13. data/unittests/div_test.rb +274 -0
  14. data/unittests/filefield_test.rb +45 -0
  15. data/unittests/filefield_xpath_test.rb +35 -0
  16. data/unittests/form_test.rb +307 -0
  17. data/unittests/frame_test.rb +151 -0
  18. data/unittests/hidden_test.rb +85 -0
  19. data/unittests/hidden_xpath_test.rb +72 -0
  20. data/unittests/html/JavascriptClick.html +42 -0
  21. data/unittests/html/blankpage.html +12 -0
  22. data/unittests/html/buttons1.html +61 -0
  23. data/unittests/html/checkboxes1.html +71 -0
  24. data/unittests/html/complex_table.html +36 -0
  25. data/unittests/html/cssTest.html +42 -0
  26. data/unittests/html/div.html +72 -0
  27. data/unittests/html/div_xml.html +21 -0
  28. data/unittests/html/fileupload.html +45 -0
  29. data/unittests/html/formTest1.html +39 -0
  30. data/unittests/html/forms2.html +45 -0
  31. data/unittests/html/forms3.html +132 -0
  32. data/unittests/html/forms4.html +27 -0
  33. data/unittests/html/frame_buttons.html +4 -0
  34. data/unittests/html/frame_links.html +4 -0
  35. data/unittests/html/frame_multi.html +5 -0
  36. data/unittests/html/iframeTest.html +15 -0
  37. data/unittests/html/iframeTest1.html +14 -0
  38. data/unittests/html/iframeTest2.html +6 -0
  39. data/unittests/html/images/1.gif +0 -0
  40. data/unittests/html/images/2.GIF +0 -0
  41. data/unittests/html/images/3.GIF +0 -0
  42. data/unittests/html/images/button.jpg +0 -0
  43. data/unittests/html/images/circle.jpg +0 -0
  44. data/unittests/html/images/minus.GIF +0 -0
  45. data/unittests/html/images/originaltriangle.jpg +0 -0
  46. data/unittests/html/images/plus.gif +0 -0
  47. data/unittests/html/images/square.jpg +0 -0
  48. data/unittests/html/images/triangle.jpg +0 -0
  49. data/unittests/html/images1.html +67 -0
  50. data/unittests/html/javascriptevents.html +35 -0
  51. data/unittests/html/link_pass.html +11 -0
  52. data/unittests/html/links1.html +42 -0
  53. data/unittests/html/links2.html +11 -0
  54. data/unittests/html/modal_dialog.html +8 -0
  55. data/unittests/html/modal_dialog_launcher.html +12 -0
  56. data/unittests/html/nestedFrames.html +6 -0
  57. data/unittests/html/new_browser.html +17 -0
  58. data/unittests/html/pass.html +10 -0
  59. data/unittests/html/popups1.html +60 -0
  60. data/unittests/html/pre.html +28 -0
  61. data/unittests/html/radioButtons1.html +71 -0
  62. data/unittests/html/redirect.html +10 -0
  63. data/unittests/html/redirect1.html +9 -0
  64. data/unittests/html/redirect2.html +9 -0
  65. data/unittests/html/redirect3.html +9 -0
  66. data/unittests/html/select_tealeaf.html +54 -0
  67. data/unittests/html/selectboxes1.html +55 -0
  68. data/unittests/html/simple_table.html +26 -0
  69. data/unittests/html/simple_table_buttons.html +104 -0
  70. data/unittests/html/simple_table_columns.html +74 -0
  71. data/unittests/html/table1.html +165 -0
  72. data/unittests/html/tableCell_using_xpath.html +19 -0
  73. data/unittests/html/textarea.html +30 -0
  74. data/unittests/html/textfields1.html +62 -0
  75. data/unittests/html/textsearch.html +44 -0
  76. data/unittests/images_test.rb +204 -0
  77. data/unittests/images_xpath_test.rb +118 -0
  78. data/unittests/iostring.rb +30 -0
  79. data/unittests/iostring_test.rb +48 -0
  80. data/unittests/javascript_test.rb +71 -0
  81. data/unittests/links_test.rb +230 -0
  82. data/unittests/links_xpath_test.rb +79 -0
  83. data/unittests/mozilla_all_tests.rb +18 -0
  84. data/unittests/pre_test.rb +74 -0
  85. data/unittests/radios_test.rb +166 -0
  86. data/unittests/radios_xpath_test.rb +101 -0
  87. data/unittests/redirect_test.rb +40 -0
  88. data/unittests/selectbox_test.rb +141 -0
  89. data/unittests/selectbox_xpath_test.rb +127 -0
  90. data/unittests/setup.rb +35 -0
  91. data/unittests/table_test.rb +372 -0
  92. data/unittests/table_xpath_test.rb +184 -0
  93. data/unittests/textfields_test.rb +230 -0
  94. data/unittests/textfields_xpath_test.rb +112 -0
  95. metadata +144 -0
@@ -0,0 +1,34 @@
1
+ # feature tests for attaching to new Firefox windows
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_NewWindow < Test::Unit::TestCase
8
+ include FireWatir
9
+
10
+ def setup
11
+ $ff.goto($htmlRoot + "new_browser.html")
12
+ end
13
+
14
+ def test_simply_attach_to_new_window_using_title
15
+ $ff.link(:text, 'New Window').click
16
+ ff_new = $ff.attach(:title, 'Pass Page')
17
+ assert(ff_new.text.include?('PASS'))
18
+ ff_new.close
19
+ #$ff.link(:text, 'New Window').click
20
+ end
21
+
22
+ def test_simply_attach_to_new_window_using_url
23
+ $ff.link(:text, 'New Window').click
24
+ ff_new = $ff.attach(:url, /pass\.html/)
25
+ assert(ff_new.text.include?('PASS'))
26
+ ff_new.close
27
+ #$ff.link(:text, 'New Window').click
28
+ end
29
+
30
+ def test_new_window_exists
31
+ assert_raises(NoMatchingWindowFoundException , "NoMatchingWindowFoundException was supposed to be thrown" ) { $ff.attach(:title, "missing_title") }
32
+ assert_raises(NoMatchingWindowFoundException , "NoMatchingWindowFoundException was supposed to be thrown" ) { $ff.attach(:url, "missing_url") }
33
+ end
34
+ end
@@ -0,0 +1,188 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
2
+ require 'unittests/setup'
3
+
4
+ class TC_Bugs< Test::Unit::TestCase
5
+ include FireWatir
6
+
7
+ def setup
8
+ $ff.goto($htmlRoot + "frame_buttons.html")
9
+ end
10
+
11
+ def test_frame_objects_bug3
12
+ frame = $ff.frame("buttonFrame")
13
+ button = frame.button(:name, "b1")
14
+ assert_equal("buttonFrame", frame.name)
15
+ assert_equal("b2", button.id)
16
+ text1 = frame.text_field(:id, "text_id")
17
+ text1.set("NewValue")
18
+ assert("NewValue",frame.text_field(:id, "text_id").value)
19
+ end
20
+
21
+ def test_link_object_bug9
22
+ $ff.goto($htmlRoot + "links1.html")
23
+ link = $ff.link(:text, "nameDelet")
24
+ assert_equal("test_link", link.name)
25
+ end
26
+
27
+
28
+ # element_by_xpath should return an element that's instance of the
29
+ # appropriate class, not the generic Element class. So if it's a div,
30
+ # it should return an instance of Div, if it's a checkbox, CheckBox,
31
+ # and so on. TODO write tests for all classes
32
+ def test_element_by_xpath_bug01
33
+ $ff.goto($htmlRoot + "div.html")
34
+ element = $ff.element_by_xpath("//div[@id='div1']")
35
+ assert_not_nil(element) # helder
36
+ # next assert always breaks, dunno why (error, not failure)
37
+ #assert_instance_of(Div, element, "wrong constructor was used")
38
+ # using this hack instead
39
+ assert(element.instance_of?(Div),
40
+ "element class should be: #{Div}; got: #{element.class}.")
41
+ end
42
+
43
+ def test_elements_by_xpath_bug10
44
+ $ff.goto($htmlRoot + "links1.html")
45
+ elements = $ff.elements_by_xpath("//a")
46
+ assert_equal(11, elements.length)
47
+ assert_equal("links2.html", elements[0].href)
48
+ assert_equal("link_class_1", elements[1].className)
49
+ assert_equal("link_id", elements[5].id)
50
+ assert_equal("Link Using an ID", elements[5].text)
51
+ end
52
+
53
+ def test_button_by_value_bug8
54
+ $ff.goto($htmlRoot + "buttons1.html")
55
+ assert_equal("Sign In", $ff.button(:value,"Sign In").value)
56
+ end
57
+
58
+ def test_html_bug7
59
+ $ff.goto($htmlRoot + "links1.html")
60
+ html = $ff.html
61
+ assert_match(/.*<a id="linktos" *>*/,html)
62
+ end
63
+
64
+ def test_span_onclick_bug14
65
+ $ff.goto($htmlRoot + "div.html")
66
+ $ff.span(:id, "span1").fireEvent("onclick")
67
+ assert($ff.text.include?("PASS") )
68
+ end
69
+
70
+ def test_file_field_value_bug20
71
+ actual_file_name = "c:\\Program Files\\TestFile.html"
72
+ $ff.goto($htmlRoot + "fileupload.html")
73
+ $ff.file_field(:name, "file3").set(actual_file_name)
74
+ set_file_name = $ff.file_field(:name, "file3").value
75
+ # make sure correct value for upload file is posted.
76
+ assert(actual_file_name, set_file_name)
77
+ end
78
+
79
+ def test_attribute_value_bug22
80
+ $ff.goto($htmlRoot + "div.html")
81
+ assert("Test1", $ff.element_by_xpath("//div[@id='div1']").attribute_value("title"))
82
+ end
83
+
84
+ def test_url_value_bug23
85
+ $ff.goto($htmlRoot + "buttons1.html")
86
+ $ff.button(:id, "b2").click
87
+ assert($htmlRoot + "pass.html", $ff.url)
88
+ end
89
+
90
+ def test_contains_text_bug28
91
+ $ff.goto($htmlRoot + "buttons1.html")
92
+ $ff.button(:id, "b2").click
93
+ assert_false($ff.contains_text("passed"))
94
+ assert($ff.contains_text("PASS"))
95
+ assert($ff.contains_text("PAS"))
96
+ assert($ff.contains_text(/PAS/))
97
+ assert($ff.contains_text(/pass/i))
98
+ assert_false($ff.contains_text(/pass/))
99
+ end
100
+
101
+ def test_frame_bug_21
102
+ $ff.goto($htmlRoot + "frame_buttons.html")
103
+ frame1 = $ff.frame(:name, "buttonFrame")
104
+ frame2 = $ff.frame(:name, "buttonFrame2")
105
+ assert_equal("buttons1.html", frame1.src)
106
+ assert_equal("blankpage.html", frame2.src)
107
+ end
108
+
109
+ def test_quotes_bug_11
110
+ $ff.goto($htmlRoot + "textfields1.html")
111
+ $ff.text_field(:name, "text1").set("value with quote (\")")
112
+ assert_equal("value with quote (\")", $ff.text_field(:name, "text1").value)
113
+ $ff.text_field(:name, "text1").set("value with backslash (\\)")
114
+ assert_equal("value with backslash (\\)", $ff.text_field(:name, "text1").value)
115
+ end
116
+
117
+ def test_close_bug_26
118
+ if ! (RUBY_PLATFORM =~ /darwin/i)
119
+ $ff.close()
120
+ $ff = Firefox.new
121
+ end
122
+ end
123
+
124
+ def test_class_bug_29
125
+ $ff.goto($htmlRoot + "div.html")
126
+ div = $ff.div(:class, "blueText")
127
+ assert_equal("div2", div.id)
128
+ end
129
+
130
+ def test_element_using_any_attribute
131
+ $ff.goto($htmlRoot + "div.html")
132
+ div = $ff.div(:title, "Test1")
133
+ assert_equal("div1", div.id)
134
+ end
135
+
136
+ def test_element_using_any_attribute2
137
+ $ff.goto($htmlRoot + "div.html")
138
+ div = $ff.div(:attribute, "attribute")
139
+ assert_equal("div1", div.id)
140
+ end
141
+
142
+ def test_file_field_bug_20
143
+ $ff.goto($htmlRoot + "fileupload.html")
144
+ # Enter dummy path.
145
+ if(RUBY_PLATFORM =~ /.*mswin.*/)
146
+ $ff.file_field(:name, "file3").set("c:\\results.txt")
147
+ else
148
+ $ff.file_field(:name, "file3").set("/user/lib/results.txt")
149
+ end
150
+ $ff.button(:name, "upload").click()
151
+ url = $ff.url
152
+ assert_match(/.*results.txt&upload=upload$/,url)
153
+ end
154
+
155
+ def test_button_bug2
156
+ $ff.goto($htmlRoot + "buttons1.html")
157
+ btn = $ff.button(:id, "b7")
158
+ assert_equal("b7", btn.id)
159
+ end
160
+
161
+ def test_getAllContents_bug25
162
+ $ff.goto($htmlRoot + "select_tealeaf.html")
163
+ $ff.select_lists.each do |select|
164
+ contents = select.getAllContents().to_s
165
+ puts contents
166
+ assert_equal("=<>>=<=", contents)
167
+ break
168
+ end
169
+ end
170
+
171
+ def test_fire_event_bug31
172
+ $ff.goto($htmlRoot + "div.html")
173
+ div = $ff.div(:attribute, "attribute")
174
+ div.fire_event("ondblclick")
175
+ assert("PASS", $ff.text)
176
+ $ff.goto($htmlRoot + "div.html")
177
+ div = $ff.div(:id, "div1")
178
+ div.fireEvent("ondblclick")
179
+ assert("PASS", $ff.text)
180
+ end
181
+
182
+ def test_contains_text_bug37
183
+ $ff.goto($htmlRoot + "frame_buttons.html")
184
+ frame = $ff.frame(:name, "buttonFrame")
185
+ assert(frame.contains_text("second button"))
186
+ assert_false(frame.contains_text("second button second"))
187
+ end
188
+ end
@@ -0,0 +1,215 @@
1
+ # feature tests for Buttons of type <input type = "button">
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_Buttons < Test::Unit::TestCase
8
+ include FireWatir
9
+
10
+ def setup
11
+ $ff.goto($htmlRoot + "buttons1.html")
12
+ end
13
+
14
+ def goto_frames_page()
15
+ $ff.goto($htmlRoot + "frame_buttons.html")
16
+ end
17
+
18
+ #def test_Spinner
19
+ # s = Spinner.new
20
+ # i = 0
21
+ # while(i < 100)
22
+ # sleep 0.05
23
+ # print s.next
24
+ # i+=1
25
+ # end
26
+ # s = nil
27
+ #end
28
+
29
+ def test_Button_to_s
30
+ # i think the tests for to_s should be dropped. The output is not in a nice format to be tested, and the
31
+ # individual properties are tested in the test_properties method
32
+
33
+ b4 = ['name: b4',
34
+ 'type: button',
35
+ 'id: b5',
36
+ 'value: Disabled Button',
37
+ 'disabled: true']
38
+ b1 = ['name: b1',
39
+ 'type: button',
40
+ 'id: b2',
41
+ 'value: Click Me',
42
+ 'disabled: false']
43
+
44
+ assert_equal(b4, $ff.button(:name, "b4").to_s)
45
+ assert_equal(b1, $ff.button(:caption, "Click Me").to_s)
46
+ assert_equal(b1, $ff.button(:index, 1).to_s)
47
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:name, "noName").to_s }
48
+ end
49
+
50
+ def test_properties
51
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:name, "noName").id }
52
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:name, "noName").name }
53
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:name, "noName").disabled }
54
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:name, "noName").type }
55
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:name, "noName").value }
56
+
57
+ assert_equal("b1" , $ff.button(:index, 1).name )
58
+ assert_equal("b2" , $ff.button(:index, 1).id )
59
+ assert_equal("button" , $ff.button(:index, 1).type )
60
+ assert_equal("Click Me" , $ff.button(:index, 1).value )
61
+ assert_equal(false , $ff.button(:index, 1).disabled )
62
+ assert_equal("italic_button" , $ff.button(:name, "b1").class_name )
63
+ assert_equal("" , $ff.button(:name , "b4").class_name )
64
+
65
+
66
+ assert_equal("b1" , $ff.button(:id, "b2").name )
67
+ assert_equal("b2" , $ff.button(:id, "b2").id )
68
+ assert_equal("button" , $ff.button(:id, "b2").type )
69
+
70
+ assert_equal("b4" , $ff.button(:index, 2).name )
71
+ assert_equal("b5" , $ff.button(:index, 2).id )
72
+ assert_equal("button" , $ff.button(:index, 2).type )
73
+ assert_equal("Disabled Button" , $ff.button(:index, 2).value )
74
+ assert_equal(true , $ff.button(:index, 2).disabled )
75
+
76
+ assert_equal( "" , $ff.button(:index, 2).title )
77
+ assert_equal( "this is button1" , $ff.button(:index, 1).title )
78
+ end
79
+
80
+
81
+ def test_button_using_default
82
+ # since most of the time, a button will be accessed based on its caption, there is a default way of accessing it....
83
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button( "Missing Caption").click }
84
+
85
+ $ff.button("Click Me").click
86
+ assert($ff.text.include?("PASS") )
87
+ end
88
+
89
+ def test_Button_click_only
90
+ $ff.button(:caption, "Click Me").click
91
+ assert($ff.text.include?("PASS") )
92
+ end
93
+
94
+ def test_button_click
95
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:caption, "Missing Caption").click }
96
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:id, "missingID").click }
97
+
98
+ assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ff.button(:caption, "Disabled Button").click }
99
+
100
+ $ff.button(:caption, "Click Me").click
101
+ assert($ff.text.include?("PASS") )
102
+ end
103
+
104
+ def test_Button_Exists
105
+ assert($ff.button(:caption, "Click Me").exists?)
106
+ assert($ff.button(:caption, "Submit").exists?)
107
+ assert($ff.button(:name, "b1").exists?)
108
+ assert($ff.button(:id, "b2").exists?)
109
+ assert($ff.button(:caption, /sub/i).exists?)
110
+
111
+ assert_false($ff.button(:caption, "missingcaption").exists?)
112
+ assert_false($ff.button(:name, "missingname").exists?)
113
+ assert_false($ff.button(:id, "missingid").exists?)
114
+ assert_false($ff.button(:caption, /missing/i).exists?)
115
+ end
116
+
117
+ def test_Button_Enabled
118
+ assert($ff.button(:caption, "Click Me").enabled?)
119
+ assert_false($ff.button(:caption, "Disabled Button").enabled?)
120
+ assert_false($ff.button(:name, "b4").enabled?)
121
+ assert_false($ff.button(:id, "b5").enabled?)
122
+
123
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:name, "noName").enabled? }
124
+ end
125
+
126
+ def test_button2
127
+ assert($ff.button(:caption, "Click Me2").exists?, 'Can\'t find Button with caption "Click Me2"')
128
+
129
+ assert($ff.button(:caption, "Disabled Button2").exists?, 'Can\'t find Button with caption "Disabled Button2"')
130
+ assert($ff.button(:caption, "Sign In").exists?, 'Can\'t find Button with caption "Sign In"')
131
+
132
+ assert_equal("b6" , $ff.button(:id, "b7").name )
133
+ assert_equal("b7" , $ff.button(:name, "b6").id )
134
+ assert_equal("Click Me2" , $ff.button(:id, "b7").value )
135
+ assert_equal(false , $ff.button(:id, "b7").disabled )
136
+ assert_equal("italic_button" , $ff.button(:name, "b6").class_name )
137
+
138
+ assert_equal("b8" , $ff.button(:id, "b9").name )
139
+ assert_equal("b9" , $ff.button(:name, "b8").id )
140
+ assert_equal("Disabled Button2" , $ff.button(:id, "b9").value )
141
+ assert_equal(false , $ff.button(:id, "b9").enabled?)
142
+ assert_equal("" , $ff.button(:name, "b8").class_name )
143
+ assert_equal("Sign In", $ff.button(:caption, "Sign In").value)
144
+
145
+ assert($ff.button(:caption, "Click Me").enabled?, 'Button wih caption "Click Me" should be enabled')
146
+
147
+ assert_false($ff.button(:caption, "Disabled Button2").enabled?, 'Button wih caption "Disabled Button2" should be disabled')
148
+
149
+
150
+ assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ff.button(:caption, "Disabled Button2").click }
151
+
152
+ $ff.button(:caption, "Click Me2").click
153
+ assert($ff.text.include?("PASS"), 'Clicking on "Click Me2" button should\'ve taken to the "PASS" page')
154
+
155
+ end
156
+
157
+ def test_frame
158
+ goto_frames_page()
159
+ f = $ff.frame("buttonFrame")
160
+ assert(f.button(:caption, "Click Me").enabled?)
161
+ #assert_raises( UnknownObjectException , "UnknownObjectException was supposed to be thrown ( no frame name supplied) " ) { $ff.button(:caption, "Disabled Button").enabled?}
162
+ end
163
+
164
+ def test_buttons
165
+ arrButtons = $ff.buttons
166
+ assert_equal(7, arrButtons.length)
167
+ #arrButtons.each do |button|
168
+ #puts button.to_s
169
+ #end
170
+ assert_equal("b2", arrButtons[1].id)
171
+ assert_equal("b5", arrButtons[2].id)
172
+ assert_equal("Submit", arrButtons[3].value)
173
+ assert_equal("sub3", arrButtons[4].name)
174
+ assert_equal("b7", arrButtons[5].id)
175
+ assert_equal("b9", arrButtons[6].id)
176
+ assert_equal("Sign In", arrButtons[7].value)
177
+ end
178
+
179
+ # Tests collection class
180
+ def test_class_buttons
181
+ arr_buttons = $ff.buttons
182
+ arr_buttons.each do |b|
183
+ assert(b.instance_of?(Button),"element class should be #{Button}; got #{b.class}")
184
+ end
185
+ # test properties
186
+ assert_equal("b2", arr_buttons[1].id)
187
+ assert_equal("b1", arr_buttons[1].name)
188
+ assert_equal("button", arr_buttons[1].type)
189
+ assert_equal("Click Me", arr_buttons[1].value)
190
+ assert_equal(false, arr_buttons[1].disabled)
191
+ assert_equal("italic_button", arr_buttons[1].class_name)
192
+ assert_equal( "this is button1", arr_buttons[1].title)
193
+
194
+ assert_equal("b5", arr_buttons[2].id)
195
+ assert_equal("b4", arr_buttons[2].name)
196
+ assert_equal("button", arr_buttons[2].type)
197
+ assert_equal("Disabled Button", arr_buttons[2].value)
198
+ assert_equal(true, arr_buttons[2].disabled)
199
+ assert_equal( "", arr_buttons[2].title)
200
+ assert_equal("", arr_buttons[2].class_name)
201
+
202
+ assert_equal("Submit", arr_buttons[3].value)
203
+ assert_equal("sub3", arr_buttons[4].name)
204
+ assert_equal("b7", arr_buttons[5].id)
205
+ assert_equal("b9", arr_buttons[6].id)
206
+ assert_equal("Sign In", arr_buttons[7].value)
207
+
208
+
209
+
210
+
211
+ end
212
+
213
+
214
+ end
215
+
@@ -0,0 +1,87 @@
1
+ # feature tests for Buttons
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_Buttons_XPath < Test::Unit::TestCase
8
+ include FireWatir
9
+
10
+ def setup
11
+ $ff.goto($htmlRoot + "buttons1.html")
12
+ end
13
+
14
+ def test_properties
15
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@name='noName']").id }
16
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@name='noName']").name }
17
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@name='noName']").disabled }
18
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@name='noName']").type }
19
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@name='noName']").value }
20
+
21
+ assert_equal("b1" , $ff.button(:xpath, "//input[@id='b2']").name )
22
+ assert_equal("b2" , $ff.button(:xpath, "//input[@id='b2']").id )
23
+ assert_equal("button" , $ff.button(:xpath, "//input[@id='b2']").type )
24
+ end
25
+
26
+ def test_button_using_default
27
+ # since most of the time, a button will be accessed based on its caption, there is a default way of accessing it....
28
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@value='Missing Caption']").click }
29
+
30
+ $ff.button(:xpath, "//input[@value='Click Me']").click
31
+ assert($ff.text.include?("PASS") )
32
+ end
33
+
34
+ def test_Button_click_only
35
+ $ff.button(:xpath, "//input[@value='Click Me']").click
36
+ assert($ff.text.include?("PASS") )
37
+ end
38
+
39
+ def test_button_click
40
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@value='Missing Caption']").click }
41
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@id='MissingId']").click }
42
+
43
+ assert_raises(ObjectDisabledException , "ObjectDisabledException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@value='Disabled Button']").click }
44
+
45
+ $ff.button(:xpath, "//input[@value='Click Me']").click
46
+ assert($ff.text.include?("PASS") )
47
+ end
48
+
49
+ def test_Button_Exists
50
+ assert($ff.button(:xpath, "//input[@value='Click Me']").exists?)
51
+ assert($ff.button(:xpath, "//input[@value='Submit']").exists?)
52
+ assert($ff.button(:xpath, "//input[@name='b1']").exists?)
53
+ assert($ff.button(:xpath, "//input[@id='b2']").exists?)
54
+
55
+ assert_false($ff.button(:xpath, "//input[@value='Missing Caption']").exists?)
56
+ assert_false($ff.button(:xpath, "//input[@name='missingname']").exists?)
57
+ assert_false($ff.button(:xpath, "//input[@id='missingid']").exists?)
58
+ end
59
+
60
+ def test_element_by_xpath_class
61
+ element = $ff.element_by_xpath("//input[@value='Click Me']")
62
+ assert(element.instance_of?(Button),"element class should be #{Button}; got #{element.class}")
63
+ element = $ff.element_by_xpath("//input[@value='Submit']")
64
+ assert(element.instance_of?(Button),"element class should be #{Button}; got #{element.class}")
65
+ element = $ff.element_by_xpath("//input[@name='b1']")
66
+ assert(element.instance_of?(Button),"element class should be #{Button}; got #{element.class}")
67
+ element = $ff.element_by_xpath("//input[@id='b2']")
68
+ assert(element.instance_of?(Button),"element class should be #{Button}; got #{element.class}")
69
+ # TODO: If object is not there this should return null
70
+ #element = $ff.element_by_xpath("//input[@value='Missing Caption']")
71
+ #assert(element.instance_of?(Button),"element class should be #{Button}; got #{element.class}")
72
+ #element = $ff.element_by_xpath("//input[@name='missingname']")
73
+ #assert(element.instance_of?(Button),"element class should be #{Button}; got #{element.class}")
74
+ #element = $ff.element_by_xpath("//input[@id='missingid']")
75
+ #assert(element.instance_of?(Button),"element class should be #{Button}; got #{element.class}")
76
+ end
77
+
78
+ def test_Button_Enabled
79
+ assert($ff.button(:xpath, "//input[@value='Click Me']").enabled?)
80
+ assert_false($ff.button(:xpath, "//input[@value='Disabled Button']").enabled?)
81
+ assert_false($ff.button(:xpath, "//input[@name='b4']").enabled?)
82
+ assert_false($ff.button(:xpath, "//input[@id='b5']").enabled?)
83
+
84
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.button(:xpath, "//input[@name='noName']").enabled? }
85
+ end
86
+ end
87
+
@@ -0,0 +1,154 @@
1
+ # feature tests for Check Boxes
2
+ # revision: $Revision: 1.0 $
3
+
4
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
5
+ require 'unittests/setup'
6
+
7
+ class TC_CheckBox < Test::Unit::TestCase
8
+ include FireWatir
9
+
10
+ def setup()
11
+ $ff.goto($htmlRoot + "checkboxes1.html")
12
+ end
13
+
14
+ def test_checkbox_properties
15
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.checkbox(:name, "noName").id }
16
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.checkbox(:name, "noName").name }
17
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.checkbox(:name, "noName").disabled }
18
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.checkbox(:name, "noName").type }
19
+ assert_raises(UnknownObjectException , "UnknownObjectException was supposed to be thrown" ) { $ff.checkbox(:name, "noName").value }
20
+
21
+ assert_equal("box1" , $ff.checkbox(:index, 1).name )
22
+ assert_instance_of(CheckBox,$ff.checkbox(:index,1))
23
+ assert_equal("" , $ff.checkbox(:index, 1).id )
24
+ assert_equal("checkbox" , $ff.checkbox(:index, 1).type )
25
+ assert_equal("on" , $ff.checkbox(:index, 1).value )
26
+ assert_equal(false , $ff.checkbox(:index, 1).disabled )
27
+
28
+ assert_equal("check_box_style" , $ff.checkbox(:name, "box1").class_name)
29
+ assert_equal("" , $ff.checkbox(:name, "box2").class_name)
30
+
31
+ assert_equal("1" , $ff.checkbox(:name,"box4").value )
32
+ assert_equal("3" , $ff.checkbox(:name,"box4" , 3).value )
33
+ assert_equal("checkbox" , $ff.checkbox(:name,"box4" , 3).type )
34
+ assert_equal(false , $ff.checkbox(:name,"box4" , 3).disabled )
35
+ assert_equal("" , $ff.checkbox(:name,"box4" , 3).id )
36
+
37
+ assert_equal("box4-value5" , $ff.checkbox(:name,"box4" , 5).title)
38
+ assert_equal("" , $ff.checkbox(:name,"box4" , 4).title)
39
+ end
40
+
41
+ def test_onClick
42
+ assert_false($ff.button(:value , "foo").enabled?)
43
+ $ff.checkbox(:name, "box5").set
44
+ assert($ff.button(:value , "foo").enabled?)
45
+
46
+ $ff.checkbox(:name, "box5").clear
47
+ assert_false($ff.button(:value , "foo").enabled?)
48
+
49
+ $ff.checkbox(:name, "box5").clear
50
+ assert_false($ff.button(:value , "foo").enabled?)
51
+ end
52
+
53
+ def test_CheckBox_Exists
54
+ assert($ff.checkbox(:name, "box1").exists?)
55
+ assert_false($ff.checkbox(:name, "missing").exists?)
56
+
57
+ assert($ff.checkbox(:name, "box4" , 1).exists?)
58
+ assert_false($ff.checkbox(:name, "box4" , 22).exists?)
59
+ end
60
+
61
+ #def test_checkbox_Enabled
62
+ # assert_raises(UnknownObjectException) { $ff.checkbox(:name, "noName").enabled? }
63
+ # assert_raises(UnknownObjectException) { $ff.checkbox(:id, "noName").enabled? }
64
+ # assert_raises(UnknownObjectException) { $ff.checkbox(:name, "box4" , 6).enabled? }
65
+ #
66
+ # assert($ff.checkbox(:name, "box1").enabled?)
67
+ # assert_false($ff.checkbox(:name, "box2").enabled?)
68
+ #
69
+ # assert($ff.checkbox(:name, "box4", 4).enabled?)
70
+ # assert_false($ff.checkbox(:name, "box4" , 5 ).enabled?)
71
+ #end
72
+
73
+ def test_checkbox_isSet
74
+ assert_raises(UnknownObjectException ) { $ff.checkbox(:name, "noName").isSet? }
75
+
76
+ assert_false($ff.checkbox(:name, "box1").isSet?)
77
+ assert_false($ff.checkbox(:name, "box2").isSet?)
78
+ assert($ff.checkbox(:name, "box3").isSet?)
79
+
80
+ assert_false($ff.checkbox(:name, "box4" , 2 ).isSet?)
81
+ assert($ff.checkbox(:name, "box4" , 1 ).isSet?)
82
+ end
83
+
84
+ def test_checkbox_clear
85
+ assert_raises(UnknownObjectException) { $ff.checkbox(:name, "noName").clear }
86
+ $ff.checkbox(:name, "box1").clear
87
+ assert_false($ff.checkbox(:name, "box1").isSet?)
88
+
89
+ assert_raises(ObjectDisabledException) { $ff.checkbox(:name, "box2").clear }
90
+ assert_false($ff.checkbox(:name, "box2").isSet?)
91
+
92
+ $ff.checkbox(:name, "box3").clear
93
+ assert_false($ff.checkbox(:name, "box3").isSet?)
94
+
95
+ $ff.checkbox(:name, "box4" , 1).clear
96
+ assert_false($ff.checkbox(:name, "box4" , 1).isSet?)
97
+ end
98
+
99
+ def test_checkbox_getState
100
+ assert_raises(UnknownObjectException) { $ff.checkbox(:name, "noName").getState }
101
+ assert_equal( false , $ff.checkbox(:name, "box1").getState )
102
+ assert_equal( true , $ff.checkbox(:name, "box3").getState)
103
+
104
+ # checkboxes that have the same name but different values
105
+ assert_equal( false , $ff.checkbox(:name, "box4" , 2).getState )
106
+ assert_equal( true , $ff.checkbox(:name, "box4" , 1).getState)
107
+ end
108
+
109
+ def test_checkbox_set
110
+ assert_raises(UnknownObjectException) { $ff.checkbox(:name, "noName").set }
111
+ $ff.checkbox(:name, "box1").set
112
+ assert($ff.checkbox(:name, "box1").isSet?)
113
+
114
+ assert_raises(ObjectDisabledException) { $ff.checkbox(:name, "box2").set }
115
+
116
+ $ff.checkbox(:name, "box3").set
117
+ assert($ff.checkbox(:name, "box3").isSet?)
118
+
119
+ # checkboxes that have the same name but different values
120
+ $ff.checkbox(:name, "box4" , 3).set
121
+ assert($ff.checkbox(:name, "box4" , 3).isSet?)
122
+
123
+ # test set using the optinal true/false
124
+ # assumes the checkbox is already checked
125
+ $ff.checkbox(:name, "box1").set( false )
126
+ assert_false($ff.checkbox(:name, "box1").isSet?)
127
+
128
+ $ff.checkbox(:name, "box1").set( true )
129
+ assert($ff.checkbox(:name, "box1").isSet?)
130
+
131
+
132
+
133
+
134
+ end
135
+
136
+ def test_checkbox_iterator
137
+
138
+ assert_equal(11, $ff.checkboxes.length)
139
+ assert_equal("box1" , $ff.checkboxes[1].name )
140
+
141
+ index=1
142
+ $ff.checkboxes.each do |c|
143
+ assert_equal( $ff.checkbox(:index, index).name , c.name )
144
+ assert_equal( $ff.checkbox(:index, index).id, c.id )
145
+ assert_equal( $ff.checkbox(:index, index).value, c.value )
146
+ assert_equal( $ff.checkbox(:index, index).isSet?, c.isSet? )
147
+ index+=1
148
+ end
149
+ assert_equal(index-1, $ff.checkboxes.length)
150
+
151
+ end
152
+
153
+
154
+ end