lib/prickle/capybara/element.rb in prickle-0.0.4 vs lib/prickle/capybara/element.rb in prickle-0.0.5
- old
+ new
@@ -1,6 +1,7 @@
require 'capybara/dsl'
+require_relative 'xpath'
require_relative 'actions'
module Prickle
module Capybara
class Element
@@ -19,42 +20,30 @@
@type = type
self
end
def identifier
- @identifier.each_pair.inject([]) do |xpath_str, (key, value)|
- xpath_str << convert_to_xpath(key, value)
- end.join " and "
+ @identifier
end
- def convert_to_xpath key, value
- if key.to_s.include? "<value>"
- key.sub "<value>", value
- else
- "@#{key}='#{value}'"
- end
- end
-
- def type
+ def type_as_tag
CONVERTED_TYPES[@type.to_sym] || @type
end
def find_element
handle_exception { find_element_by_xpath }
end
- def xpath
- xpath = "//#{type}[#{identifier}"
- xpath << " and contains(text(), '#{@text}')" if @text
- xpath << "]"
- end
-
def find_element_by_xpath
- wait_until(Prickle::Capybara.wait_time) do
+ wait_until(Capybara.wait_time) do
find(:xpath, xpath).visible?
- end unless Prickle::Capybara.wait_time.nil?
+ end unless Capybara.wait_time.nil?
- find(:xpath, xpath)
+ find :xpath, xpath
+ end
+
+ def xpath
+ XPath::for_element_with type_as_tag, identifier
end
def handle_exception &block
begin
block.call