# feature tests for Forms $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED require 'unittests/setup' class TC_Forms2 < Test::Unit::TestCase # Note: there is no TC_Forms1 def setup uses_page "forms2.html" end def test_form_exists assert(browser.form(:name, "test2").exists?) assert_false(browser.form(:name, "missing").exists?) assert(browser.form("test2").exists?) assert_false(browser.form("missing").exists?) assert(browser.form(:index, 1).exists?) assert_false(browser.form(:index, 88).exists?) assert(browser.form(:method, "get").exists?) assert_false(browser.form(:method, "missing").exists?) assert(browser.form(:id, 'f2').exists?) assert_false(browser.form(:id, 'missing').exists?) assert(browser.form(:action, /pass.html/).exists?) assert_false(browser.form(:action, "missing").exists?) end def test_multiple_attribute assert_true(browser.form(:name => 'test2', :id => 'f2').exists?) assert_true(browser.form(:name => 'test2', :method => 'get', :action => 'pass2.html')) end def test_button_in_form assert(browser.form(:name, "test2").button(:caption, "Submit").exists?) end def test_form_sub_element assert_equal('Click Me', browser.form(:index, 1).button(:name, 'b1').value) end # The following tests form bug 2261 tag_method :test_form_outer_html, :fails_on_firefox def test_form_outer_html expected = "\r\n

" actual = browser.form(:name, 'test2').html actual.sub!('style=""','') # ie9 adds in a style tag so just strip it out #ie9 also has som additional formatting so remove that too actual.gsub!('"','') actual.gsub!(/\n/,'') # ignore attributes order by sorting them sorted_expected, sorted_actual = [expected, actual].map! do |html| html.strip.downcase.scan(%r{

<(.*)>\s*
}).flatten. map {|part| part.split(" ").sort.join(" ")}.join(">
<") end assert_not_equal("", sorted_expected) assert_not_equal("", sorted_actual) assert_equal(sorted_expected, sorted_actual) end tag_method :test_form_inner_html, :fails_on_ie def test_form_inner_html expected = "\n
\n" assert_equal(expected, browser.form(:name, 'test2').html) end def test_form_flash assert_nothing_raised{ browser.form(:name, 'test2').flash } end end class TC_Forms_Collection < Test::Unit::TestCase def setup goto_page "forms2.html" end def test_forms_collection forms = browser.forms assert_equal(4, forms.length) assert(forms.first.action =~ /pass.html$/) assert_equal('test2', forms.last.name) end end class TC_Form_Display < Test::Unit::TestCase include CaptureIOHelper def test_showforms goto_page "forms2.html" actual = capture_stdout { browser.showForms } expected = <