Skip to content

Commit

Permalink
Merge 181a195 into 5a3e8a9
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Sep 17, 2018
2 parents 5a3e8a9 + 181a195 commit 7792c16
Show file tree
Hide file tree
Showing 19 changed files with 257 additions and 215 deletions.
7 changes: 4 additions & 3 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Metrics/ClassLength:
Max: 116
Exclude:
- 'lib/watir/locators/element/locator.rb'
- 'lib/watir/locators/element/selector_builder/xpath.rb'
- 'lib/watir/browser.rb'
- 'lib/watir/elements/element.rb'
- 'lib/watir/elements/select.rb'
Expand All @@ -69,11 +70,11 @@ Metrics/PerceivedComplexity:
Metrics/CyclomaticComplexity:
Max: 9

# Offense count: 28
Metrics/AbcSize:
Max: 22
Max: 21
Exclude:
- 'lib/watir/locators/element/selector_builder.rb'
- 'lib/watir/locators/element/locator.rb'
- 'lib/watir/generator/base/generator.rb'

# TODO: fix with Watir 7
Expand Down Expand Up @@ -124,7 +125,7 @@ Style/MethodCallWithoutArgsParentheses:
Style/FormatStringToken:
Exclude:
- 'lib/watir/browser.rb'
- 'lib/watir/locators/text_field/selector_builder.rb'
- 'lib/watir/locators/text_field/selector_builder/xpath.rb'
- 'lib/watir/window.rb'

Style/Documentation:
Expand Down
2 changes: 1 addition & 1 deletion lib/watir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def always_locate_message
end

#
# Whether or not Watir should prefer CSS when translating the Watir selectors to Selenium.
# Whether or not Watir should prefer CSS when translating the Watir selector to Selenium.
#

def prefer_css?
Expand Down
14 changes: 7 additions & 7 deletions lib/watir/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ def elements(*args)
# @api private
#

def extract_selector(selectors)
case selectors.size
def extract_selector(selector)
case selector.size
when 2
msg = "Using ordered parameters to locate elements (:#{selectors.first}, #{selectors.last.inspect})"
msg = "Using ordered parameters to locate elements (:#{selector.first}, #{selector.last.inspect})"
Watir.logger.deprecate msg,
"{#{selectors.first}: #{selectors.last.inspect}}",
"{#{selector.first}: #{selector.last.inspect}}",
ids: [:selector_parameters]
return {selectors[0] => selectors[1]}
return {selector[0] => selector[1]}
when 1
obj = selectors.first
obj = selector.first
return obj if obj.is_a? Hash
when 0
return {}
end

raise ArgumentError, "expected Hash, got #{selectors.inspect}"
raise ArgumentError, "expected Hash, got #{selector.inspect}"
end
end # Container
end # Watir
4 changes: 3 additions & 1 deletion lib/watir/locators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@

require 'watir/locators/cell/locator'
require 'watir/locators/cell/selector_builder'
require 'watir/locators/cell/selector_builder/xpath'

require 'watir/locators/row/locator'
require 'watir/locators/row/selector_builder'
require 'watir/locators/row/selector_builder/xpath'

require 'watir/locators/text_area/locator'
require 'watir/locators/text_area/selector_builder'
require 'watir/locators/text_area/selector_builder/xpath'

require 'watir/locators/text_field/locator'
require 'watir/locators/text_field/selector_builder'
Expand Down
11 changes: 3 additions & 8 deletions lib/watir/locators/button/locator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@ def using_selenium(*)
# force watir usage
end

def can_convert_regexp_to_contains?
# regexp conversion won't work with the complex xpath selector
false
end

def matches_selector?(element, selector)
if selector.key?(:value)
copy = selector.dup
def matches_values?(element, values_to_match)
if values_to_match.key?(:value)
copy = values_to_match.dup
value = copy.delete(:value)

super(element, copy) &&
Expand Down
22 changes: 0 additions & 22 deletions lib/watir/locators/button/selector_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,6 @@ module Watir
module Locators
class Button
class SelectorBuilder < Element::SelectorBuilder
def build_wd_selector(selectors)
return if selectors.values.any? { |e| e.is_a? Regexp }

selectors.delete(:tag_name) || raise('internal error: no tag_name?!')

button_attr_exp = xpath_builder.attribute_expression(:button, selectors)

xpath = './/button'
xpath << "[#{button_attr_exp}]" unless button_attr_exp.empty?

unless selectors[:type].eql? false
selectors[:type] = Watir::Button::VALID_TYPES if [nil, true].include?(selectors[:type])
input_attr_exp = xpath_builder.attribute_expression(:input, selectors)

xpath << ' | .//input'
xpath << "[#{input_attr_exp}]"
end

p build_wd_selector: xpath if $DEBUG

[:xpath, xpath]
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions lib/watir/locators/button/selector_builder/xpath.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ module Locators
class Button
class SelectorBuilder
class XPath < Element::SelectorBuilder::XPath
def add_tag_name(selector)
selector.delete(:tag_name)
"[local-name()='button']"
end

def add_attributes(selector)
button_attr_exp = attribute_expression(:button, selector)
xpath = button_attr_exp.empty? ? '' : "[#{button_attr_exp}]"
return xpath if selector[:type].eql? false

selector[:type] = Watir::Button::VALID_TYPES if [nil, true].include?(selector[:type])
xpath << " | .//*[local-name()='input']"
input_attr_exp = attribute_expression(:input, selector)
xpath << "[#{input_attr_exp}]" unless input_attr_exp.empty?
end

def lhs_for(building, key)
if building == :input && key == :text
'@value'
Expand All @@ -13,6 +29,11 @@ def lhs_for(building, key)

private

def convert_regexp_to_contains?
# regexp conversion won't work with the complex xpath selector
false
end

def equal_pair(building, key, value)
if building == :button && key == :value
# :value should look for both node text and @value attribute
Expand Down
14 changes: 0 additions & 14 deletions lib/watir/locators/cell/selector_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,6 @@ module Watir
module Locators
class Cell
class SelectorBuilder < Element::SelectorBuilder
def build_wd_selector(selectors)
return if selectors.values.any? { |e| e.is_a? Regexp }

expressions = %w[./th ./td]
attr_expr = xpath_builder.attribute_expression(nil, selectors)

expressions.map! { |e| "#{e}[#{attr_expr}]" } unless attr_expr.empty?

xpath = expressions.join(' | ')

p build_wd_selector: xpath if $DEBUG

[:xpath, xpath]
end
end
end
end
Expand Down
27 changes: 27 additions & 0 deletions lib/watir/locators/cell/selector_builder/xpath.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Watir
module Locators
class Cell
class SelectorBuilder
class XPath < Element::SelectorBuilder::XPath
def add_attributes(selector)
attr_expr = attribute_expression(nil, selector)

expressions = %w[./th ./td]
expressions.map! { |e| "#{e}[#{attr_expr}]" } unless attr_expr.empty?

expressions.join(' | ')
end

def default_start
''
end

def add_tag_name(selector)
selector.delete(:tag_name)
''
end
end
end
end
end
end

0 comments on commit 7792c16

Please sign in to comment.