Methods

Included Modules

RWebSpec::Assert

Public Instance Methods

assert_button_not_present(button_id) click to toggle source

Button

# File lib/rwebspec/assert.rb, line 235
def assert_button_not_present(button_id)
  @web_browser.buttons.each { |button|
    perform_assertion { assert(button.id != button_id, "unexpected button id: #{button_id} found") }
  }
end
assert_button_not_present_with_text(text) click to toggle source
# File lib/rwebspec/assert.rb, line 241
def assert_button_not_present_with_text(text)
  @web_browser.buttons.each { |button|
    perform_assertion { assert(button.value != text, "unexpected button id: #{text} found") }
  }
end
assert_button_present(button_id) click to toggle source
# File lib/rwebspec/assert.rb, line 247
def assert_button_present(button_id)
  @web_browser.buttons.each { |button|
    return if button_id == button.id
  }
  fail("can't find the button with id: #{button_id}")
end
assert_button_present_with_text(button_text) click to toggle source
# File lib/rwebspec/assert.rb, line 254
def assert_button_present_with_text(button_text)
  @web_browser.buttons.each { |button|
    return if button_text == button.value
  }
  fail("can't find the button with text: #{button_text}")
end
assert_checkbox_checked(checkbox_name) click to toggle source
assert_checkbox_not_checked(checkbox_name) click to toggle source
assert_checkbox_not_selected(checkbox_name) click to toggle source

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
Also aliased as: assert_checkbox_not_checked
assert_checkbox_selected(checkbox_name) click to toggle source
# 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
Also aliased as: assert_checkbox_checked
assert_element_exists(tag, element_id) click to toggle source
Alias for: assert_exists
assert_element_not_exists?(tag, element_id) click to toggle source
Alias for: assert_not_exists
assert_equals(expected, actual, msg=nil) click to toggle source
# 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
assert_exists(tag, element_id) click to toggle source

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
assert_exists?(tag, element_id) click to toggle source
Alias for: assert_exists
assert_hidden(tag, element_id) click to toggle source

Assert tag with element id is hidden?, example

assert_hidden(:div, "secret")
assert_hidden(:span, "secret_span")
# File lib/rwebspec/assert.rb, line 296
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
Also aliased as: assert_not_visible
assert_menu_label(select_name, option_label) click to toggle source
assert_menu_label_present(select_name, option_label) click to toggle source
assert_menu_value(select_name, option_value) click to toggle source
assert_menu_value_present(select_name, option_value) click to toggle source
assert_nil(actual, msg="") click to toggle source
# File lib/rwebspec/assert.rb, line 11
def assert_nil(actual, msg="")
  perform_assertion { assert(actual.nil?, msg) }
end
assert_not(condition, msg = "") click to toggle source
# File lib/rwebspec/assert.rb, line 7
def assert_not(condition, msg = "")
  perform_assertion { assert(!condition, msg) }
end
assert_not_exists(tag, element_id) click to toggle source
# 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
assert_not_exists?(tag, element_id) click to toggle source
Alias for: assert_not_exists
assert_not_nil(actual, msg="") click to toggle source
# File lib/rwebspec/assert.rb, line 15
def assert_not_nil(actual, msg="")
  perform_assertion { assert(!actual.nil?, msg) }
end
assert_not_visible(tag, element_id) click to toggle source
Alias for: assert_hidden
assert_option_equals(select_name, option_label) click to toggle source
# 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
assert_option_not_present(select_name, option_label) click to toggle source
# 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
assert_option_present(select_name, option_label) click to toggle source
# 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
assert_option_value_equals(select_name, option_value) click to toggle source
# 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
assert_option_value_not_present(select_name, option_value) click to toggle source

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
assert_option_value_present(select_name, option_value) click to toggle source
# 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
assert_radio_button_checked(radio_group, radio_option) click to toggle source
assert_radio_button_not_checked(radio_group, radio_option) click to toggle source
assert_radio_option_checked(radio_group, radio_option) click to toggle source
assert_radio_option_not_checked(radio_group, radio_option) click to toggle source
assert_radio_option_not_present(radio_group, radio_option) click to toggle source

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
assert_radio_option_not_selected(radio_group, radio_option) click to toggle source
# 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
assert_radio_option_present(radio_group, radio_option) click to toggle source
# 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
assert_radio_option_selected(radio_group, radio_option) click to toggle source
# 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_select_label(select_name, option_label) click to toggle source
assert_select_label_not_present(select_name, option_label) click to toggle source
assert_select_label_present(select_name, option_label) click to toggle source
assert_select_value(select_name, option_value) click to toggle source
assert_select_value_not_present(select_name, option_value) click to toggle source
assert_select_value_present(select_name, option_value) click to toggle source
assert_text_field_value(textfield_name, text) click to toggle source

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
assert_text_in_element(element_id, text) click to toggle source
# 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_in_page_source(text) click to toggle source

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_in_table(table_id, text, options = { :just_plain_text => false }) click to toggle source
assert_text_not_in_page_source(text) click to toggle source

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_in_table(table_id, text, options = { :just_plain_text => false }) click to toggle source
assert_text_not_present(text) click to toggle source

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
assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false }) click to toggle source
# 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
Also aliased as: assert_text_not_in_table
assert_text_present(text) click to toggle source

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_text_present_in_table(table_id, text, options = { :just_plain_text => false }) click to toggle source

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
Also aliased as: assert_text_in_table
assert_title(title) click to toggle source
Alias for: assert_title_equals
assert_title_equals(title) click to toggle source

assertions

# File lib/rwebspec/assert.rb, line 24
def assert_title_equals(title)
  assert_equals(title, @web_browser.page_title)
end
Also aliased as: assert_title
assert_visible(tag, element_id) click to toggle source

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
fail(message) click to toggle source
# File lib/rwebspec/assert.rb, line 19
def fail(message)
  perform_assertion { assert(false, message) }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.