Module: RWebSpec::Mechanize::Assert
- Includes:
- Test::Unit::Assertions
- Included in:
- LoadTestHelper
- Defined in:
- lib/rwebspec-mechanize/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_menu_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_menu_label_present)
- #assert_option_value_equals(select_name, option_value) ⇒ Object (also: #assert_select_value, #assert_menu_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_menu_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_in_page_source(text) ⇒ Object
Assert text present in page source (html) assert_text_in_page_source(“iTest2 Cool”) # iTest2 Cool.
-
#assert_text_not_in_page_source(text) ⇒ Object
Assert text not present in page source (html) assert_text_not_in_page_source(“iTest2 Cool”) # iTest2 Cool.
-
#assert_text_not_present(text) ⇒ Object
Assert text not present in page source (html) assert_text_not_present(“iTest2 Cool”) # iTest2 Cool.
- #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(“iTest2 Cool”) # iTest2 Cool.
-
#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
236 237 238 239 240 |
# File 'lib/rwebspec-mechanize/assert.rb', line 236 def () @web_browser..each { || perform_assertion { assert(.id != , "unexpected button id: #{} found") } } end |
#assert_button_not_present_with_text(text) ⇒ Object
242 243 244 245 246 |
# File 'lib/rwebspec-mechanize/assert.rb', line 242 def (text) @web_browser..each { || perform_assertion { assert(.value != text, "unexpected button id: #{text} found") } } end |
#assert_button_present(button_id) ⇒ Object
248 249 250 251 252 253 |
# File 'lib/rwebspec-mechanize/assert.rb', line 248 def () @web_browser..each { || return if == .id } fail("can't find the button with id: #{}") end |
#assert_button_present_with_text(button_text) ⇒ Object
255 256 257 258 259 260 |
# File 'lib/rwebspec-mechanize/assert.rb', line 255 def () @web_browser..each { || return if == .value } fail("can't find the button with text: #{}") end |
#assert_checkbox_not_selected(checkbox_name) ⇒ Object Also known as: assert_checkbox_not_checked
Checkbox
99 100 101 102 103 104 105 |
# File 'lib/rwebspec-mechanize/assert.rb', line 99 def assert_checkbox_not_selected(checkbox_name) @web_browser.checkboxes.each { |checkbox| if (checkbox.name == checkbox_name) then perform_assertion { assert(!checkbox.isSet?, "Checkbox #{checkbox_name} is checked unexpectly") } end } end |
#assert_checkbox_selected(checkbox_name) ⇒ Object Also known as: assert_checkbox_checked
109 110 111 112 113 114 115 |
# File 'lib/rwebspec-mechanize/assert.rb', line 109 def assert_checkbox_selected(checkbox_name) @web_browser.checkboxes.each { |checkbox| if (checkbox.name == checkbox_name) then perform_assertion { assert(checkbox.isSet?, "Checkbox #{checkbox_name} not checked") } end } end |
#assert_equals(expected, actual, msg = nil) ⇒ Object
263 264 265 |
# File 'lib/rwebspec-mechanize/assert.rb', line 263 def assert_equals(expected, actual, msg=nil) perform_assertion { 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)
272 273 274 |
# File 'lib/rwebspec-mechanize/assert.rb', line 272 def assert_exists(tag, element_id) perform_assertion { assert(eval("#{tag}(:id, '#{element_id.to_s}').exists?"), "Element '#{tag}' with id: '#{element_id}' not found") } 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")
297 298 299 |
# File 'lib/rwebspec-mechanize/assert.rb', line 297 def assert_hidden(tag, element_id) perform_assertion { assert(!eval("#{tag}(:id, '#{element_id.to_s}').visible?"), "Element '#{tag}' with id: '#{element_id}' is visible") } end |
#assert_link_not_present_with_exact(link_text) ⇒ Object
72 73 74 75 76 |
# File 'lib/rwebspec-mechanize/assert.rb', line 72 def assert_link_not_present_with_exact(link_text) @web_browser.links.each { |link| perform_assertion { assert(link_text != link.text, "unexpected link (exact): #{link_text} found") } } end |
#assert_link_not_present_with_text(link_text) ⇒ Object
90 91 92 93 94 |
# File 'lib/rwebspec-mechanize/assert.rb', line 90 def assert_link_not_present_with_text(link_text) @web_browser.links.each { |link| perform_assertion { 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
65 66 67 68 69 70 |
# File 'lib/rwebspec-mechanize/assert.rb', line 65 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 ") # =>
83 84 85 86 87 88 |
# File 'lib/rwebspec-mechanize/assert.rb', line 83 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/rwebspec-mechanize/assert.rb', line 12 def assert_nil(actual, msg="") perform_assertion { assert(actual.nil?, msg) } end |
#assert_not(condition, msg = "") ⇒ Object
8 9 10 |
# File 'lib/rwebspec-mechanize/assert.rb', line 8 def assert_not(condition, msg = "") perform_assertion { assert(!condition, msg) } end |
#assert_not_exists(tag, element_id) ⇒ Object Also known as: assert_not_exists?, assert_element_not_exists?
279 280 281 |
# File 'lib/rwebspec-mechanize/assert.rb', line 279 def assert_not_exists(tag, element_id) perform_assertion { assert_not(eval("#{tag}(:id, '#{element_id.to_s}').exists?"), "Unexpected element'#{tag}' + with id: '#{element_id}' found")} end |
#assert_not_nil(actual, msg = "") ⇒ Object
16 17 18 |
# File 'lib/rwebspec-mechanize/assert.rb', line 16 def assert_not_nil(actual, msg="") perform_assertion { assert(!actual.nil?, msg) } end |
#assert_option_equals(select_name, option_label) ⇒ Object Also known as: assert_select_label,
169 170 171 172 173 174 175 176 177 178 |
# File 'lib/rwebspec-mechanize/assert.rb', line 169 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 perform_assertion { 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
132 133 134 135 136 137 138 139 |
# File 'lib/rwebspec-mechanize/assert.rb', line 132 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 perform_assertion { 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,
156 157 158 159 160 161 162 163 164 |
# File 'lib/rwebspec-mechanize/assert.rb', line 156 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 } fail("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,
183 184 185 186 187 188 |
# File 'lib/rwebspec-mechanize/assert.rb', line 183 def assert_option_value_equals(select_name, option_value) @web_browser.select_lists.each { |select| next unless select.name == select_name perform_assertion { 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
121 122 123 124 125 126 127 128 |
# File 'lib/rwebspec-mechanize/assert.rb', line 121 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 perform_assertion { 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,
143 144 145 146 147 148 149 150 151 |
# File 'lib/rwebspec-mechanize/assert.rb', line 143 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 } fail("can't find the combo 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
197 198 199 200 201 202 203 |
# File 'lib/rwebspec-mechanize/assert.rb', line 197 def assert_radio_option_not_present(radio_group, radio_option) @web_browser.radios.each { |radio| if (radio.name == radio_group) then perform_assertion { 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 ,
223 224 225 226 227 228 229 |
# File 'lib/rwebspec-mechanize/assert.rb', line 223 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 perform_assertion { assert(!radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] checked unexpected") } end } end |
#assert_radio_option_present(radio_group, radio_option) ⇒ Object
205 206 207 208 209 210 |
# File 'lib/rwebspec-mechanize/assert.rb', line 205 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 ,
212 213 214 215 216 217 218 |
# File 'lib/rwebspec-mechanize/assert.rb', line 212 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 perform_assertion { 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
345 346 347 |
# File 'lib/rwebspec-mechanize/assert.rb', line 345 def assert_text_field_value(textfield_name, text) perform_assertion { assert_equal(text, text_field(:name, textfield_name).value) } end |
#assert_text_in_element(element_id, text) ⇒ Object
– Not tested
353 354 355 356 357 |
# File 'lib/rwebspec-mechanize/assert.rb', line 353 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") perform_assertion { assert(elem.innerText.include?(text), "the text #{text} not found in element #{element_id}") } end |
#assert_text_in_page_source(text) ⇒ Object
Assert text present in page source (html)
assert_text_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
33 34 35 |
# File 'lib/rwebspec-mechanize/assert.rb', line 33 def assert_text_in_page_source(text) perform_assertion { assert((@web_browser.page_source.include? text), 'expected html: ' + text + ' not found') } end |
#assert_text_not_in_page_source(text) ⇒ Object
Assert text not present in page source (html)
assert_text_not_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
39 40 41 |
# File 'lib/rwebspec-mechanize/assert.rb', line 39 def assert_text_not_in_page_source(text) perform_assertion { assert(!(@web_browser.page_source.include? text), 'expected html: ' + text + ' found') } end |
#assert_text_not_present(text) ⇒ Object
Assert text not present in page source (html)
assert_text_not_present("iTest2 Cool") # <b>iTest2</b> Cool
51 52 53 |
# File 'lib/rwebspec-mechanize/assert.rb', line 51 def assert_text_not_present(text) perform_assertion { assert(!(@web_browser.text.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
333 334 335 |
# File 'lib/rwebspec-mechanize/assert.rb', line 333 def assert_text_not_present_in_table(table_id, text, = { :just_plain_text => false }) perform_assertion { 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("iTest2 Cool") # <b>iTest2</b> Cool
45 46 47 |
# File 'lib/rwebspec-mechanize/assert.rb', line 45 def assert_text_present(text) perform_assertion { assert((@web_browser.text.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
327 328 329 |
# File 'lib/rwebspec-mechanize/assert.rb', line 327 def assert_text_present_in_table(table_id, text, = { :just_plain_text => false }) perform_assertion { 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/rwebspec-mechanize/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")
290 291 292 |
# File 'lib/rwebspec-mechanize/assert.rb', line 290 def assert_visible(tag, element_id) perform_assertion { assert(eval("#{tag}(:id, '#{element_id.to_s}').visible?"), "Element '#{tag}' with id: '#{element_id}' not visible") } end |
#fail(message) ⇒ Object
20 21 22 |
# File 'lib/rwebspec-mechanize/assert.rb', line 20 def fail() perform_assertion { assert(false, ) } end |