Skip to content

Instantly share code, notes, and snippets.

@jarib
Created December 12, 2008 21:20
Show Gist options
  • Save jarib/35278 to your computer and use it in GitHub Desktop.
Save jarib/35278 to your computer and use it in GitHub Desktop.
Index: commonwatir/unittests/dl_test.rb
===================================================================
--- commonwatir/unittests/dl_test.rb (revision 0)
+++ commonwatir/unittests/dl_test.rb (revision 0)
@@ -0,0 +1,66 @@
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
+require 'unittests/setup'
+
+class TC_Dl < Test::Unit::TestCase
+ include Watir::Exception
+
+ def setup
+ goto_page "definition_lists.html"
+ end
+
+ def test_exists
+ assert browser.dl(:id, "experience-list").exists?, "Could not find <dl> by :id"
+ assert browser.dl(:class, "list").exists?, "Could not find <dl> by :class"
+ assert browser.dl(:xpath, "//dl[@id='experience-list']").exists?, "Could not find <dl> by :xpath"
+ assert browser.dl(:index, 1).exists?, "Could not find <dl> by :index"
+ end
+
+ def test_does_not_exist
+ assert !browser.dl(:id, 'no_such_id').exists?, "Found non-existing <dl>"
+ end
+
+ def test_attribute_class_name
+ assert_equal "list", browser.dl(:id, "experience-list").class_name
+ assert_equal "", browser.dl(:id, 'noop').class_name
+ assert_raises(UnknownObjectException) do
+ browser.dl(:id, 'no_such_id').class_name
+ end
+ end
+
+ def test_attribute_id
+ assert_equal "experience-list", browser.dl(:class, 'list').id
+ assert_equal "", browser.dl(:class, 'personalia').id
+ assert_raises(UnknownObjectException) do
+ browser.dl(:id, 'no_such_id').id
+ end
+ end
+
+ def test_attribute_title
+ assert_equal "experience", browser.dl(:class, 'list').title
+ assert_equal "", browser.dl(:id, 'noop').title
+ assert_raises(UnknownObjectException) do
+ browser.dl(:id, 'no_such_id').title
+ end
+ end
+
+ def test_attribute_text
+ assert_match /11 years/, browser.dl(:id, "experience-list").text
+ assert_equal "", browser.dl(:id, 'noop').text
+ assert_raises(UnknownObjectException) do
+ browser.dl(:id, 'no_such_id').text
+ end
+ end
+
+ def test_dls_iterator
+ assert_equal(3, browser.dls.length)
+ assert_equal("experience-list", browser.dls[1].id)
+
+ browser.dls.each_with_index do |dl, idx|
+ assert_equal(browser.dl(:index,idx+1).text, dl.text)
+ assert_equal(browser.dl(:index,idx+1).id, dl.id)
+ assert_equal(browser.dl(:index,idx+1).class_name , dl.class_name)
+ assert_equal(browser.dl(:index,idx+1).title, dl.title)
+ end
+ end
+
+end
\ No newline at end of file
Index: commonwatir/unittests/html/definition_lists.html
===================================================================
--- commonwatir/unittests/html/definition_lists.html (revision 0)
+++ commonwatir/unittests/html/definition_lists.html (revision 0)
@@ -0,0 +1,48 @@
+<html>
+ <head>
+ <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+ <title>definition_lists</title>
+ </head>
+
+ <body id="definition_list">
+ <dl id="experience-list" class="list" title="experience">
+ <dt id="experience" class="industry" title="experience">Experience</dt>
+ <dd>11 years</dd>
+
+ <dt id="education" onclick="this.innerHTML='changed'">Education</dt>
+ <dd title="education" onclick="this.innerHTML='changed'">Master</dd>
+
+ <dt class="current-industry">Current industry</dt>
+ <dd class="industry">Architecture</dd>
+
+ <dt>Previous industry experience</dt>
+ <dd class="industry">Architecture</dd>
+ </dl>
+
+ <dl class="personalia">
+ <dt id="name" title="name"><div>Name</div></dt>
+ <dd id="someone" class="name" title="someone">John Doe</dd>
+
+ <dt>Address</dt>
+ <dd class="address">John Doe</dd>
+
+ <dt>City</dt>
+ <dd id="city">New York</dd>
+
+ <dt>Country</dt>
+ <dd>USA</dd>
+
+ <dt>Gender</dt>
+ <dd>Male</dd>
+
+ <dt>Age</dt>
+ <dd>35</dd>
+ </dl>
+
+ <dl id="noop" onclick="this.innerHTML = 'noop'">
+ <dt class="noop"></dt> <!-- empty node -->
+ <dd class="noop"></dt> <!-- empty node -->
+ </dl>
+
+ </body>
+</html>
\ No newline at end of file
Index: commonwatir/unittests/dd_test.rb
===================================================================
--- commonwatir/unittests/dd_test.rb (revision 0)
+++ commonwatir/unittests/dd_test.rb (revision 0)
@@ -0,0 +1,66 @@
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
+require 'unittests/setup'
+
+class TC_Dd < Test::Unit::TestCase
+ include Watir::Exception
+
+ def setup
+ goto_page "definition_lists.html"
+ end
+
+ def test_exists
+ assert browser.dd(:id, "someone").exists?, "Could not find <dd> by :id"
+ assert browser.dd(:class, "name").exists?, "Could not find <dd> by :class"
+ assert browser.dd(:xpath, "//dd[@id='someone']").exists?, "Could not find <dd> by :xpath"
+ assert browser.dd(:index, 1).exists?, "Could not find <dd> by :index"
+ end
+
+ def test_does_not_exist
+ assert !browser.dd(:id, 'no_such_id').exists?, "Found non-existing <dd>"
+ 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
+
+ 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
+
+end
\ No newline at end of file
Index: commonwatir/unittests/dt_test.rb
===================================================================
--- commonwatir/unittests/dt_test.rb (revision 0)
+++ commonwatir/unittests/dt_test.rb (revision 0)
@@ -0,0 +1,66 @@
+$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..') unless $SETUP_LOADED
+require 'unittests/setup'
+
+class TC_Dt < Test::Unit::TestCase
+ include Watir::Exception
+
+ def setup
+ goto_page "definition_lists.html"
+ end
+
+ def test_exists
+ assert browser.dt(:id, "experience").exists?, "Could not find <dt> by :id"
+ assert browser.dt(:class, "current-industry").exists?, "Could not find <dt> by :class"
+ assert browser.dt(:xpath, "//dt[@id='experience']").exists?, "Could not find <dt> by :xpath"
+ assert browser.dt(:index, 1).exists?, "Could not find <dt> by :index"
+ end
+
+ def test_does_not_exist
+ assert !browser.dt(:id, 'no_such_id').exists?, "Found non-existing <dt>"
+ end
+
+ def test_attribute_class_name
+ assert_equal "industry", browser.dt(:id, "experience").class_name
+ assert_equal "", browser.dt(:id, 'education').class_name
+ assert_raises(UnknownObjectException) do
+ browser.dt(:id, 'no_such_id').class_name
+ end
+ end
+
+ def test_attribute_id
+ assert_equal "experience", browser.dt(:class, 'industry').id
+ assert_equal "", browser.dt(:class, 'current-industry').id
+ assert_raises(UnknownObjectException) do
+ browser.dt(:id, 'no_such_id').id
+ end
+ end
+
+ def test_attribute_title
+ assert_equal "experience", browser.dt(:id, 'experience').title
+ assert_equal "", browser.dt(:class, 'noop').title
+ assert_raises(UnknownObjectException) do
+ browser.dt(:id, 'no_such_id').title
+ end
+ end
+
+ def test_attribute_text
+ assert_equal "Experience", browser.dt(:id, "experience").text
+ assert_equal "", browser.dt(:class, 'noop').text
+ assert_raises(UnknownObjectException) do
+ browser.dt(:id, 'no_such_id').text
+ end
+ end
+
+ def test_dts_iterator
+ assert_equal(11, browser.dts.length)
+ assert_equal("experience", browser.dts[1].id)
+
+ browser.dts.each_with_index do |dt, idx|
+ assert_equal(browser.dt(:index,idx+1).text, dt.text)
+ assert_equal(browser.dt(:index,idx+1).id, dt.id)
+ assert_equal(browser.dt(:index,idx+1).class_name , dt.class_name)
+ assert_equal(browser.dt(:index,idx+1).title, dt.title)
+ end
+ end
+
+end
\ No newline at end of file
Index: watir/lib/watir/container.rb
===================================================================
--- watir/lib/watir/container.rb (revision 1655)
+++ watir/lib/watir/container.rb (working copy)
@@ -612,6 +612,42 @@
Divs.new(self)
end
+ # this is the main method for accessing the dls iterator. Returns a Dls collection
+ #
+ # Typical usage:
+ #
+ # ie.dls.each { |d| puts d.to_s } # iterate through all the dls on the page
+ # ie.dls[1].to_s # goto the first dl on the page
+ # ie.dls.length # show how many dls are on the page.
+ #
+ def dls
+ Dls.new(self)
+ end
+
+ # this is the main method for accessing the dds iterator. Returns a Dds collection
+ #
+ # Typical usage:
+ #
+ # ie.dds.each { |d| puts d.to_s } # iterate through all the dds on the page
+ # ie.dds[1].to_s # goto the first dd on the page
+ # ie.dds.length # show how many dds are on the page.
+ #
+ def dds
+ Dds.new(self)
+ end
+
+ # this is the main method for accessing the dts iterator. Returns a Dts collection
+ #
+ # Typical usage:
+ #
+ # ie.dts.each { |d| puts d.to_s } # iterate through all the dts on the page
+ # ie.dts[1].to_s # goto the first dt on the page
+ # ie.dts.length # show how many dts are on the page.
+ #
+ def dts
+ Dts.new(self)
+ end
+
# this is the main method for accessing the spans iterator.
#
# Returns a Spans object
Index: watir/lib/watir/non_control_elements.rb
===================================================================
--- watir/lib/watir/non_control_elements.rb (revision 1655)
+++ watir/lib/watir/non_control_elements.rb (working copy)
@@ -124,5 +124,14 @@
class H6 < NonControlElement
TAG = 'H6'
end
+ class Dl < NonControlElement
+ TAG = 'DL'
+ end
+ class Dt < NonControlElement
+ TAG = 'DT'
+ end
+ class Dd < NonControlElement
+ TAG = 'DD'
+ end
end
\ No newline at end of file
Index: watir/lib/watir/collections.rb
===================================================================
--- watir/lib/watir/collections.rb (revision 1655)
+++ watir/lib/watir/collections.rb (working copy)
@@ -309,4 +309,23 @@
end
end
+ class Dls < ElementCollections
+ include CommonCollection
+ def element_class; Dl; end
+ def element_tag; 'DL'; end
+ end
+
+ class Dts < ElementCollections
+ include CommonCollection
+ def element_class; Dt; end
+ def element_tag; 'DT'; end
+ end
+
+ class Dds < ElementCollections
+ include CommonCollection
+ def element_class; Dd; end
+ def element_tag; 'DD'; end
+ end
+
+
end
Index: firewatir/lib/firewatir/htmlelements.rb
===================================================================
--- firewatir/lib/firewatir/htmlelements.rb (revision 1655)
+++ firewatir/lib/firewatir/htmlelements.rb (working copy)
@@ -1870,6 +1870,22 @@
end
class Lis < ElementCollections; end
+ class Dl < NonControlElement
+ TAG = 'DL'
+ end
+ class Dls < ElementCollections; end
+
+ class Dt < NonControlElement
+ TAG = 'DT'
+ end
+ class Dts < ElementCollections; end
+
+ class Dd < NonControlElement
+ TAG = 'DD'
+ end
+ class Dds < ElementCollections; end
+
+
class H1 < NonControlElement
TAG = 'H1'
end
Index: firewatir/lib/firewatir/container.rb
===================================================================
--- firewatir/lib/firewatir/container.rb (revision 1655)
+++ firewatir/lib/firewatir/container.rb (working copy)
@@ -383,9 +383,70 @@
Image.new(self, how, what)
end
+ #
+ # Description:
+ # Used to access a definition list element - a <dl> HTML tag.
+ #
+ # Input:
+ # - how - Attribute used to identify the definition list element.
+ # - what - Value of that attribute.
+ #
+ # Typical Usage:
+ #
+ # ff.dl(:id, 'user_name') # access the dl element with an ID of user_name
+ # ff.dl(:title, 'address') # access the dl element with a title of address
+ #
+ # Returns:
+ # Dl object.
+ #
+ def dl(how, what = nil)
+ locate if defined?(locate)
+ Dl.new(self, how, what)
+ end
+ #
+ # Description:
+ # Used to access a definition term element - a <dt> HTML tag.
+ #
+ # Input:
+ # - how - Attribute used to identify the image element.
+ # - what - Value of that attribute.
+ #
+ # Typical Usage:
+ #
+ # ff.dt(:id, 'user_name') # access the dt element with an ID of user_name
+ # ff.dt(:title, 'address') # access the dt element with a title of address
+ #
+ # Returns:
+ # Dt object.
+ #
+ def dt(how, what = nil)
+ locate if defined?(locate)
+ Dt.new(self, how, what)
+ end
+ #
# Description:
+ # Used to access a definition description element - a <dd> HTML tag.
+ #
+ # Input:
+ # - how - Attribute used to identify the image element.
+ # - what - Value of that attribute.
+ #
+ # Typical Usage:
+ #
+ # ff.dd(:id, 'user_name') # access the dd element with an ID of user_name
+ # ff.dd(:title, 'address') # access the dd element with a title of address
+ #
+ # Returns:
+ # Dd object.
+ #
+ def dd(how, what = nil)
+ locate if defined?(locate)
+ Dd.new(self, how, what)
+ end
+
+ # Description:
# Searching for Page Elements. Not for external consumption.
#
# def ole_inner_elements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment