Checkbox
# File lib/rwebspec/assert.rb, line 98 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
# File lib/rwebspec/assert.rb, line 108 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
# File lib/rwebspec/assert.rb, line 262 def assert_equals(expected, actual, msg=nil) perform_assertion { assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg) } end
Check a HTML element exists or not Example:
assert_exists("label", "receipt_date")
assert_exists(:span, :receipt_date)
# File lib/rwebspec/assert.rb, line 271 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
# File lib/rwebspec/assert.rb, line 71 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
# File lib/rwebspec/assert.rb, line 89 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 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
# File lib/rwebspec/assert.rb, line 64 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 a link containing specified text in the page
<a href="">Click Me</a>
assert_link_present_with_text("Click ") # =>
# File lib/rwebspec/assert.rb, line 82 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
# File lib/rwebspec/assert.rb, line 11 def assert_nil(actual, msg="") perform_assertion { assert(actual.nil?, msg) } end
# File lib/rwebspec/assert.rb, line 7 def assert_not(condition, msg = "") perform_assertion { assert(!condition, msg) } end
# File lib/rwebspec/assert.rb, line 278 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
# File lib/rwebspec/assert.rb, line 15 def assert_not_nil(actual, msg="") perform_assertion { assert(!actual.nil?, msg) } end
# File lib/rwebspec/assert.rb, line 168 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
# File lib/rwebspec/assert.rb, line 131 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
# File lib/rwebspec/assert.rb, line 155 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
# File lib/rwebspec/assert.rb, line 182 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
select
# File lib/rwebspec/assert.rb, line 120 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
# File lib/rwebspec/assert.rb, line 142 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
radio_group is the name field, radio options ‘value’ field
# File lib/rwebspec/assert.rb, line 196 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
# File lib/rwebspec/assert.rb, line 222 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
# File lib/rwebspec/assert.rb, line 204 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
# File lib/rwebspec/assert.rb, line 211 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 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
# File lib/rwebspec/assert.rb, line 344 def assert_text_field_value(textfield_name, text) perform_assertion { assert_equal(text, text_field(:name, textfield_name).value) } end
# File lib/rwebspec/assert.rb, line 352 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 present in page source (html)
assert_text_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
# File lib/rwebspec/assert.rb, line 32 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 present in page source (html)
assert_text_not_in_page_source("<b>iTest2</b> Cool") # <b>iTest2</b> Cool
# File lib/rwebspec/assert.rb, line 38 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 in page source (html)
assert_text_not_present("iTest2 Cool") # <b>iTest2</b> Cool
# File lib/rwebspec/assert.rb, line 50 def assert_text_not_present(text) perform_assertion { assert(!(@web_browser.text.include? text), 'expected text: ' + text + ' found') } end
# File lib/rwebspec/assert.rb, line 332 def assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false }) perform_assertion { assert_not(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") } end
Assert text present in page source (html)
assert_text_present("iTest2 Cool") # <b>iTest2</b> Cool
# File lib/rwebspec/assert.rb, line 44 def assert_text_present(text) perform_assertion { assert((@web_browser.text.include? text), 'expected text: ' + text + ' not found') } end
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
# File lib/rwebspec/assert.rb, line 326 def assert_text_present_in_table(table_id, text, options = { :just_plain_text => false }) perform_assertion { assert(table_source(table_id, options).include?(text), "the text #{text} not found in table #{table_id}") } end
assertions
# File lib/rwebspec/assert.rb, line 24 def assert_title_equals(title) assert_equals(title, @web_browser.page_title) end
Assert tag with element id is visible?, eg.
assert_visible(:div, "public_notice") assert_visible(:span, "public_span")
# File lib/rwebspec/assert.rb, line 289 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
Generated with the Darkfish Rdoc Generator 2.