Class: Ext::Component

Inherits:
Object
  • Object
show all
Defined in:
lib/selenium-extjs/component/Component.rb

Direct Known Subclasses

Button, Field, Grid, Panel, Window

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, parent = nil, selenium = nil) ⇒ Component

Returns a new instance of Component.



9
10
11
12
13
14
# File 'lib/selenium-extjs/component/Component.rb', line 9

def initialize(id, parent = nil, selenium = nil)
  @id = id
  @parent = parent
  @selenium = selenium
   init_component()
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

algumas ideias… obj.items_component_array -> serializar o retorno em uma lista tratar obj.store



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/selenium-extjs/component/Component.rb', line 23

def method_missing(method_name, *args, &block)

  #
  cmp = "window.Ext.getCmp('#{@id}')"
 
  # TODO: unit for validate this :p
  # registered?
  # is_registered
  # isRegistered()

  if method_name.to_s.end_with? "="
    return nil
  end
  
  # convert method name to ext model.
  method_name = Ext::extfy(method_name.to_s)

  # build js arguments list
  arguments = Ext::arguments(args)

  # move to selenium.
  cmd = Ext::build_remote_call(@id, method_name, arguments)
  p cmd
  
  ret = @selenium.get_eval(cmd)
  if ret.start_with? "JSON:"
    ret = JSON ret.split(":", 2)[1]
  end

  if ret == "true" || ret == "false"
    ret = (ret =="true")
  end


  if ret.is_a? Hash
    if ret.has_key? "cmpid"
      p "---->"
      p ret
      return @selenium.get_cmp(ret["cmpid"], nil)
    else
      return ret
    end
  else
    return ret
  end
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



6
7
8
# File 'lib/selenium-extjs/component/Component.rb', line 6

def parent
  @parent
end

Instance Method Details

#getIdObject



90
91
92
# File 'lib/selenium-extjs/component/Component.rb', line 90

def getId()
  return @id
end

#highlightObject



94
95
96
# File 'lib/selenium-extjs/component/Component.rb', line 94

def highlight
 @selenium.highlight(selector())
end

#init_componentObject



16
17
# File 'lib/selenium-extjs/component/Component.rb', line 16

def init_component()
end

#nodeObject

common tag element for this element



75
76
77
# File 'lib/selenium-extjs/component/Component.rb', line 75

def node
 return "//div[@id='#{@id}']"
end

#selectorObject

xpath for this element.



80
81
82
83
84
85
86
87
88
# File 'lib/selenium-extjs/component/Component.rb', line 80

def selector
 p @parent
 sel = ""
 if @parent && @parent.getId()
   sel += @parent.selector()
 end
 sel += node()
 return sel
end

#wait_for_ajaxObject



70
71
72
# File 'lib/selenium-extjs/component/Component.rb', line 70

def wait_for_ajax
 @selenium.wait_for_condition("window.Ext.Ajax.isLoading() == false")
end