Sha256: 62b81a2301d6122835aa11a7737725778a10b42cddbb63e74bbad66ccfd3d49b

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

require_relative '../unit_helper'

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

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

  describe '#build' do
    it 'without only tag name' do
      selector = {tag_name: 'a'}
      built = {xpath: ".//*[local-name()='a']"}

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

    it 'converts visible_text String to link_text' do
      selector = {tag_name: 'a', visible_text: 'Foo'}
      built = {link_text: 'Foo'}

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

    it 'converts visible_text Regexp to partial_link_text' do
      selector = {tag_name: 'a', visible_text: /Foo/}
      built = {partial_link_text: 'Foo'}

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

    it 'does not convert visible_text with casefold Regexp to partial_link_text' do
      selector = {tag_name: 'a', visible_text: /partial text/i}
      built = {xpath: ".//*[local-name()='a']", visible_text: /partial text/i}

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

    it 'does not convert :visible_text with String and other locators' do
      selector = {tag_name: 'a', visible_text: 'Foo', id: 'Foo'}
      built = {xpath: ".//*[local-name()='a'][@id='Foo']", visible_text: 'Foo'}

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

    it 'does not convert :visible_text with Regexp and other locators' do
      selector = {tag_name: 'a', visible_text: /Foo/, id: 'Foo'}
      built = {xpath: ".//*[local-name()='a'][@id='Foo']", visible_text: /Foo/}

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

Version data entries

17 entries across 17 versions & 1 rubygems

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