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
47
# 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
  @delay = 0
  @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



308
309
310
# File 'lib/ruby_app/element.rb', line 308

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

Instance Method Details

#add_class(selector, _class) ⇒ Object



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

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

#alert(message) ⇒ Object



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

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

#assert(name, expression = nil) ⇒ Object



281
282
283
# File 'lib/ruby_app/element.rb', line 281

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



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

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


195
196
197
# File 'lib/ruby_app/element.rb', line 195

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

#assert_exists_search(text, value = nil) ⇒ Object



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

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



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

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

#assert_exists_selector_for(selector) ⇒ Object



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

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



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

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



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

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



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

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

#assert_is_selector_visible(selector) ⇒ Object



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

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



263
264
265
# File 'lib/ruby_app/element.rb', line 263

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

#assert_not_exists_input(text, value = nil) ⇒ Object



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

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


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

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

#assert_not_exists_search(text, value = nil) ⇒ Object



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

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



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

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



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

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



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

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



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

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



191
192
193
# File 'lib/ruby_app/element.rb', line 191

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

#assert_not_is_selector_visible(selector) ⇒ Object



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

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



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

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


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

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

#click_list_item(text) ⇒ Object



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

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


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

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

#click_selector(selector) ⇒ Object



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

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

#confirm_refresh_browser(message) ⇒ Object



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

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

#create_trigger(element, interval) ⇒ Object



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

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

#delay(duration) ⇒ Object



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

def delay(duration)
  @delay = duration
  return self
end

#destroy_trigger(element) ⇒ Object



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

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

#execute(statement = nil) ⇒ Object



289
290
291
292
293
294
295
296
# File 'lib/ruby_app/element.rb', line 289

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



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

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

#log(message) ⇒ Object



285
286
287
# File 'lib/ruby_app/element.rb', line 285

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

#process!Object



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

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

#quit!Object



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

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

#refresh_browserObject



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

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

#remove_class(selector, _class) ⇒ Object



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

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



87
88
89
# File 'lib/ruby_app/element.rb', line 87

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

#send_message(element, message = nil) ⇒ Object



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

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


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

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



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

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



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

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

#to_hashObject



298
299
300
301
302
303
304
305
306
# File 'lib/ruby_app/element.rb', line 298

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

#todayObject



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

def today
  @now.send(:to_date)
end

#trigger_element(element) ⇒ Object



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

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

#update_document_text(selector, value) ⇒ Object



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

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

#update_element(element) ⇒ Object



91
92
93
# File 'lib/ruby_app/element.rb', line 91

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

#update_element?(element) ⇒ Boolean

Returns:

  • (Boolean)


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

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

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



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

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

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



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

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



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

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



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

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

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



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

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



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

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