Permalink
Browse files

None of the HTML expressions take arguments any more

  • Loading branch information...
1 parent 422ff06 commit b6074b3fb0acdf064b888d62b1a7c8530a1f0515 @jnicklas jnicklas committed Jan 2, 2012
Showing with 11 additions and 70 deletions.
  1. +11 −45 lib/xpath/html.rb
  2. +0 −25 spec/html_spec.rb
View
@@ -7,12 +7,9 @@ module HTML
#
# @param [String] locator
# Text, id, title, or image alt attribute of the link
- # @option options [String] :href
- # `href` attribute of the link
#
- def link(locator, options={})
- href = options[:href]
- link = descendant(:a)[href ? attr(:href).equals(href) : attr(:href)]
+ def link(locator)
+ link = descendant(:a)[attr(:href)]
link[attr(:id).equals(locator) | string.n.is(locator) | attr(:title).is(locator) | descendant(:img)[attr(:alt).is(locator)]]
end
@@ -59,20 +56,10 @@ def fieldset(locator)
#
# @param [String] locator
# Label, id, or name of field to match
- # @option options [Bool] :checked
- # Match only if the input has a `checked` attribute
- # @option options [Bool] :unchecked
- # Match only if the input does not have a `checked` attribute
- # @option options [String] :with
- # Text that matches only elements with this value
- # (`value` attribute or contained text)
- #
- def field(locator, options={})
+ #
+ def field(locator)
xpath = descendant(:input, :textarea, :select)[~attr(:type).one_of('submit', 'image', 'hidden')]
xpath = locate_field(xpath, locator)
- xpath = xpath[attr(:checked)] if options[:checked]
- xpath = xpath[~attr(:checked)] if options[:unchecked]
- xpath = xpath[field_value(options[:with])] if options.has_key?(:with)
xpath
end
@@ -83,14 +70,10 @@ def field(locator, options={})
#
# @param [String] locator
# Label, id, or name of field to match
- # @option options [String] :with
- # Text that matches only elements with this value
- # (`value` attribute or contained text)
#
- def fillable_field(locator, options={})
+ def fillable_field(locator)
xpath = descendant(:input, :textarea)[~attr(:type).one_of('submit', 'image', 'radio', 'checkbox', 'hidden', 'file')]
xpath = locate_field(xpath, locator)
- xpath = xpath[field_value(options[:with])] if options.has_key?(:with)
xpath
end
@@ -99,21 +82,9 @@ def fillable_field(locator, options={})
#
# @param [String] locator
# Label, id, or name of the field to match
- # @option options [Array] :options
- # @option options [Array] :selected
#
- def select(locator, options={})
- xpath = locate_field(descendant(:select), locator)
-
- options[:options].each do |option|
- xpath = xpath[descendant(:option).equals(option)]
- end if options[:options]
-
- [options[:selected]].flatten.each do |option|
- xpath = xpath[descendant(:option)[attr(:selected)].equals(option)]
- end if options[:selected]
-
- xpath
+ def select(locator)
+ locate_field(descendant(:select), locator)
end
@@ -122,7 +93,7 @@ def select(locator, options={})
# @param [String] locator
# Label, id, or name of the checkbox to match
#
- def checkbox(locator, options={})
+ def checkbox(locator)
xpath = locate_field(descendant(:input)[attr(:type).equals('checkbox')], locator)
end
@@ -132,7 +103,7 @@ def checkbox(locator, options={})
# @param [String] locator
# Label, id, or name of the radio button to match
#
- def radio_button(locator, options={})
+ def radio_button(locator)
locate_field(descendant(:input)[attr(:type).equals('radio')], locator)
end
@@ -142,7 +113,7 @@ def radio_button(locator, options={})
# @param [String] locator
# Label, id, or name of the file field to match
#
- def file_field(locator, options={})
+ def file_field(locator)
locate_field(descendant(:input)[attr(:type).equals('file')], locator)
end
@@ -174,7 +145,7 @@ def option(name)
# @option options [Array] :rows
# Content of each cell in each row to match
#
- def table(locator, options={})
+ def table(locator)
descendant(:table)[attr(:id).equals(locator) | descendant(:caption).contains(locator)]
end
@@ -184,10 +155,5 @@ def locate_field(xpath, locator)
locate_field = xpath[attr(:id).equals(locator) | attr(:name).equals(locator) | attr(:placeholder).equals(locator) | attr(:id).equals(anywhere(:label)[string.n.is(locator)].attr(:for))]
locate_field += descendant(:label)[string.n.is(locator)].descendant(xpath)
end
-
- def field_value(value)
- (string.n.is(value) & tag(:textarea)) | (attr(:value).equals(value) & ~tag(:textarea))
- end
-
end
end
View
@@ -33,8 +33,6 @@ def all(*args)
it("finds links by image's approximate alt attribute") { get('Alt').should == 'link-img' }
it("prefers exact matches of image's alt attribute") { all('An image').should == ['link-img-exact', 'link-img-fuzzy'] }
it("does not find links without href attriutes") { get('Wrong Link').should be_nil }
- it("finds links with an href") { get("Href-ed link", :href => 'http://www.example.com').should == 'link-href' }
- it("does not find links with an incorrect href") { get("Href-ed link", :href => 'http://www.somewhere.com').should be_nil }
end
describe '#button' do
@@ -162,28 +160,6 @@ def all(*args)
it("does not find image buttons") { get('Input image with parent label').should be_nil }
it("does not find hidden fields") { get('Input hidden with parent label').should be_nil }
end
-
- context "with :with option" do
- it("finds inputs that match option") { get('input-with-id', :with => 'correct-value').should == 'input-with-id-data' }
- it("omits inputs that don't match option") { get('input-with-id', :with => 'wrong-value').should be_nil }
- it("finds textareas that match option") { get('textarea-with-id', :with => 'Correct value').should == 'textarea-with-id-data' }
- it("omits textareas that don't match option") { get('textarea-with-id', :with => 'Wrong value').should be_nil }
- end
-
- context "with :checked option" do
- context "when true" do
- it("finds checked fields") {}
- it("omits unchecked fields") {}
- end
- context "when false" do
- it("finds unchecked fields") {}
- it("omits checked fields") {}
- end
- context "when ommitted" do
- it("finds unchecked fields") {}
- it("finds checked fields") {}
- end
- end
end
describe '#fillable_field' do
@@ -242,7 +218,6 @@ def all(*args)
subject {:table}
it("finds tables by id") { get('table-with-id').should == 'table-with-id-data' }
it("finds tables by caption") { get('Table with caption').should == 'table-with-caption-data' }
- it("finds cell content regardless of whitespace") { get('whitespaced-table', :rows => [["I have nested whitespace", "I don't"]]).should == 'table-with-whitespace' }
end
end

0 comments on commit b6074b3

Please sign in to comment.