spec/unit/selector_builder/element_spec.rb in watir-6.16.5 vs spec/unit/selector_builder/element_spec.rb in watir-6.17.0

- old
+ new

@@ -49,11 +49,11 @@ expect { selector_builder.build(selector) }.to raise_exception Watir::Exception::LocatorException, msg end it 'raises exception when not a String' do selector = {xpath: 7} - msg = /expected one of \[String\], got 7:(Fixnum|Integer)/ + msg = /expected one of \[String\], got 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end end @@ -79,11 +79,11 @@ expect(selector_builder.build(selector)).to eq built end it 'raises exception when not a String or Regexp' do selector = {tag_name: 7} - msg = /expected one of \[String, Regexp, Symbol\], got 7:(Fixnum|Integer)/ + msg = /expected one of \[String, Regexp, Symbol\], got 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end end @@ -184,18 +184,18 @@ expect(selector_builder.build(selector)).to eq built end it 'raises exception when not a String or Regexp or Array' do selector = {class: 7} - msg = /expected one of \[String, Regexp, TrueClass, FalseClass\], got 7:(Fixnum|Integer)/ + msg = /expected one of \[String, Regexp, TrueClass, FalseClass\], got 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end it 'raises exception when Array values are not a String or Regexp' do selector = {class: [7]} - msg = /expected one of \[String, Regexp, TrueClass, FalseClass\], got 7:(Fixnum|Integer)/ + msg = /expected one of \[String, Regexp, TrueClass, FalseClass\], got 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end end @@ -242,18 +242,18 @@ expect(selector_builder.build(selector)).to eq built end it 'raises exception when attribute value is not a Boolean, String or Regexp' do selector = {foo: 7} - msg = /expected one of \[String, Regexp, TrueClass, FalseClass\], got 7:(Fixnum|Integer)/ + msg = /expected one of \[String, Regexp, TrueClass, FalseClass\], got 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end it 'raises exception when attribute key is not a String or Regexp' do selector = {7 => 'foo'} - msg = /Unable to build XPath using 7:(Fixnum|Integer)/ + msg = /Unable to build XPath using 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception Watir::Exception::LocatorException, msg end end @@ -290,11 +290,11 @@ }.to have_deprecated_caption end it 'raises exception when text is not a String or Regexp' do selector = {text: 7} - msg = /expected one of \[String, Regexp\], got 7:(Fixnum|Integer)/ + msg = /expected one of \[String, Regexp\], got 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end end @@ -572,11 +572,14 @@ it 'handles case insensitive' do selector = {action: /ME/i} built = {xpath: './/*[contains(translate(@action,' \ "'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'," \ -"'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ'), 'me')]"} +"'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ'), " \ +"translate('me'," \ +"'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'," \ +"'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ'))]"} expect(selector_builder.build(selector)).to eq built end end @@ -660,11 +663,11 @@ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end it 'raises exception when visible text is not a String or Regexp' do selector = {visible_text: 7} - msg = /expected one of \[String, Regexp\], got 7:(Fixnum|Integer)/ + msg = /expected one of \[String, Regexp\], got 7:Integer/ expect { selector_builder.build(selector) }.to raise_exception TypeError, msg end end @@ -758,9 +761,55 @@ built = {xpath: ".//*[local-name()='div']"} build_selector = selector_builder.build(selector) expect(build_selector.delete(:scope)).to_not be_nil expect(build_selector).to eq built + end + end + + context 'with case-insensitive attributes' do + it 'respects case when locating uknown element with uknown attribute' do + expect(selector_builder.build(hreflang: 'en')).to eq(xpath: ".//*[@hreflang='en']") + expect(selector_builder.build(hreflang: /en/)).to eq(xpath: ".//*[contains(@hreflang, 'en')]") + end + + it 'ignores case when locating uknown element with defined attribute' do + lhs = 'translate(@lang,' \ + "'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'," \ + "'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ')" + rhs = "translate('en'," \ + "'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'," \ + "'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ')" + expect(selector_builder.build(lang: 'en')).to eq(xpath: ".//*[#{lhs}=#{rhs}]") + expect(selector_builder.build(lang: /en/)).to eq(xpath: ".//*[contains(#{lhs}, #{rhs})]") + expect(selector_builder.build(tag_name: /a/, lang: 'en')) + .to eq(xpath: ".//*[contains(local-name(), 'a')][#{lhs}=#{rhs}]") + expect(selector_builder.build(tag_name: /a/, lang: /en/)) + .to eq(xpath: ".//*[contains(local-name(), 'a')][contains(#{lhs}, #{rhs})]") + end + + it 'ignores case when attribute is defined for element' do + lhs = 'translate(@hreflang,' \ + "'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'," \ + "'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ')" + rhs = "translate('en'," \ + "'ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞŸŽŠŒ'," \ + "'abcdefghijklmnopqrstuvwxyzàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿžšœ')" + expect(selector_builder.build(tag_name: 'a', hreflang: 'en')) + .to eq(xpath: ".//*[local-name()='a'][#{lhs}=#{rhs}]") + expect(selector_builder.build(tag_name: 'a', hreflang: /en/)) + .to eq(xpath: ".//*[local-name()='a'][contains(#{lhs}, #{rhs})]") + end + + it 'respects case when attribute is not defined for element' do + expect(selector_builder.build(tag_name: 'table', hreflang: 'en')) + .to eq(xpath: ".//*[local-name()='table'][@hreflang='en']") + expect(selector_builder.build(tag_name: 'table', hreflang: /en/)) + .to eq(xpath: ".//*[local-name()='table'][contains(@hreflang, 'en')]") + expect(selector_builder.build(tag_name: /a/, hreflang: 'en')) + .to eq(xpath: ".//*[contains(local-name(), 'a')][@hreflang='en']") + expect(selector_builder.build(tag_name: /a/, hreflang: /en/)) + .to eq(xpath: ".//*[contains(local-name(), 'a')][contains(@hreflang, 'en')]") end end end end