Module: RWebUnit::Assert
- Includes:
- Test::Unit::Assertions
- Included in:
- AbstractWebPage, RSpecHelper, TestScript, WebTestCase
- Defined in:
- lib/rwebunit/assert.rb
Instance Method Summary collapse
-
#assert_button_not_present(button_id) ⇒ Object
Button.
- #assert_button_not_present_with_text(text) ⇒ Object
- #assert_button_present(button_id) ⇒ Object
- #assert_button_present_with_text(button_text) ⇒ Object
-
#assert_checkbox_not_selected(checkbox_name) ⇒ Object
(also: #assert_checkbox_not_checked)
Checkbox.
- #assert_checkbox_selected(checkbox_name) ⇒ Object (also: #assert_checkbox_checked)
- #assert_equals(expected, actual, msg = nil) ⇒ Object
-
#assert_exists(tag, element_id) ⇒ Object
(also: #assert_exists?, #assert_element_exists)
Check a HTML element exists or not Example: assert_exists(“label”, “receipt_date”) assert_exists(:span, :receipt_date).
-
#assert_hidden(tag, element_id) ⇒ Object
(also: #assert_not_visible)
Assert tag with element id is hidden?, example assert_hidden(:div, “secret”) assert_hidden(:span, “secret_span”).
- #assert_link_not_present_with_exact(link_text) ⇒ Object
- #assert_link_not_present_with_text(link_text) ⇒ Object
-
#assert_link_present_with_exact(link_text) ⇒ Object
Assert a link with specified text (exact match) in the page.
-
#assert_link_present_with_text(link_text) ⇒ Object
Assert a link containing specified text in the page <a href=“”>Click Me</a> assert_link_present_with_text(“Click ”) # =>.
- #assert_nil(actual, msg = "") ⇒ Object
- #assert_not(condition, msg = "") ⇒ Object
- #assert_not_exists(tag, element_id) ⇒ Object (also: #assert_not_exists?, #assert_element_not_exists?)
- #assert_not_nil(actual, msg = "") ⇒ Object
- #assert_option_equals(select_name, option_label) ⇒ Object (also: #assert_select_label)
- #assert_option_not_present(select_name, option_label) ⇒ Object (also: #assert_select_label_not_present)
- #assert_option_present(select_name, option_label) ⇒ Object (also: #assert_select_label_present)
- #assert_option_value_equals(select_name, option_value) ⇒ Object (also: #assert_select_value)
-
#assert_option_value_not_present(select_name, option_value) ⇒ Object
(also: #assert_select_value_not_present)
select.
- #assert_option_value_present(select_name, option_value) ⇒ Object (also: #assert_select_value_present)
-
#assert_radio_option_not_present(radio_group, radio_option) ⇒ Object
radio_group is the name field, radio options ‘value’ field.
- #assert_radio_option_not_selected(radio_group, radio_option) ⇒ Object (also: #assert_radio_button_not_checked, #assert_radio_option_not_checked)
- #assert_radio_option_present(radio_group, radio_option) ⇒ Object
- #assert_radio_option_selected(radio_group, radio_option) ⇒ Object (also: #assert_radio_button_checked, #assert_radio_option_checked)
-
#assert_text_field_value(textfield_name, text) ⇒ Object
Assert a text field (with given name) has the value.
-
#assert_text_in_element(element_id, text) ⇒ Object
– Not tested —–.
-
#assert_text_not_present(text) ⇒ Object
Assert text not present in page source (html) assert_text_not_present(“<h1>iTest2</h1>”).
- #assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false }) ⇒ Object (also: #assert_text_not_in_table)
-
#assert_text_present(text) ⇒ Object
Assert text present in page source (html) assert_text_present(“<h1>iTest2</h1>”).
-
#assert_text_present_in_table(table_id, text, options = { :just_plain_text => false }) ⇒ Object
(also: #assert_text_in_table)
Assert given text appear inside a table (inside <table> tag like below) .
-
#assert_title_equals(title) ⇒ Object
(also: #assert_title)
assertions.
-
#assert_visible(tag, element_id) ⇒ Object
Assert tag with element id is visible?, eg.
- #fail(message) ⇒ Object
Instance Method Details
#assert_button_not_present(button_id) ⇒ Object
Button
209 210 211 212 213 |
# File 'lib/rwebunit/assert.rb', line 209 def () @web_browser..each { || assert(.id != , "unexpected button id: #{} found") } end |
#assert_button_not_present_with_text(text) ⇒ Object
215 216 217 218 219 |
# File 'lib/rwebunit/assert.rb', line 215 def (text) @web_browser..each { || assert(.value != text, "unexpected button id: #{text} found") } end |
#assert_button_present(button_id) ⇒ Object
221 222 223 224 225 226 |
# File 'lib/rwebunit/assert.rb', line 221 def () @web_browser..each { || return if == .id } assert(false, "can't find the button with id: #{}") end |
#assert_button_present_with_text(button_text) ⇒ Object
228 229 230 231 232 233 |
# File 'lib/rwebunit/assert.rb', line 228 def () @web_browser..each { || return if == .value } assert(false, "can't find the button with text: #{}") end |
#assert_checkbox_not_selected(checkbox_name) ⇒ Object Also known as: assert_checkbox_not_checked
Checkbox
86 87 88 89 90 91 92 |
# File 'lib/rwebunit/assert.rb', line 86 def assert_checkbox_not_selected(checkbox_name) @web_browser.checkboxes.each { |checkbox| if (checkbox.name == checkbox_name) then assert(!checkbox.isSet?, "Checkbox #{checkbox_name} is checked unexpectly") end } end |
#assert_checkbox_selected(checkbox_name) ⇒ Object Also known as: assert_checkbox_checked
95 96 97 98 99 100 101 |
# File 'lib/rwebunit/assert.rb', line 95 def assert_checkbox_selected(checkbox_name) @web_browser.checkboxes.each { |checkbox| if (checkbox.name == checkbox_name) then assert(checkbox.isSet?, "Checkbox #{checkbox_name} not checked") end } end |
#assert_equals(expected, actual, msg = nil) ⇒ Object
236 237 238 |
# File 'lib/rwebunit/assert.rb', line 236 def assert_equals(expected, actual, msg=nil) assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg) end |
#assert_exists(tag, element_id) ⇒ Object Also known as: assert_exists?, assert_element_exists
Check a HTML element exists or not Example:
assert_exists("label", "receipt_date")
assert_exists(:span, :receipt_date)
246 247 248 249 250 251 252 |
# File 'lib/rwebunit/assert.rb', line 246 def assert_exists(tag, element_id) {} begin assert eval("#{tag}(:id, '#{element_id.to_s}').exists?") rescue => e raise "Element '#{tag}' with id: '#{element_id}' not found, #{e}" end end |
#assert_hidden(tag, element_id) ⇒ Object Also known as: assert_not_visible
Assert tag with element id is hidden?, example
assert_hidden(:div, "secret")
assert_hidden(:span, "secret_span")
281 282 283 284 285 286 287 |
# File 'lib/rwebunit/assert.rb', line 281 def assert_hidden(tag, element_id) begin assert(!eval("#{tag}(:id, '#{element_id.to_s}').visible?")) rescue => e raise "Element '#{tag}' with id: '#{element_id}' is visible, #{e}" end end |
#assert_link_not_present_with_exact(link_text) ⇒ Object
59 60 61 62 63 |
# File 'lib/rwebunit/assert.rb', line 59 def assert_link_not_present_with_exact(link_text) @web_browser.links.each { |link| assert(link_text != link.text, "unexpected link (exact): #{link_text} found") } end |
#assert_link_not_present_with_text(link_text) ⇒ Object
77 78 79 80 81 |
# File 'lib/rwebunit/assert.rb', line 77 def assert_link_not_present_with_text(link_text) @web_browser.links.each { |link| assert(!link.text.include?(link_text), "unexpected link containing: #{link_text} found") } end |
#assert_link_present_with_exact(link_text) ⇒ Object
Assert a link with specified text (exact match) in the page
<a href="">Click Me</a>
assert_link_present_with_exact("Click Me") => true
assert_link_present_with_exact("Click") => false
52 53 54 55 56 57 |
# File 'lib/rwebunit/assert.rb', line 52 def assert_link_present_with_exact(link_text) @web_browser.links.each { |link| return if link_text == link.text } fail( "can't find the link with text: #{link_text}") end |
#assert_link_present_with_text(link_text) ⇒ Object
Assert a link containing specified text in the page
<a href="">Click Me</a>
assert_link_present_with_text("Click ") # =>
70 71 72 73 74 75 |
# File 'lib/rwebunit/assert.rb', line 70 def assert_link_present_with_text(link_text) @web_browser.links.each { |link| return if link.text.include?(link_text) } fail( "can't find the link containing text: #{link_text}") end |
#assert_nil(actual, msg = "") ⇒ Object
12 13 14 |
# File 'lib/rwebunit/assert.rb', line 12 def assert_nil(actual, msg="") assert(actual.nil?, msg) end |
#assert_not(condition, msg = "") ⇒ Object
8 9 10 |
# File 'lib/rwebunit/assert.rb', line 8 def assert_not(condition, msg = "") assert(!condition, msg) end |
#assert_not_exists(tag, element_id) ⇒ Object Also known as: assert_not_exists?, assert_element_not_exists?
256 257 258 259 260 261 262 |
# File 'lib/rwebunit/assert.rb', line 256 def assert_not_exists(tag, element_id) {} begin assert_not eval("#{tag}(:id, '#{element_id.to_s}').exists?") raise "Unexpected element'#{tag}' + with id: '#{element_id}' found" rescue => e end end |
#assert_not_nil(actual, msg = "") ⇒ Object
16 17 18 |
# File 'lib/rwebunit/assert.rb', line 16 def assert_not_nil(actual, msg="") assert(!actual.nil?, msg) end |
#assert_option_equals(select_name, option_label) ⇒ Object Also known as: assert_select_label
148 149 150 151 152 153 154 155 156 157 |
# File 'lib/rwebunit/assert.rb', line 148 def assert_option_equals(select_name, option_label) @web_browser.select_lists.each { |select| next unless select.name == select_name select.o.each do |option| # items in the list if (option.text == option_label) then assert_equal(select.value, option.value, "Select #{select_name}'s value is not equal to expected option label: '#{option_label}'") end end } end |
#assert_option_not_present(select_name, option_label) ⇒ Object Also known as: assert_select_label_not_present
116 117 118 119 120 121 122 123 |
# File 'lib/rwebunit/assert.rb', line 116 def assert_option_not_present(select_name, option_label) @web_browser.select_lists.each { |select| next unless select.name == select_name select.o.each do |option| # items in the list assert(!(option.text == option_label), "unexpected select option: #{option_label} for #{select_name} found") end } end |
#assert_option_present(select_name, option_label) ⇒ Object Also known as: assert_select_label_present
137 138 139 140 141 142 143 144 145 |
# File 'lib/rwebunit/assert.rb', line 137 def assert_option_present(select_name, option_label) @web_browser.select_lists.each { |select| next unless select.name == select_name select.o.each do |option| # items in the list return if option.text == option_label end } assert(false, "can't find the combob box: #{select_name} with value: #{option_label}") end |
#assert_option_value_equals(select_name, option_value) ⇒ Object Also known as: assert_select_value
160 161 162 163 164 165 |
# File 'lib/rwebunit/assert.rb', line 160 def assert_option_value_equals(select_name, option_value) @web_browser.select_lists.each { |select| next unless select.name == select_name assert_equal(select.value, option_value, "Select #{select_name}'s value is not equal to expected: '#{option_value}'") } end |
#assert_option_value_not_present(select_name, option_value) ⇒ Object Also known as: assert_select_value_not_present
select
106 107 108 109 110 111 112 113 |
# File 'lib/rwebunit/assert.rb', line 106 def assert_option_value_not_present(select_name, option_value) @web_browser.select_lists.each { |select| continue unless select.name == select_name select.o.each do |option| # items in the list assert(!(option.value == option_value), "unexpected select option: #{option_value} for #{select_name} found") end } end |
#assert_option_value_present(select_name, option_value) ⇒ Object Also known as: assert_select_value_present
126 127 128 129 130 131 132 133 134 |
# File 'lib/rwebunit/assert.rb', line 126 def assert_option_value_present(select_name, option_value) @web_browser.select_lists.each { |select| next unless select.name == select_name select.o.each do |option| # items in the list return if option.value == option_value end } assert(false, "can't find the combob box with value: #{option_value}") end |
#assert_radio_option_not_present(radio_group, radio_option) ⇒ Object
radio_group is the name field, radio options ‘value’ field
172 173 174 175 176 177 178 |
# File 'lib/rwebunit/assert.rb', line 172 def assert_radio_option_not_present(radio_group, radio_option) @web_browser.radios.each { |radio| if (radio.name == radio_group) then assert(!(radio_option == radio.value), "unexpected radio option: " + radio_option + " found") end } end |
#assert_radio_option_not_selected(radio_group, radio_option) ⇒ Object Also known as: assert_radio_option_not_checked ,
197 198 199 200 201 202 203 |
# File 'lib/rwebunit/assert.rb', line 197 def assert_radio_option_not_selected(radio_group, radio_option) @web_browser.radios.each { |radio| if (radio.name == radio_group and radio_option == radio.value) then assert(!radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] checked unexpected") end } end |
#assert_radio_option_present(radio_group, radio_option) ⇒ Object
180 181 182 183 184 185 |
# File 'lib/rwebunit/assert.rb', line 180 def assert_radio_option_present(radio_group, radio_option) @web_browser.radios.each { |radio| return if (radio.name == radio_group) and (radio_option == radio.value) } fail("can't find the radio option : '#{radio_option}'") end |
#assert_radio_option_selected(radio_group, radio_option) ⇒ Object Also known as: assert_radio_option_checked ,
187 188 189 190 191 192 193 |
# File 'lib/rwebunit/assert.rb', line 187 def assert_radio_option_selected(radio_group, radio_option) @web_browser.radios.each { |radio| if (radio.name == radio_group and radio_option == radio.value) then assert(radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] not checked") end } end |
#assert_text_field_value(textfield_name, text) ⇒ Object
Assert a text field (with given name) has the value
<input id=“tid” name=“text1” value=“text already there” type=“text”>
assert_text_field_value(“text1”, “text already there”) => true
330 331 332 |
# File 'lib/rwebunit/assert.rb', line 330 def assert_text_field_value(textfield_name, text) assert_equal(text, text_field(:name, textfield_name).value) end |
#assert_text_in_element(element_id, text) ⇒ Object
– Not tested
338 339 340 341 342 |
# File 'lib/rwebunit/assert.rb', line 338 def assert_text_in_element(element_id, text) elem = element_by_id(element_id) assert_not_nil(elem.innerText, "element #{element_id} has no text") assert(elem.innerText.include?(text), "the text #{text} not found in element #{element_id}") end |
#assert_text_not_present(text) ⇒ Object
Assert text not present in page source (html)
assert_text_not_present("<h1>iTest2</h1>")
38 39 40 |
# File 'lib/rwebunit/assert.rb', line 38 def assert_text_not_present(text) assert(!(@web_browser.page_source.include? text), 'expected text: ' + text + ' found') end |
#assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false }) ⇒ Object Also known as: assert_text_not_in_table
319 320 321 |
# File 'lib/rwebunit/assert.rb', line 319 def assert_text_not_present_in_table(table_id, text, = { :just_plain_text => false }) assert_not(table_source(table_id, ).include?(text), "the text #{text} not found in table #{table_id}") end |
#assert_text_present(text) ⇒ Object
Assert text present in page source (html)
assert_text_present("<h1>iTest2</h1>")
32 33 34 |
# File 'lib/rwebunit/assert.rb', line 32 def assert_text_present(text) assert((@web_browser.page_source.include? text), 'expected text: ' + text + ' not found') end |
#assert_text_present_in_table(table_id, text, options = { :just_plain_text => false }) ⇒ Object Also known as: assert_text_in_table
Assert given text appear inside a table (inside <table> tag like below)
<table id=“t1”>
<tbody>
<tr id="row_1">
<td id="cell_1_1">A</td>
<td id="cell_1_2">B</td>
</tr>
<tr id="row_2">
<td id="cell_2_1">a</td>
<td id="cell_2_2">b</td>
</tr>
</tbody>
</table>
The plain text view of above table
A B a b
Examples
assert_text_present_in_table("t1", ">A<") # => true
assert_text_present_in_table("t1", ">A<", :just_plain_text => true) # => false
314 315 316 |
# File 'lib/rwebunit/assert.rb', line 314 def assert_text_present_in_table(table_id, text, = { :just_plain_text => false }) assert(table_source(table_id, ).include?(text), "the text #{text} not found in table #{table_id}") end |
#assert_title_equals(title) ⇒ Object Also known as: assert_title
assertions
25 26 27 |
# File 'lib/rwebunit/assert.rb', line 25 def assert_title_equals(title) assert_equals(title, @web_browser.page_title) end |
#assert_visible(tag, element_id) ⇒ Object
Assert tag with element id is visible?, eg.
assert_visible(:div, "public_notice")
assert_visible(:span, "public_span")
270 271 272 273 274 275 276 |
# File 'lib/rwebunit/assert.rb', line 270 def assert_visible(tag, element_id) begin assert(eval("#{tag}(:id, '#{element_id.to_s}').visible?")) rescue => e raise "Element '#{tag}' with id: '#{element_id}' not visible, #{e}" end end |
#fail(message) ⇒ Object
20 21 22 |
# File 'lib/rwebunit/assert.rb', line 20 def fail() assert(false, ) end |