Class: RubyApp::Element::Event

Inherits:
Object
  • Object
show all
Extended by:
Mixins::TranslateMixin
Defined in:
lib/ruby_app/element.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Mixins::TranslateMixin

localize, translate

Constructor Details

#initialize(data = nil) ⇒ Event

Returns a new instance of Event.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ruby_app/element.rb', line 28

def initialize(data = nil)
  if data
    @now = Time.parse(data['now'])

    session = RubyApp::Session.get_session(data['session'])
    raise RubyApp::Exceptions::SessionInvalidException.new(data['session']) unless session
    @session = session

    source = RubyApp::Element.get_element(data['source'])
    raise RubyApp::Exceptions::ElementInvalidException.new(data['source']) unless source
    @source = source

  else
    @now = Time.now
    @session = nil
    @source = nil
  end
  @statements = []
end

Instance Attribute Details

#nowObject (readonly)

Returns the value of attribute now.



26
27
28
# File 'lib/ruby_app/element.rb', line 26

def now
  @now
end

#sessionObject (readonly)

Returns the value of attribute session.



26
27
28
# File 'lib/ruby_app/element.rb', line 26

def session
  @session
end

#sourceObject (readonly)

Returns the value of attribute source.



26
27
28
# File 'lib/ruby_app/element.rb', line 26

def source
  @source
end

Class Method Details

.from_hash(data) ⇒ Object



197
198
199
# File 'lib/ruby_app/element.rb', line 197

def self.from_hash(data)
  Kernel.eval(data['_class']).new(data)
end

Instance Method Details

#add_class(selector, _class) ⇒ Object



98
99
100
101
# File 'lib/ruby_app/element.rb', line 98

def add_class(selector, _class)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.addClass(#{_selector.to_json}, #{_class.to_json});")
end

#assert_exists_input(text, value = nil) ⇒ Object



165
166
167
168
# File 'lib/ruby_app/element.rb', line 165

def assert_exists_input(text, value = nil)
  self.assert_exists_selector_for("label:contains('#{text}')") unless value
  self.assert_exists_selector_value_for("label:contains('#{text}')", value) if value
end


156
157
158
# File 'lib/ruby_app/element.rb', line 156

def assert_exists_link(text)
  self.assert_exists_selector("a:contains('#{text}')")
end

#assert_exists_selector(selector) ⇒ Object



160
161
162
163
# File 'lib/ruby_app/element.rb', line 160

def assert_exists_selector(selector)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.assertExists(#{_selector.to_json});")
end

#assert_exists_selector_for(selector) ⇒ Object



170
171
172
173
# File 'lib/ruby_app/element.rb', line 170

def assert_exists_selector_for(selector)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.assertExistsFor(#{_selector.to_json});")
end

#assert_exists_selector_value_for(selector, value) ⇒ Object



175
176
177
178
# File 'lib/ruby_app/element.rb', line 175

def assert_exists_selector_value_for(selector, value)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.assertExistsValueFor(#{_selector.to_json}, #{value.to_json});")
end

#assert_exists_text(text) ⇒ Object



152
153
154
# File 'lib/ruby_app/element.rb', line 152

def assert_exists_text(text)
  self.assert_exists_selector("*:contains('#{text}')")
end

#confirm_refresh_browser(message) ⇒ Object



60
61
62
# File 'lib/ruby_app/element.rb', line 60

def confirm_refresh_browser(message)
  self.execute("RubyApp.confirmRefreshBrowser(#{message.to_json});")
end

#create_trigger(element, interval) ⇒ Object



77
78
79
# File 'lib/ruby_app/element.rb', line 77

def create_trigger(element, interval)
  self.execute("RubyApp.createTrigger(#{element.element_id.to_json}, #{(interval * 1000).to_json});")
end

#destroy_trigger(element) ⇒ Object



81
82
83
# File 'lib/ruby_app/element.rb', line 81

def destroy_trigger(element)
  self.execute("RubyApp.destroyTrigger(#{element.element_id.to_json});")
end

#execute(statement) ⇒ Object



184
185
186
# File 'lib/ruby_app/element.rb', line 184

def execute(statement)
  @statements << statement
end

#go(url) ⇒ Object



89
90
91
# File 'lib/ruby_app/element.rb', line 89

def go(url)
  self.execute("RubyApp.go(#{url.to_json});")
end

#log(message) ⇒ Object



180
181
182
# File 'lib/ruby_app/element.rb', line 180

def log(message)
  self.execute("RubyApp.log(#{message.to_json});")
end

#process!Object



52
53
54
# File 'lib/ruby_app/element.rb', line 52

def process!
  self.source.send(:on_event, self)
end

#quit!Object



85
86
87
# File 'lib/ruby_app/element.rb', line 85

def quit!
  self.go('/quit')
end

#refresh_browserObject



56
57
58
# File 'lib/ruby_app/element.rb', line 56

def refresh_browser
  self.execute("RubyApp.refreshBrowser();")
end

#remove_class(selector, _class) ⇒ Object



103
104
105
106
# File 'lib/ruby_app/element.rb', line 103

def remove_class(selector, _class)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.removeClass(#{_selector.to_json}, #{_class.to_json});")
end

#remove_page(page) ⇒ Object



69
70
71
# File 'lib/ruby_app/element.rb', line 69

def remove_page(page)
  self.execute("RubyApp.removePage(#{page.element_id.to_json});")
end


127
128
129
# File 'lib/ruby_app/element.rb', line 127

def set_cookie(name, value, expires = Time.now + 365*24*60*60)
  self.execute("RubyApp.setCookie(#{name.to_json}, #{value.to_json}, new Date(#{expires.year}, #{expires.month - 1}, #{expires.day}, #{expires.hour}, #{expires.min}, #{expires.sec}));")
end

#show_page(page, options = {}) ⇒ Object



64
65
66
67
# File 'lib/ruby_app/element.rb', line 64

def show_page(page, options = {})
  options.merge!(:changeHash => false)
  self.execute("RubyApp.showPage(#{page.element_id.to_json}, #{options.to_json});")
end

#swipe(direction) ⇒ Object



148
149
150
# File 'lib/ruby_app/element.rb', line 148

def swipe(direction)
  self.execute("RubyApp.swipe#{direction == :left ? 'Left' : 'Right'}();")
end


131
132
133
# File 'lib/ruby_app/element.rb', line 131

def tap_link(text)
  self.tap_selector("a:contains('#{text}')")
end

#tap_list_item(text) ⇒ Object



135
136
137
# File 'lib/ruby_app/element.rb', line 135

def tap_list_item(text)
  self.tap_selector("a.item:contains('#{text}')")
end


139
140
141
# File 'lib/ruby_app/element.rb', line 139

def tap_list_link(text)
  self.tap_selector("a.link[title*='#{text}']")
end

#tap_selector(selector) ⇒ Object



143
144
145
146
# File 'lib/ruby_app/element.rb', line 143

def tap_selector(selector)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.tap(#{_selector.to_json});")
end

#to_hashObject



188
189
190
191
192
193
194
195
# File 'lib/ruby_app/element.rb', line 188

def to_hash
  {
    '_class' => self.class.to_s,
    'now' => @now,
    'source' => @source ? @source.element_id : nil,
    'statements' => @statements
  }
end

#todayObject



48
49
50
# File 'lib/ruby_app/element.rb', line 48

def today
  @now.send(:to_date)
end

#update_element(element) ⇒ Object



73
74
75
# File 'lib/ruby_app/element.rb', line 73

def update_element(element)
  self.execute("RubyApp.updateElement(#{element.element_id.to_json});")
end

#update_input(text, value) ⇒ Object



118
119
120
# File 'lib/ruby_app/element.rb', line 118

def update_input(text, value)
  self.update_value_for("label:contains('#{text}')", value)
end

#update_style(selector, property, value) ⇒ Object



93
94
95
96
# File 'lib/ruby_app/element.rb', line 93

def update_style(selector, property, value)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.updateStyle(#{_selector.to_json}, #{property.to_json}, #{value.to_json});")
end

#update_text(selector, value) ⇒ Object



108
109
110
111
# File 'lib/ruby_app/element.rb', line 108

def update_text(selector, value)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.updateText(#{_selector.to_json}, #{value.to_json});")
end

#update_value(selector, value) ⇒ Object



113
114
115
116
# File 'lib/ruby_app/element.rb', line 113

def update_value(selector, value)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.updateValue(#{_selector.to_json}, #{value.to_json});")
end

#update_value_for(selector, value) ⇒ Object



122
123
124
125
# File 'lib/ruby_app/element.rb', line 122

def update_value_for(selector, value)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.updateValueFor(#{_selector.to_json}, #{value.to_json});")
end