From b6074b3fb0acdf064b888d62b1a7c8530a1f0515 Mon Sep 17 00:00:00 2001 From: Jonas Nicklas Date: Mon, 2 Jan 2012 13:00:52 +0100 Subject: [PATCH] None of the HTML expressions take arguments any more --- lib/xpath/html.rb | 56 ++++++++++------------------------------------- spec/html_spec.rb | 25 --------------------- 2 files changed, 11 insertions(+), 70 deletions(-) diff --git a/lib/xpath/html.rb b/lib/xpath/html.rb index cdfdeca..04e7d13 100644 --- a/lib/xpath/html.rb +++ b/lib/xpath/html.rb @@ -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 diff --git a/spec/html_spec.rb b/spec/html_spec.rb index be7aff6..05e7496 100644 --- a/spec/html_spec.rb +++ b/spec/html_spec.rb @@ -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