Included Modules

RWebSpec::Assert

Public Instance Methods

assert_button_not_present(button_id) click to toggle source

Button

     # File lib/rwebspec/assert.rb, line 209
209:     def assert_button_not_present(button_id)
210:       @web_browser.buttons.each { |button|
211:         assert(button.id != button_id, "unexpected button id: #{button_id} found")
212:       }
213:     end
assert_button_not_present_with_text(text) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 215
215:     def assert_button_not_present_with_text(text)
216:       @web_browser.buttons.each { |button|
217:         assert(button.value != text, "unexpected button id: #{text} found")
218:       }
219:     end
assert_button_present(button_id) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 221
221:     def assert_button_present(button_id)
222:       @web_browser.buttons.each { |button|
223:         return if button_id == button.id
224:       }
225:       assert(false, "can't find the button with id: #{button_id}")
226:     end
assert_button_present_with_text(button_text) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 228
228:     def assert_button_present_with_text(button_text)
229:       @web_browser.buttons.each { |button|
230:         return if button_text == button.value
231:       }
232:       assert(false, "can't find the button with text: #{button_text}")
233:     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 86
86:     def assert_checkbox_not_selected(checkbox_name)
87:       @web_browser.checkboxes.each { |checkbox|
88:         if (checkbox.name == checkbox_name) then
89:           assert(!checkbox.isSet?, "Checkbox #{checkbox_name} is checked unexpectly")
90:         end
91:       }
92:     end
Also aliased as: assert_checkbox_not_checked
assert_checkbox_selected(checkbox_name) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 95
 95:     def assert_checkbox_selected(checkbox_name)
 96:       @web_browser.checkboxes.each { |checkbox|
 97:         if (checkbox.name == checkbox_name) then
 98:           assert(checkbox.isSet?, "Checkbox #{checkbox_name} not checked")
 99:         end
100:       }
101:     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

(Not documented)

     # File lib/rwebspec/assert.rb, line 236
236:     def assert_equals(expected, actual, msg=nil)
237:       assert(expected == actual, (msg.nil?) ? "Expected: #{expected} diff from actual: #{actual}" : msg)
238:     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 246
246:     def assert_exists(tag, element_id) {}
247:       begin
248:         assert eval("#{tag}(:id, '#{element_id.to_s}').exists?")
249:       rescue => e
250:         raise "Element '#{tag}' with id: '#{element_id}' not found, #{e}"
251:       end
252:     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 281
281:     def assert_hidden(tag, element_id)
282:       begin
283:         assert(!eval("#{tag}(:id, '#{element_id.to_s}').visible?"))
284:       rescue => e
285:         raise "Element '#{tag}' with id: '#{element_id}' is visible, #{e}"
286:       end
287:     end
Also aliased as: assert_not_visible
assert_nil(actual, msg="") click to toggle source

(Not documented)

    # File lib/rwebspec/assert.rb, line 12
12:     def assert_nil(actual, msg="")
13:       assert(actual.nil?, msg)
14:     end
assert_not(condition, msg = "") click to toggle source

(Not documented)

    # File lib/rwebspec/assert.rb, line 8
 8:     def assert_not(condition, msg = "")
 9:       assert(!condition, msg)
10:     end
assert_not_exists(tag, element_id) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 256
256:     def assert_not_exists(tag, element_id) {}
257:       begin
258:         assert_not eval("#{tag}(:id, '#{element_id.to_s}').exists?")
259:         raise "Unexpected element'#{tag}' + with id: '#{element_id}' found"
260:       rescue => e
261:       end
262:     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

(Not documented)

    # File lib/rwebspec/assert.rb, line 16
16:     def assert_not_nil(actual, msg="")
17:       assert(!actual.nil?, msg)
18:     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

(Not documented)

     # File lib/rwebspec/assert.rb, line 148
148:     def assert_option_equals(select_name, option_label)
149:       @web_browser.select_lists.each { |select|
150:         next unless select.name == select_name
151:         select.o.each do |option| # items in the list
152:           if (option.text == option_label) then
153:             assert_equal(select.value, option.value, "Select #{select_name}'s value is not equal to expected option label: '#{option_label}'")
154:           end
155:         end
156:       }
157:     end
Also aliased as: assert_select_label
assert_option_not_present(select_name, option_label) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 116
116:     def assert_option_not_present(select_name, option_label)
117:       @web_browser.select_lists.each { |select|
118:         next unless select.name == select_name
119:         select.o.each do |option| # items in the list
120:           assert(!(option.text == option_label), "unexpected select option: #{option_label} for #{select_name} found")
121:         end
122:       }
123:     end
assert_option_present(select_name, option_label) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 137
137:     def assert_option_present(select_name, option_label)
138:       @web_browser.select_lists.each { |select|
139:         next unless select.name == select_name
140:         select.o.each do |option| # items in the list
141:           return if option.text == option_label
142:         end
143:       }
144:       assert(false, "can't find the combob box: #{select_name} with value: #{option_label}")
145:     end
Also aliased as: assert_select_label_present
assert_option_value_equals(select_name, option_value) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 160
160:     def assert_option_value_equals(select_name, option_value)
161:       @web_browser.select_lists.each { |select|
162:         next unless select.name == select_name
163:         assert_equal(select.value, option_value, "Select #{select_name}'s value is not equal to expected: '#{option_value}'")
164:       }
165:     end
Also aliased as: assert_select_value
assert_option_value_not_present(select_name, option_value) click to toggle source

select

     # File lib/rwebspec/assert.rb, line 106
106:     def assert_option_value_not_present(select_name, option_value)
107:       @web_browser.select_lists.each { |select|
108:         continue unless select.name == select_name
109:         select.o.each do |option| # items in the list
110:           assert(!(option.value == option_value), "unexpected select option: #{option_value} for #{select_name} found")
111:         end
112:       }
113:     end
assert_option_value_present(select_name, option_value) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 126
126:     def assert_option_value_present(select_name, option_value)
127:       @web_browser.select_lists.each { |select|
128:         next unless select.name == select_name
129:         select.o.each do |option| # items in the list
130:           return if option.value == option_value
131:         end
132:       }
133:       assert(false, "can't find the combob box with value: #{option_value}")
134:     end
Also aliased as: assert_select_value_present
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 172
172:     def assert_radio_option_not_present(radio_group, radio_option)
173:       @web_browser.radios.each { |radio|
174:         if (radio.name == radio_group) then
175:           assert(!(radio_option == radio.value), "unexpected radio option: " + radio_option  + " found")
176:         end
177:       }
178:     end
assert_radio_option_not_selected(radio_group, radio_option) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 197
197:     def assert_radio_option_not_selected(radio_group, radio_option)
198:       @web_browser.radios.each { |radio|
199:         if (radio.name == radio_group and radio_option == radio.value) then
200:           assert(!radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] checked unexpected")
201:         end
202:       }
203:     end
assert_radio_option_present(radio_group, radio_option) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 180
180:     def assert_radio_option_present(radio_group, radio_option)
181:       @web_browser.radios.each { |radio|
182:         return if (radio.name == radio_group) and (radio_option == radio.value)
183:       }
184:       fail("can't find the radio option : '#{radio_option}'")
185:     end
assert_radio_option_selected(radio_group, radio_option) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 187
187:     def assert_radio_option_selected(radio_group, radio_option)
188:       @web_browser.radios.each { |radio|
189:         if (radio.name == radio_group and radio_option == radio.value) then
190:           assert(radio.isSet?, "Radio button #{radio_group}-[#{radio_option}] not checked")
191:         end
192:       }
193:     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

assert_text_field_value(“text1”, “text already there”) => true

     # File lib/rwebspec/assert.rb, line 330
330:     def assert_text_field_value(textfield_name, text)
331:       assert_equal(text, text_field(:name, textfield_name).value)
332:     end
assert_text_in_element(element_id, text) click to toggle source

— Not tested

 -----
     # File lib/rwebspec/assert.rb, line 338
338:     def assert_text_in_element(element_id, text)
339:       elem = element_by_id(element_id)
340:       assert_not_nil(elem.innerText, "element #{element_id} has no text")
341:       assert(elem.innerText.include?(text), "the text #{text} not found in element #{element_id}")
342:     end
assert_text_in_table(table_id, text, options = { :just_plain_text => false }) click to toggle source
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("<h1>iTest2</h1>")
    # File lib/rwebspec/assert.rb, line 38
38:     def assert_text_not_present(text)
39:       assert(!(@web_browser.page_source.include? text), 'expected text: ' + text + ' found')
40:     end
assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false }) click to toggle source

(Not documented)

     # File lib/rwebspec/assert.rb, line 319
319:     def assert_text_not_present_in_table(table_id, text, options = { :just_plain_text => false })
320:       assert_not(table_source(table_id, options).include?(text),  "the text #{text} not found in table #{table_id}")
321:     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("<h1>iTest2</h1>")
    # File lib/rwebspec/assert.rb, line 32
32:     def assert_text_present(text)
33:       assert((@web_browser.page_source.include? text), 'expected text: ' + text + ' not found')
34:     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

tag like below)

  <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>

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 314
314:     def assert_text_present_in_table(table_id, text, options = { :just_plain_text => false })
315:       assert(table_source(table_id, options).include?(text),  "the text #{text} not found in table #{table_id}")
316:     end
Also aliased as: assert_text_in_table
assert_title(title) click to toggle source
assert_title_equals(title) click to toggle source

assertions

    # File lib/rwebspec/assert.rb, line 25
25:     def assert_title_equals(title)
26:       assert_equals(title, @web_browser.page_title)
27:     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 270
270:     def assert_visible(tag, element_id)
271:       begin
272:         assert(eval("#{tag}(:id, '#{element_id.to_s}').visible?"))
273:       rescue => e
274:         raise "Element '#{tag}' with id: '#{element_id}' not visible, #{e}"
275:       end
276:     end
fail(message) click to toggle source

(Not documented)

    # File lib/rwebspec/assert.rb, line 20
20:     def fail(message)
21:       assert(false, message)
22:     end

Private Instance Methods

table_source(table_id, options) click to toggle source

TODO for drag-n-drop, check the postion in list

    def assert_position_in_list(list_element_id)
      raise "not implemented"
    end
     # File lib/rwebspec/assert.rb, line 353
353:     def table_source(table_id, options)
354:           elem_table = table(:id, table_id.to_s)
355:       elem_table_text = elem_table.text 
356:       elem_table_html = is_firefox? ? elem_table.innerHTML : elem_table.html
357:       table_source = options[:just_plain_text] ? elem_table_text : elem_table_html
358:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.