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



219
220
221
# File 'lib/ruby_app/element.rb', line 219

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

Instance Method Details

#add_class(selector, _class) ⇒ Object



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

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

#assert(name, expression = nil) ⇒ Object



193
194
195
# File 'lib/ruby_app/element.rb', line 193

def assert(name, expression = nil)
  self.execute("RubyApp.assert(#{name.to_json}, #{(expression ? expression : yield).to_json});")
end

#assert_exists_input(text, value = nil) ⇒ Object



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

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


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

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

#assert_exists_selector(selector) ⇒ Object



168
169
170
171
# File 'lib/ruby_app/element.rb', line 168

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

#assert_exists_selector_for(selector) ⇒ Object



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

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



188
189
190
191
# File 'lib/ruby_app/element.rb', line 188

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



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

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

#assert_not_exists_selector(selector) ⇒ Object



173
174
175
176
# File 'lib/ruby_app/element.rb', line 173

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

#assert_not_exists_text(text) ⇒ Object



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

def assert_not_exists_text(text)
  self.assert_not_exists_selector("*:contains('#{text}')")
end


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

def click_link(text)
  self.click_selector("a:contains('#{text}')")
end

#click_list_item(text) ⇒ Object



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

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


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

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

#click_selector(selector) ⇒ Object



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

def click_selector(selector)
  _selector = ".ui-page-active #{selector}"
  self.execute("RubyApp.click(#{_selector.to_json});")
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



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

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

#destroy_trigger(element) ⇒ Object



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

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

#execute(statement = nil) ⇒ Object



201
202
203
204
205
206
207
208
# File 'lib/ruby_app/element.rb', line 201

def execute(statement = nil)
  if statement
    @statements << statement
  else
    yield if block_given?
    self.execute("RubyApp.sendEvent({_class:'RubyApp::Element::ExecutedEvent', source:$('html').attr('id')});")
  end
end

#go(url) ⇒ Object



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

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

#log(message) ⇒ Object



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

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



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

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



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

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



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

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

#send_message(element, message = nil) ⇒ Object



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

def send_message(element, message = nil)
  self.execute("RubyApp.sendEvent({_class:'RubyApp::Element::MessagedEvent', source:#{element.element_id.to_json}, message:#{message.to_json}});")
end


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

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



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

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



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

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

#to_hashObject



210
211
212
213
214
215
216
217
# File 'lib/ruby_app/element.rb', line 210

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



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

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

#update_input(text, value) ⇒ Object



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

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

#update_style(selector, property, value) ⇒ Object



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

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



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

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



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

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



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

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