Sha256: e5b6f03c732bbb3f5a3980a9ad53e7eb898ce29b51379216ccbf5db5a618185f

Contents?: true

Size: 1.86 KB

Versions: 17

Compression:

Stored size: 1.86 KB

Contents

require_relative '../unit_helper'

describe Watir::Locators::Cell::SelectorBuilder do
  include LocatorSpecHelper

  let(:selector_builder) { described_class.new(attributes, query_scope) }

  describe '#build' do
    it 'without any arguments' do
      selector = {}
      built = {xpath: "./*[local-name()='th' or local-name()='td']"}

      expect(selector_builder.build(selector)).to eq built
    end

    context 'with index' do
      it 'positive' do
        selector = {index: 3}
        built = {xpath: "(./*[local-name()='th' or local-name()='td'])[4]"}

        expect(selector_builder.build(selector)).to eq built
      end

      it 'negative' do
        selector = {index: -3}
        built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()-2]"}

        expect(selector_builder.build(selector)).to eq built
      end

      it 'last' do
        selector = {index: -1}
        built = {xpath: "(./*[local-name()='th' or local-name()='td'])[last()]"}

        expect(selector_builder.build(selector)).to eq built
      end

      it 'does not return index if it is zero' do
        selector = {index: 0}
        built = {xpath: "./*[local-name()='th' or local-name()='td']"}

        expect(selector_builder.build(selector)).to eq built
      end

      it 'raises exception when index is not an Integer' do
        selector = {index: 'foo'}
        msg = /expected one of \[(Integer|Fixnum)\], got "foo":String/

        expect { selector_builder.build(selector) }.to raise_exception TypeError, msg
      end
    end

    context 'with multiple locators' do
      it 'attribute and text' do
        selector = {headers: /before_tax/, text: '5 934'}
        built = {xpath: "./*[local-name()='th' or local-name()='td']" \
"[normalize-space()='5 934'][contains(@headers, 'before_tax')]"}

        expect(selector_builder.build(selector)).to eq built
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
watir-7.1.0 spec/unit/selector_builder/cell_spec.rb
watir-7.0.0 spec/unit/selector_builder/cell_spec.rb
watir-7.0.0.beta5 spec/unit/selector_builder/cell_spec.rb
watir-7.0.0.beta4 spec/unit/selector_builder/cell_spec.rb
watir-7.0.0.beta3 spec/unit/selector_builder/cell_spec.rb
watir-7.0.0.beta2 spec/unit/selector_builder/cell_spec.rb
watir-7.0.0.beta1 spec/unit/selector_builder/cell_spec.rb
watir-6.19.1 spec/unit/selector_builder/cell_spec.rb
watir-6.19.0 spec/unit/selector_builder/cell_spec.rb
watir-6.18.0 spec/unit/selector_builder/cell_spec.rb
watir-6.17.0 spec/unit/selector_builder/cell_spec.rb
watir-6.16.5 spec/unit/selector_builder/cell_spec.rb
watir-6.16.4 spec/unit/selector_builder/cell_spec.rb
watir-6.16.3 spec/unit/selector_builder/cell_spec.rb
watir-6.16.2 spec/unit/selector_builder/cell_spec.rb
watir-6.16.1 spec/unit/selector_builder/cell_spec.rb
watir-6.16.0 spec/unit/selector_builder/cell_spec.rb