Module: Kameleon::DSL::Context::SpecialSelectors

Defined in:
lib/kameleon/dsl/context/scope.rb

Overview

! extending selectors in capybara way github.com/jnicklas/capybara/blob/master/lib/capybara.rb#L76

Class Method Summary collapse

Class Method Details

.cell(param) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/kameleon/dsl/context/scope.rb', line 77

def self.cell(param)
  value_in_row, value_in_column = *param
  if value_in_row.is_a?(Fixnum) and value_in_column.is_a?(Fixnum)
    [:xpath, "//tbody/tr[#{value_in_row}]/td[#{value_in_column}]"]
  else
    #! on page there might be more then one table
    result = Capybara.current_session.all(:xpath, "//table//th")
    elements = result.each.to_a
    position = elements.index { |n| n.text =~ /#{value_in_column}/ }
    [:xpath, "//tr[*='#{value_in_row}'][1]/td[#{position+1}]"]
  end
end

.column(param) ⇒ Object



90
91
92
93
94
# File 'lib/kameleon/dsl/context/scope.rb', line 90

def self.column(param)
  raise "not implemented"
  #            position = session.all(:xpath, "//table//th").index { |n| n.text =~ /#{value}/ }
  #            return [:xpath, ".//table//th[#{position + 1}] | .//table//td[#{position + 1}]", :select_multiple]
end

.row(param) ⇒ Object



66
67
68
69
70
71
72
73
74
75
# File 'lib/kameleon/dsl/context/scope.rb', line 66

def self.row(param)
  case param
    when String
      [:xpath, "//tr[*='#{param}'][1]"]
    when Fixnum
      [:xpath, "//tbody/tr[#{param}]"]
    else
      raise "not implemented"
  end
end