Sha256: bcf0fd9ccae7a8285886d31143fbb745988db409907696b03031ea48511d4c43

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 KB

Contents

module Akephalos
  class Node
    def initialize(node)
      @nodes = []
      @_node = node
    end

    def checked?
      @_node.isChecked
    end

    def text
      @_node.asText
    end

    def [](name)
      @_node.hasAttribute(name.to_s) ? @_node.getAttribute(name.to_s) : nil
    end

    def value=(value)
      case tag_name
      when "textarea"
        @_node.setText(value)
      when "input"
        @_node.setValueAttribute(value)
      end
    end

    def select_option(option)
      opt = @_node.getOptions.detect { |o| o.asText == option }

      opt && opt.setSelected(true)
    end

    def unselect_option(option)
      opt = @_node.getOptions.detect { |o| o.asText == option }

      opt && opt.setSelected(false)
    end

    def options
      @_node.getOptions.map { |node| Node.new(node) }
    end

    def selected_options
      @_node.getSelectedOptions.map { |node| Node.new(node) }
    end

    def fire_event(name)
      @_node.fireEvent(name)
    end

    def tag_name
      @_node.getNodeName
    end

    def visible?
      @_node.isDisplayed
    end

    def click
      @_node.click
      @_node.getPage.getEnclosingWindow.getJobManager.waitForJobs(1000)
      @_node.getPage.getEnclosingWindow.getJobManager.waitForJobsStartingBefore(1000)
    end

    def find(selector)
      nodes = @_node.getByXPath(selector).map { |node| Node.new(node) }
      @nodes << nodes
      nodes
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
akephalos-0.1.0-java lib/akephalos/node.rb
akephalos-0.1.0 lib/akephalos/node.rb
akephalos-0.0.5 lib/akephalos/node.rb