unittests/form_test.rb in watir-1.5.6 vs unittests/form_test.rb in watir-1.6.2
- old
+ new
@@ -1,60 +1,66 @@
# feature tests for Forms
-# revision: $Revision: 1348 $
+# revision: $Revision: 1513 $
-$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') if $0 == __FILE__
+$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
- goto_page "forms2.html"
+ uses_page "forms2.html"
end
- def test_Form_Exists
- assert($ie.form(:name, "test2").exists?)
- assert(!$ie.form(:name, "missing").exists?)
+ def test_form_exists
+ assert(browser.form(:name, "test2").exists?)
+ assert_false(browser.form(:name, "missing").exists?)
- assert($ie.form("test2").exists?)
- assert(!$ie.form( "missing").exists?)
+ assert(browser.form("test2").exists?)
+ assert_false(browser.form("missing").exists?)
- assert($ie.form(:index, 1).exists?)
- assert(!$ie.form(:index, 88).exists?)
+ assert(browser.form(:index, 1).exists?)
+ assert_false(browser.form(:index, 88).exists?)
- assert($ie.form(:method, "get").exists?)
- assert(!$ie.form(:method, "missing").exists?)
+ assert(browser.form(:method, "get").exists?)
+ assert_false(browser.form(:method, "missing").exists?)
- assert($ie.form(:id, 'f2').exists?)
- assert(!$ie.form(:id, 'missing').exists?)
+ assert(browser.form(:id, 'f2').exists?)
+ assert_false(browser.form(:id, 'missing').exists?)
- assert($ie.form(:action, "pass.html").exists?)
- assert(!$ie.form(:action, "missing").exists?)
+ assert(browser.form(:action, "pass.html").exists?)
+ assert_false(browser.form(:action, "missing").exists?)
end
- def test_ButtonInForm
- assert($ie.form(:name, "test2").button(:caption , "Submit").exists?)
+ def test_button_in_form
+ assert(browser.form(:name, "test2").button(:caption, "Submit").exists?)
end
-
- # The following tests from bug 2261
- def test_form_html
- assert_equal("\r\n<FORM id=f2 name=test2 action=pass2.html method=get><BR><INPUT type=submit value=Submit> </FORM>",
- $ie.form(:name, 'test2').html)
+ def test_form_sub_element
+ assert_equal('Click Me', browser.form(:index, 1).button(:name, 'b1').value)
end
- def test_form_flash
- assert_nothing_raised{ $ie.form(:name, 'test2').flash }
+
+ # The following tests form bug 2261
+ tag_method :test_form_outer_html, :fails_on_firefox
+ def test_form_outer_html
+ expected = "\r\n<FORM id=f2 name=test2 action=pass2.html method=get><BR><INPUT type=submit value=Submit> </FORM>"
+ assert_equal(expected, browser.form(:name, 'test2').html)
end
- def test_form_sub_element
- assert_equal('Click Me', $ie.form(:index, 1).button(:name, 'b1').value)
+ tag_method :test_form_inner_html, :fails_on_ie
+ def test_form_inner_html
+ expected = "\n<br><input value=\"Submit\" type=\"submit\">\n"
+ assert_equal(expected, browser.form(:name, 'test2').html)
end
+ def test_form_flash
+ assert_nothing_raised{ browser.form(:name, 'test2').flash }
+ end
end
require 'unittests/iostring'
class TC_Form_Display < Test::Unit::TestCase
include MockStdoutTestCase
def test_showforms
goto_page "forms2.html"
$stdout = @mockout
- $ie.showForms
+ browser.showForms
assert_equal(<<END_OF_MESSAGE, @mockout)
There are 4 forms
Form name:
id:
method: get
@@ -78,146 +84,133 @@
class TC_Forms3 < Test::Unit::TestCase
def setup
goto_page "forms3.html"
end
- # The following tests from bug 2261
+ # The following tests form bug 2261
def test_p_in_form
- $ie.form(:name, 'buttonsubmit').p(:index, 1).text
+ assert_equal "This form has a submit button that is an image",
+ browser.form(:name, 'buttonsubmit').p(:index, 1).text
end
- def test_Form_Exists
- assert($ie.form(:name, "test2").exists?)
- assert(!$ie.form(:name, "missing").exists?)
-
- assert($ie.form("test2").exists?)
- assert(!$ie.form( "missing").exists?)
-
- assert($ie.form(:index, 1).exists?)
- assert(!$ie.form(:index, 88).exists?)
-
- assert($ie.form(:method, "get").exists?)
- assert(!$ie.form(:method, "missing").exists?)
-
- assert($ie.form(:action, "pass.html").exists?)
- assert(!$ie.form(:action, "missing").exists?)
- end
-
+ # test for bug reported by Scott Pack, http://rubyforge.org/pipermail/wtr-general/2005-June/002223.html
def test_index_other_element_before_it
- # test for bug reported by Scott Pack, http://rubyforge.org/pipermail/wtr-general/2005-June/002223.html
- assert_equal("check1" , $ie.checkbox(:index,1).name )
+ assert_equal("check1" , browser.checkbox(:index,1).name)
end
+ tag_method :test_reset, :fails_on_firefox
def test_reset
- $ie.text_field(:id, "t1").set("Hello, reset test!")
- assert_equal($ie.text_field(:id, 't1').getContents, 'Hello, reset test!')
+ browser.text_field(:id, "t1").set("Hello, reset test!")
+ assert_equal(browser.text_field(:id, 't1').value, 'Hello, reset test!')
- $ie.button(:caption, "Reset").click
- assert_equal("" , $ie.text_field(:id, 't1').getContents )
+ browser.button(:caption, "Reset").click
+ assert_equal("" , browser.text_field(:id, 't1').value)
# also verify it works under a form
- $ie.text_field(:id, "t1").set("reset test - using a form")
- assert_equal($ie.text_field(:id, 't1').getContents, 'reset test - using a form')
+ browser.text_field(:id, "t1").set("reset test - using a form")
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
- $ie.form(:index,2).button(:index,2).click
- assert_equal("" , $ie.text_field(:id, 't1').getContents )
+ browser.form(:index,2).button(:index,2).click
+ assert_equal("" , browser.text_field(:id, 't1').value)
# also verify it works under a form, this time using the :id attribute
- $ie.text_field(:id, "t1").set("reset test - using a form")
- assert_equal($ie.text_field(:id, 't1').getContents, 'reset test - using a form')
+ browser.text_field(:id, "t1").set("reset test - using a form")
+ assert_equal(browser.text_field(:id, 't1').value, 'reset test - using a form')
- $ie.form(:index,2).button(:id,'reset_button').click
- assert_equal("" , $ie.text_field(:id, 't1').getContents )
+ browser.form(:index,2).button(:id,'reset_button').click
+ assert_equal("" , browser.text_field(:id, 't1').value)
end
def test_flash1
- $ie.form(:name ,"test2").button(:caption , "Submit").flash
+ assert_nothing_raised do
+ browser.form(:name, "test2").button(:caption , "Submit").flash
+ end
end
def test_objects_with_same_name
- assert_equal('textfield' ,$ie.text_field( :name , 'g1').value )
- assert_equal('button' ,$ie.button( :name , 'g1').value )
- assert_equal('1' ,$ie.checkbox( :name , 'g1').value )
- assert_equal('2' ,$ie.radio( :name , 'g1').value )
+ assert_equal('textfield' ,browser.text_field( :name, 'g1').value )
+ assert_equal('button' ,browser.button( :name, 'g1').value )
+ assert_equal('1' ,browser.checkbox( :name, 'g1').value )
+ assert_equal('2' ,browser.radio( :name, 'g1').value )
- assert_equal('textfield' ,$ie.text_field( :name , /g1/).value )
- assert_equal('button' ,$ie.button( :name , /g1/).value )
- assert_equal('1' ,$ie.checkbox( :name , /g1/).value )
- assert_equal('2' ,$ie.radio( :name , /g1/).value )
+ assert_equal('textfield' ,browser.text_field( :name, /g1/).value )
+ assert_equal('button' ,browser.button( :name, /g1/).value )
+ assert_equal('1' ,browser.checkbox( :name, /g1/).value )
+ assert_equal('2' ,browser.radio( :name, /g1/).value )
- assert_equal('textfield_id' ,$ie.text_field( :id , 'g1').value )
- assert_equal('button_id' ,$ie.button( :id , 'g1').value )
- assert_equal('1_id' ,$ie.checkbox( :id , 'g1').value )
- assert_equal('2_id' ,$ie.radio( :id , 'g1').value )
+ assert_equal('textfield_id' ,browser.text_field( :id, 'g1').value )
+ assert_equal('button_id' ,browser.button( :id, 'g1').value )
+ assert_equal('1_id' ,browser.checkbox( :id, 'g1').value )
+ assert_equal('2_id' ,browser.radio( :id, 'g1').value )
- assert_equal('textfield_id' ,$ie.text_field( :id , /g1/).value )
- assert_equal('button_id' ,$ie.button( :id , /g1/).value )
- assert_equal('1_id' ,$ie.checkbox( :id , /g1/).value )
- assert_equal('2_id' ,$ie.radio( :id , /g1/).value )
+ assert_equal('textfield_id' ,browser.text_field( :id, /g1/).value )
+ assert_equal('button_id' ,browser.button( :id, /g1/).value )
+ assert_equal('1_id' ,browser.checkbox( :id, /g1/).value )
+ assert_equal('2_id' ,browser.radio( :id, /g1/).value )
end
def test_flash2
- $ie.button(:value, 'Click Me').flash
- assert_raises( Watir::UnknownObjectException ) { $ie.text_field( :name , 'g177').flash }
+ browser.button(:value, 'Click Me').flash
+ assert_raises(UnknownObjectException) { browser.text_field( :name , 'g177').flash }
end
def test_submitWithImage
- assert( $ie.button(:alt , "submit").exists? )
- assert( $ie.button(:alt , /sub/).exists? )
+ assert( browser.button(:alt, "submit").exists? )
+ assert( browser.button(:alt, /sub/).exists? )
- assert(! $ie.button(:alt , "missing").exists? )
- assert(! $ie.button(:alt , /missing/).exists? )
+ assert_false( browser.button(:alt, "missing").exists? )
+ assert_false( browser.button(:alt, /missing/).exists? )
- #assert( $ie.button(:src , "file:///#{$myDir}/html/images/button.jpg").exists? ) # this doesnt work for everybody
- assert( $ie.button(:src , /button/).exists? )
+ #assert( browser.button(:src , "file:///#{$myDir}/html/images/button.jpg").exists? ) # this doesnt work for everybody
+ assert( browser.button(:src, /button/).exists? )
- assert(! $ie.button(:src , "missing").exists? )
- assert(! $ie.button(:src , /missing/).exists? )
- assert_nothing_raised("raised an exception when it shouldnt have") { $ie.button(:src , /button/).click }
+ assert_false( browser.button(:src, "missing").exists? )
+ assert_false( browser.button(:src, /missing/).exists? )
+ assert_nothing_raised("raised an exception when it shouldnt have") { browser.button(:src , /button/).click }
- assert( $ie.text.include?("PASS") )
+ assert( browser.text.include?("PASS") )
end
end
class TC_Forms3_Display < Test::Unit::TestCase
include MockStdoutTestCase # BUG in test: output not verified!
def test_show_stuff
goto_page "forms3.html"
$stdout = @mockout
- $ie.showAllObjects
- puts $ie.getText
- puts $ie.getHTML
+ browser.show_all_objects
+ puts browser.text
+ puts browser.html
end
end
class TC_Forms4 < Test::Unit::TestCase
def setup
- goto_page "forms4.html"
+ uses_page "forms4.html"
end
def test_find_text_field_ignoring_form
- assert_equal($ie.text_field(:name, 'name').getContents, 'apple') # should it raise a not-unique error instead?
+ assert_equal(browser.text_field(:name, 'name').value, 'apple')
end
def test_correct_form_field_is_found_using_form_name
- assert_equal($ie.form(:name, 'apple_form').text_field(:name, 'name').getContents, 'apple')
- assert_equal($ie.form(:name, 'banana_form').text_field(:name, 'name').getContents, 'banana')
+ assert_equal(browser.form(:name, 'apple_form').text_field(:name, 'name').value, 'apple')
+ assert_equal(browser.form(:name, 'banana_form').text_field(:name, 'name').value, 'banana')
end
def test_correct_form_field_is_found_using_form_index
- assert_equal($ie.form(:index, 1).text_field(:name, 'name').getContents, 'apple')
- assert_equal($ie.form(:index, 2).text_field(:name, 'name').getContents, 'banana')
+ assert_equal(browser.form(:index, 1).text_field(:name, 'name').value, 'apple')
+ assert_equal(browser.form(:index, 2).text_field(:name, 'name').value, 'banana')
end
def test_using_text_on_form
- $ie.form(:name, 'apple_form').text_field(:name, 'name').set('strudel')
- assert_equal($ie.form(:index, 1).text_field(:name, 'name').getContents, 'strudel')
+ browser.form(:name, 'apple_form').text_field(:name, 'name').set('strudel')
+ assert_equal(browser.form(:index, 1).text_field(:name, 'name').value, 'strudel')
end
def test_submit
- $ie.form(:name, 'apple_form').submit
- assert( $ie.text.include?("PASS") )
+ browser.form(:name, 'apple_form').submit
+ assert(browser.text.include?("PASS"))
end
end
class TC_Hidden_Fields < Test::Unit::TestCase
def setup
@@ -225,76 +218,76 @@
end
def test_hidden
# test using index
- assert( $ie.hidden(:index,1).exists? )
- assert( $ie.hidden(:index,2).exists? )
- assert(! $ie.hidden(:index,3).exists? )
+ assert( browser.hidden(:index, 1).exists? )
+ assert( browser.hidden(:index, 2).exists? )
+ assert_false( browser.hidden(:index, 3).exists? )
- $ie.hidden(:index,1).value = 44
- $ie.hidden(:index,2).value = 55
+ browser.hidden(:index, 1).value = 44
+ browser.hidden(:index, 2).value = 55
- $ie.button(:value , "Show Hidden").click
+ browser.button(:value, "Show Hidden").click
- assert_equal("44" , $ie.text_field(:name , "vis1").value )
- assert_equal("55" , $ie.text_field(:name , "vis2").value )
+ assert_equal("44", browser.text_field(:name, "vis1").value )
+ assert_equal("55", browser.text_field(:name, "vis2").value )
# test using name and ID
- assert( $ie.hidden(:name ,"hid1").exists? )
- assert( $ie.hidden(:id,"hidden_1").exists? )
- assert(! $ie.hidden(:name,"hidden_44").exists? )
- assert(! $ie.hidden(:id,"hidden_55").exists? )
+ assert( browser.hidden(:name, "hid1").exists? )
+ assert( browser.hidden(:id, "hidden_1").exists? )
+ assert_false( browser.hidden(:name, "hidden_44").exists? )
+ assert_false( browser.hidden(:id, "hidden_55").exists? )
- $ie.hidden(:name ,"hid1").value = 444
- $ie.hidden(:id,"hidden_1").value = 555
+ browser.hidden(:name, "hid1").value = 444
+ browser.hidden(:id, "hidden_1").value = 555
- $ie.button(:value , "Show Hidden").click
+ browser.button(:value, "Show Hidden").click
- assert_equal("444" , $ie.text_field(:name , "vis1").value )
- assert_equal("555" , $ie.text_field(:name ,"vis2").value )
+ assert_equal("444", browser.text_field(:name, "vis1").value)
+ assert_equal("555", browser.text_field(:name, "vis2").value)
- # test the over-ridden append method
- $ie.hidden(:name ,"hid1").append("a")
- $ie.button(:value , "Show Hidden").click
- assert_equal("444a" , $ie.text_field(:name , "vis1").value )
- assert_equal("555" , $ie.text_field(:name ,"vis2").value )
+ # test the over-ridden append method
+ browser.hidden(:name, "hid1").append("a")
+ browser.button(:value, "Show Hidden").click
+ assert_equal("444a", browser.text_field(:name, "vis1").value )
+ assert_equal("555", browser.text_field(:name, "vis2").value )
- # test the over-ridden clear method
- $ie.hidden(:name ,"hid1").clear
- $ie.button(:value , "Show Hidden").click
- assert_equal("" , $ie.text_field(:name , "vis1").value )
- assert_equal("555" , $ie.text_field(:name ,"vis2").value )
+ # test the over-ridden clear method
+ browser.hidden(:name, "hid1").clear
+ browser.button(:value, "Show Hidden").click
+ assert_equal("", browser.text_field(:name, "vis1").value)
+ assert_equal("555", browser.text_field(:name, "vis2").value)
# test using a form
- assert( $ie.form(:name , "has_a_hidden").hidden(:name ,"hid1").exists? )
- assert( $ie.form(:name , "has_a_hidden").hidden(:id,"hidden_1").exists? )
- assert(! $ie.form(:name , "has_a_hidden").hidden(:name,"hidden_44").exists? )
- assert(! $ie.form(:name , "has_a_hidden").hidden(:id,"hidden_55").exists? )
+ assert( browser.form(:name, "has_a_hidden").hidden(:name, "hid1").exists? )
+ assert( browser.form(:name, "has_a_hidden").hidden(:id, "hidden_1").exists? )
+ assert_false( browser.form(:name, "has_a_hidden").hidden(:name, "hidden_44").exists? )
+ assert_false( browser.form(:name, "has_a_hidden").hidden(:id, "hidden_55").exists? )
- $ie.form(:name , "has_a_hidden").hidden(:name ,"hid1").value = 222
- $ie.form(:name , "has_a_hidden").hidden(:id,"hidden_1").value = 333
+ browser.form(:name, "has_a_hidden").hidden(:name, "hid1").value = 222
+ browser.form(:name, "has_a_hidden").hidden(:id, "hidden_1").value = 333
- $ie.button(:value , "Show Hidden").click
+ browser.button(:value, "Show Hidden").click
- assert_equal("222" , $ie.text_field(:name , "vis1").value )
- assert_equal("333" , $ie.text_field(:name ,"vis2").value )
+ assert_equal("222", browser.text_field(:name, "vis1").value)
+ assert_equal("333", browser.text_field(:name, "vis2").value)
# iterators
- assert_equal(2, $ie.hiddens.length)
- count =1
- $ie.hiddens.each do |h|
+ assert_equal(2, browser.hiddens.length)
+ count = 1
+ browser.hiddens.each do |h|
case count
when 1
- assert_equal( "", h.id)
- assert_equal( "hid1", h.name)
+ assert_equal("", h.id)
+ assert_equal("hid1", h.name)
when 2
- assert_equal( "", h.name)
- assert_equal( "hidden_1", h.id)
+ assert_equal("", h.name)
+ assert_equal("hidden_1", h.id)
end
- count+=1
+ count += 1
end
- assert_equal("hid1" , $ie.hiddens[1].name )
- assert_equal("hidden_1" , $ie.hiddens[2].id )
+ assert_equal("hid1", browser.hiddens[1].name)
+ assert_equal("hidden_1", browser.hiddens[2].id)
end
end
\ No newline at end of file