$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
require 'unittests/setup'
class TC_Dd < Test::Unit::TestCase
include Watir::Exception
location __FILE__
def setup
uses_page "definition_lists.html"
end
def test_exists
assert browser.dd(:id, "someone").exists?, "Could not find
by :id"
assert browser.dd(:class, "name").exists?, "Could not find by :class"
assert_nothing_raised do
browser.dd(:xpath, "//dd[@id='someone']").locate
end
assert browser.dd(:xpath, "//dd[@id='someone']").exists?, "Could not find by :xpath"
assert browser.dd(:index, 1).exists?, "Could not find by :index"
end
def test_does_not_exist
assert !browser.dd(:id, 'no_such_id').exists?, "Found non-existing "
end
def test_attribute_class_name
assert_equal "name", browser.dd(:id, "someone").class_name
assert_equal "", browser.dd(:id, 'city').class_name
assert_raises(UnknownObjectException) do
browser.dd(:id, 'no_such_id').class_name
end
end
def test_attribute_id
assert_equal "someone", browser.dd(:class, 'name').id
assert_equal "", browser.dd(:class, 'address').id
assert_raises(UnknownObjectException) do
browser.dd(:id, 'no_such_id').id
end
end
def test_attribute_title
assert_equal "someone", browser.dd(:class, 'name').title
assert_equal "", browser.dd(:class, 'noop').title
assert_raises(UnknownObjectException) do
browser.dd(:id, 'no_such_id').title
end
end
def test_attribute_text
assert_equal "John Doe", browser.dd(:id, "someone").text
assert_equal "", browser.dd(:class, 'noop').text
assert_raises(UnknownObjectException) do
browser.dd(:id, 'no_such_id').text
end
end
tag_method :test_dd_iterator, :fails_on_ie
def test_dd_iterator
assert_equal(11, browser.dds.length)
assert_equal("education", browser.dds[2].title)
browser.dds.each_with_index do |dd, idx|
assert_equal(browser.dd(:index,idx+1).text, dd.text)
assert_equal(browser.dd(:index,idx+1).id, dd.id)
assert_equal(browser.dd(:index,idx+1).class_name , dd.class_name)
assert_equal(browser.dd(:index,idx+1).title, dd.title)
end
end
tag_method :test_dd_iterator_ie, :fails_on_firefox
def test_dd_iterator_ie
assert_equal(11, browser.dds.length)
assert_equal("education", browser.dds[1].title)
browser.dds.each_with_index do |dd, idx|
assert_equal(browser.dd(:index,idx).text, dd.text)
assert_equal(browser.dd(:index,idx).id, dd.id)
assert_equal(browser.dd(:index,idx).class_name , dd.class_name)
assert_equal(browser.dd(:index,idx).title, dd.title)
end
end
end