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

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



301
302
303
# File 'lib/ruby_app/element.rb', line 301

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

Instance Method Details

#add_class(selector, _class) ⇒ Object



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

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

#alert(message) ⇒ Object



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

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

#assert(name, expression = nil) ⇒ Object



275
276
277
# File 'lib/ruby_app/element.rb', line 275

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



247
248
249
250
# File 'lib/ruby_app/element.rb', line 247

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


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

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

#assert_exists_search(text, value = nil) ⇒ Object



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

def assert_exists_search(text, value = nil)
  self.assert_exists_selector("form.ui-listview-filter input[placeholder='#{text}']") unless value
  self.assert_exists_selector_value("form.ui-listview-filter input[placeholder='#{text}']", value) if value
end

#assert_exists_selector(selector) ⇒ Object



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

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

#assert_exists_selector_for(selector) ⇒ Object



227
228
229
230
# File 'lib/ruby_app/element.rb', line 227

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

#assert_exists_selector_value(selector, value = nil) ⇒ Object



207
208
209
210
# File 'lib/ruby_app/element.rb', line 207

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

#assert_exists_selector_value_for(selector, value) ⇒ Object



237
238
239
240
# File 'lib/ruby_app/element.rb', line 237

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



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

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

#assert_is_selector_visible(selector) ⇒ Object



265
266
267
268
# File 'lib/ruby_app/element.rb', line 265

def assert_is_selector_visible(selector)
  _selector = ".ui-page-active #{selector}:last"
  self.execute("RubyApp.assertIsVisible(#{_selector.to_json});")
end

#assert_is_text_visible(text) ⇒ Object



257
258
259
# File 'lib/ruby_app/element.rb', line 257

def assert_is_text_visible(text)
  self.assert_is_selector_visible("*:visible:contains('#{text}')")
end

#assert_not_exists_input(text, value = nil) ⇒ Object



252
253
254
255
# File 'lib/ruby_app/element.rb', line 252

def assert_not_exists_input(text, value = nil)
  self.assert_not_exists_selector_for("label:contains('#{text}')") unless value
  self.assert_not_exists_selector_value_for("label:contains('#{text}')", value) if value
end


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

def assert_not_exists_link(text)
  self.assert_not_exists_selector("a:visible:contains('#{text}')")
end

#assert_not_exists_search(text, value = nil) ⇒ Object



222
223
224
225
# File 'lib/ruby_app/element.rb', line 222

def assert_not_exists_search(text, value = nil)
  self.assert_not_exists_selector("form.ui-listview-filter input[placeholder='#{text}']") unless value
  self.assert_not_exists_selector_value("form.ui-listview-filter input[placeholder='#{text}']", value) if value
end

#assert_not_exists_selector(selector) ⇒ Object



202
203
204
205
# File 'lib/ruby_app/element.rb', line 202

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

#assert_not_exists_selector_for(selector) ⇒ Object



232
233
234
235
# File 'lib/ruby_app/element.rb', line 232

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

#assert_not_exists_selector_value(selector, value = nil) ⇒ Object



212
213
214
215
# File 'lib/ruby_app/element.rb', line 212

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

#assert_not_exists_selector_value_for(selector, value) ⇒ Object



242
243
244
245
# File 'lib/ruby_app/element.rb', line 242

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

#assert_not_exists_text(text) ⇒ Object



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

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

#assert_not_is_selector_visible(selector) ⇒ Object



270
271
272
273
# File 'lib/ruby_app/element.rb', line 270

def assert_not_is_selector_visible(selector)
  _selector = ".ui-page-active #{selector}:last"
  self.execute("RubyApp.assertNotIsVisible(#{_selector.to_json});")
end

#assert_not_is_text_visible(text) ⇒ Object



261
262
263
# File 'lib/ruby_app/element.rb', line 261

def assert_not_is_text_visible(text)
  self.assert_not_is_selector_visible("*:visible:contains('#{text}')")
end


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

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

#click_list_item(text) ⇒ Object



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

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


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

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

#click_selector(selector) ⇒ Object



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

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

#confirm_refresh_browser(message) ⇒ Object



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

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

#create_trigger(element, interval) ⇒ Object



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

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

#destroy_trigger(element) ⇒ Object



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

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

#execute(statement = nil) ⇒ Object



283
284
285
286
287
288
289
290
# File 'lib/ruby_app/element.rb', line 283

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



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

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

#log(message) ⇒ Object



279
280
281
# File 'lib/ruby_app/element.rb', line 279

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



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

def quit!
  self.go("#{RubyApp::Application.root_or_nil}/quit")
end

#refresh_browserObject



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

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

#remove_class(selector, _class) ⇒ Object



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

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



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

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

#send_message(element, message = nil) ⇒ Object



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

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


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

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



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

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



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

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

#to_hashObject



292
293
294
295
296
297
298
299
# File 'lib/ruby_app/element.rb', line 292

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

#trigger_element(element) ⇒ Object



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

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

#update_document_text(selector, value) ⇒ Object



133
134
135
# File 'lib/ruby_app/element.rb', line 133

def update_document_text(selector, value)
  self.execute("RubyApp.updateText(#{selector.to_json}, #{value.to_json});")
end

#update_element(element) ⇒ Object



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

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

#update_element?(element) ⇒ Boolean

Returns:

  • (Boolean)


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

def update_element?(element)
  return @statements.include?("RubyApp.updateElement(#{element.element_id.to_json});")
end

#update_input(text, value, change = true) ⇒ Object



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

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

#update_search(text, value, change = true) ⇒ Object



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

def update_search(text, value, change = true)
  _selector = ".ui-page-active form.ui-listview-filter input[placeholder='#{text}']"
  self.execute("RubyApp.updateValue(#{_selector.to_json}, #{value.to_json}, #{change.to_json});")
end

#update_style(selector, property, value) ⇒ Object



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

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



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

def update_text(selector, value)
  _selector = ".ui-page-active #{selector}"
  self.update_document_text(_selector, value)
end

#update_value(selector, value, change = true) ⇒ Object



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

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

#update_value_for(selector, value, change = true) ⇒ Object



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

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