Class: Akephalos::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/akephalos/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Node

Returns a new instance of Node.



3
4
5
6
# File 'lib/akephalos/node.rb', line 3

def initialize(node)
  @nodes = []
  @_node = node
end

Instance Method Details

#[](name) ⇒ Object



16
17
18
# File 'lib/akephalos/node.rb', line 16

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

#checked?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/akephalos/node.rb', line 8

def checked?
  @_node.isChecked
end

#clickObject



77
78
79
80
81
# File 'lib/akephalos/node.rb', line 77

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

#find(selector) ⇒ Object



83
84
85
86
87
# File 'lib/akephalos/node.rb', line 83

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

#fire_event(name) ⇒ Object



65
66
67
# File 'lib/akephalos/node.rb', line 65

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

#optionsObject



57
58
59
# File 'lib/akephalos/node.rb', line 57

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

#select_option(option) ⇒ Object



45
46
47
48
49
# File 'lib/akephalos/node.rb', line 45

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

  opt && opt.setSelected(true)
end

#selected_optionsObject



61
62
63
# File 'lib/akephalos/node.rb', line 61

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

#tag_nameObject



69
70
71
# File 'lib/akephalos/node.rb', line 69

def tag_name
  @_node.getNodeName
end

#textObject



12
13
14
# File 'lib/akephalos/node.rb', line 12

def text
  @_node.asText
end

#unselect_option(option) ⇒ Object



51
52
53
54
55
# File 'lib/akephalos/node.rb', line 51

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

  opt && opt.setSelected(false)
end

#valueObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/akephalos/node.rb', line 20

def value
  case tag_name
  when "select"
    if self[:multiple]
      @_node.selected_options.map { |option| option.text }
    else
      selected_option = @_node.selected_options.first
      selected_option ? selected_option.text : nil
    end
  when "textarea"
    @_node.getText
  else
    self[:value]
  end
end

#value=(value) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/akephalos/node.rb', line 36

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

#visible?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/akephalos/node.rb', line 73

def visible?
  @_node.isDisplayed
end