Sha256: 5be933c9cdb267b5ff0cdeb4e6d2e29b7a8181b43610de21a420544fda1be99b

Contents?: true

Size: 1.46 KB

Versions: 14

Compression:

Stored size: 1.46 KB

Contents

module TestCentricity
  class List < UIElement
    attr_accessor :list_item

    def initialize(name, parent, locator, context)
      super
      @type = :list
      define_list_elements({ :list_item => 'li' })
    end

    def define_list_elements(element_spec)
      element_spec.each do |element, value|
        case element
        when :list_item
          @list_item = value
        else
          raise "#{element} is not a recognized list element"
        end
      end
    end

    def get_list_items(element_spec = nil)
      define_list_elements(element_spec) unless element_spec.nil?
      obj, = find_element
      object_not_found_exception(obj, nil)
      obj.all(@list_item).collect(&:text)
    end

    def get_list_item(index)
      items = get_list_items
      items[index - 1]
    end

    def get_item_count
      obj, = find_element
      object_not_found_exception(obj, nil)
      obj.all(@list_item).count
    end

    def verify_list_items(expected, enqueue = false)
      actual = get_list_items
      enqueue ?
          ExceptionQueue.enqueue_assert_equal(expected, actual, "Expected list #{object_ref_message}") :
          assert_equal(expected, actual, "Expected list #{object_ref_message} to be #{expected} but found #{actual}")
    end

    def get_list_row_locator(row)
      case @locator_type
      when :xpath
        "#{@locator}/#{@list_item}[#{row}]"
      when :css
        "#{@locator} > #{@list_item}:nth-of-type(#{row})"
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
testcentricity_web-2.3.9 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.8 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.7 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.6.2 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.6.1 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.6 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.5 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.4 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.3 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.2 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.1 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.3.0 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.2.1 lib/testcentricity_web/elements/list.rb
testcentricity_web-2.2.0 lib/testcentricity_web/elements/list.rb