Class: Symbiont::Platforms::WatirWebDriver::PlatformObject

Inherits:
Object
  • Object
show all
Defined in:
lib/symbiont/platform_watir/platform_object.rb

Instance Method Summary collapse

Constructor Details

#initialize(browser) ⇒ PlatformObject

Returns a new instance of PlatformObject.



7
8
9
# File 'lib/symbiont/platform_watir/platform_object.rb', line 7

def initialize(browser)
  @browser = browser
end

Instance Method Details

#backObject



29
30
31
# File 'lib/symbiont/platform_watir/platform_object.rb', line 29

def back
  @browser.back
end

#button_element(locator) ⇒ Object

Buttons ##



175
176
177
# File 'lib/symbiont/platform_watir/platform_object.rb', line 175

def button_element(locator)
  reference_web_object("button(locator)", WebObjects::Button, locator)
end

#cell_element(locator) ⇒ Object



282
283
284
# File 'lib/symbiont/platform_watir/platform_object.rb', line 282

def cell_element(locator)
  reference_web_object("td(locator)", WebObjects::TableCell, locator, 'td')
end

#check_checkbox_for(locator) ⇒ Object



231
232
233
# File 'lib/symbiont/platform_watir/platform_object.rb', line 231

def check_checkbox_for(locator)
  access_web_object("checkbox(locator).set", WebObjects::CheckBox, locator)
end

#check_checkbox_for_checked(locator) ⇒ Object



227
228
229
# File 'lib/symbiont/platform_watir/platform_object.rb', line 227

def check_checkbox_for_checked(locator)
  access_web_object("checkbox(locator).set?", WebObjects::CheckBox, locator)
end

#check_radio_for_selected(locator) ⇒ Object



264
265
266
# File 'lib/symbiont/platform_watir/platform_object.rb', line 264

def check_radio_for_selected(locator)
  access_web_object("radio(locator).set?", WebObjects::Radio, locator)
end

#checkbox_element(locator) ⇒ Object

Checkboxes ##



223
224
225
# File 'lib/symbiont/platform_watir/platform_object.rb', line 223

def checkbox_element(locator)
  reference_web_object("checkbox(locator)", WebObjects::CheckBox, locator)
end

#click_button_for(locator) ⇒ Object



179
180
181
# File 'lib/symbiont/platform_watir/platform_object.rb', line 179

def click_button_for(locator)
  access_web_object("button(locator).click", WebObjects::Button, locator)
end


169
170
171
# File 'lib/symbiont/platform_watir/platform_object.rb', line 169

def click_link_for(locator)
  access_web_object("link(locator).click", WebObjects::Link, locator)
end

#div_element(locator) ⇒ Object

Sectional Elements ##



292
293
294
# File 'lib/symbiont/platform_watir/platform_object.rb', line 292

def div_element(locator)
  reference_web_object("div(locator)", WebObjects::Div, locator, 'div')
end

#div_text_for(locator) ⇒ Object



296
297
298
# File 'lib/symbiont/platform_watir/platform_object.rb', line 296

def div_text_for(locator)
  access_web_object("div(locator).text", WebObjects::Div, locator, nil, 'div')
end

#focusObject



59
60
61
62
63
64
# File 'lib/symbiont/platform_watir/platform_object.rb', line 59

def focus
  web_object = @browser.execute_script("return document.activeElement")
  type = web_object.type.to_sym if web_object.tag_name.to_sym == :input
  object_class = ::Symbiont::WebObjects.get_class_for(web_object.tag_name, type)
  object_class.new(web_object)
end

#forwardObject



33
34
35
# File 'lib/symbiont/platform_watir/platform_object.rb', line 33

def forward
  @browser.forward
end

#get_hidden_field_value_for(locator) ⇒ Object



217
218
219
# File 'lib/symbiont/platform_watir/platform_object.rb', line 217

def get_hidden_field_value_for(locator)
  access_web_object("hidden(locator).value", WebObjects::HiddenField, locator)
end

#get_select_list_item_for(locator) ⇒ Object



245
246
247
248
# File 'lib/symbiont/platform_watir/platform_object.rb', line 245

def get_select_list_item_for(locator)
  access_web_object("select_list(locator).selected_options[0].text", WebObjects::SelectList, locator)
  # Should I consider: select_list(identifier).options.find {|o| o.selected?}.text
end

#get_select_list_value_for(locator) ⇒ Object



250
251
252
# File 'lib/symbiont/platform_watir/platform_object.rb', line 250

def get_select_list_value_for(locator)
  access_web_object("select_list(locator).value", WebObjects::SelectList, locator)
end

#get_table_cell_text_for(locator) ⇒ Object



286
287
288
# File 'lib/symbiont/platform_watir/platform_object.rb', line 286

def get_table_cell_text_for(locator)
  access_web_object("td(locator).text", WebObjects::TableCell, locator, nil, 'td')
end

#get_text_area_value_for(locator) ⇒ Object



203
204
205
# File 'lib/symbiont/platform_watir/platform_object.rb', line 203

def get_text_area_value_for(locator)
  access_web_object("text_area(locator).value", WebObjects::TextArea, locator)
end

#get_text_field_value_for(locator) ⇒ Object



189
190
191
# File 'lib/symbiont/platform_watir/platform_object.rb', line 189

def get_text_field_value_for(locator)
  access_web_object("text_field(locator).value", WebObjects::TextField, locator)
end

#h1_element(locator) ⇒ Object

Header Elements ##



310
311
312
# File 'lib/symbiont/platform_watir/platform_object.rb', line 310

def h1_element(locator)
  reference_web_object("h1(locator)", WebObjects::Heading, locator, 'h1')
end

#h1_text_for(locator) ⇒ Object



314
315
316
# File 'lib/symbiont/platform_watir/platform_object.rb', line 314

def h1_text_for(locator)
  access_web_object("h1(locator).text", WebObjects::Heading, locator, nil, 'h1')
end

#h2_element(locator) ⇒ Object



318
319
320
# File 'lib/symbiont/platform_watir/platform_object.rb', line 318

def h2_element(locator)
  reference_web_object("h2(locator)", WebObjects::Heading, locator, 'h2')
end

#h2_text_for(locator) ⇒ Object



322
323
324
# File 'lib/symbiont/platform_watir/platform_object.rb', line 322

def h2_text_for(locator)
  access_web_object("h2(locator).text", WebObjects::Heading, locator, nil, 'h2')
end

#hidden_field_element(locator) ⇒ Object

Hidden Fields ##



213
214
215
# File 'lib/symbiont/platform_watir/platform_object.rb', line 213

def hidden_field_element(locator)
  reference_web_object("hidden(locator)", WebObjects::HiddenField, locator)
end

#label_element(locator) ⇒ Object

Labels ##



155
156
157
# File 'lib/symbiont/platform_watir/platform_object.rb', line 155

def label_element(locator)
  reference_web_object("label(locator)", WebObjects::Label, locator, 'label')
end

#label_text_for(locator) ⇒ Object



159
160
161
# File 'lib/symbiont/platform_watir/platform_object.rb', line 159

def label_text_for(locator)
  access_web_object("label(locator).text", WebObjects::Label, locator, nil, 'label')
end

Links ##



165
166
167
# File 'lib/symbiont/platform_watir/platform_object.rb', line 165

def link_element(locator)
  reference_web_object("link(locator)", WebObjects::Link, locator)
end

#list_item_element(locator) ⇒ Object



352
353
354
# File 'lib/symbiont/platform_watir/platform_object.rb', line 352

def list_item_element(locator)
  reference_web_object("li(locator)", WebObjects::ListItem, locator, 'li')
end

#list_item_text_for(locator) ⇒ Object



356
357
358
# File 'lib/symbiont/platform_watir/platform_object.rb', line 356

def list_item_text_for(locator)
  access_web_object("li(locator).text", WebObjects::ListItem, locator, nil, 'li')
end

#list_items_elements(locator) ⇒ Object



360
361
362
# File 'lib/symbiont/platform_watir/platform_object.rb', line 360

def list_items_elements(locator)
  reference_web_object("lis(locator)", WebObjects::ListItem, locator, 'li')
end

#markupObject



51
52
53
# File 'lib/symbiont/platform_watir/platform_object.rb', line 51

def markup
  @browser.html
end

#ordered_list_element(locator) ⇒ Object

List Elements ##



328
329
330
# File 'lib/symbiont/platform_watir/platform_object.rb', line 328

def ordered_list_element(locator)
  reference_web_object("ol(locator)", WebObjects::OrderedList, locator, 'ol')
end

#ordered_list_text_for(locator) ⇒ Object



332
333
334
# File 'lib/symbiont/platform_watir/platform_object.rb', line 332

def ordered_list_text_for(locator)
  access_web_object("ol(locator).text", WebObjects::OrderedList, locator, nil, 'ol')
end

#ordered_lists_elements(locator) ⇒ Object



336
337
338
# File 'lib/symbiont/platform_watir/platform_object.rb', line 336

def ordered_lists_elements(locator)
  reference_web_object("ols(locator)", WebObjects::OrderedList, locator, 'ol')
end

#paragraph_element(locator) ⇒ Object

Paragraphs ##



145
146
147
# File 'lib/symbiont/platform_watir/platform_object.rb', line 145

def paragraph_element(locator)
  reference_web_object("p(locator)", WebObjects::Paragraph, locator, 'p')
end

#paragraph_text_for(locator) ⇒ Object



149
150
151
# File 'lib/symbiont/platform_watir/platform_object.rb', line 149

def paragraph_text_for(locator)
  access_web_object("p(locator).text", WebObjects::Paragraph, locator, nil, 'p')
end

#radio_element(locator) ⇒ Object

Radios ##



260
261
262
# File 'lib/symbiont/platform_watir/platform_object.rb', line 260

def radio_element(locator)
  reference_web_object("radio(locator)", WebObjects::Radio, locator)
end

#refreshObject



37
38
39
# File 'lib/symbiont/platform_watir/platform_object.rb', line 37

def refresh
  @browser.refresh
end

#remove_cookiesObject



41
42
43
# File 'lib/symbiont/platform_watir/platform_object.rb', line 41

def remove_cookies
  @browser.cookies.clear
end

#run_script(script) ⇒ Object



25
26
27
# File 'lib/symbiont/platform_watir/platform_object.rb', line 25

def run_script(script)
  @browser.execute_script(script)
end

#screenshot(file) ⇒ Object



21
22
23
# File 'lib/symbiont/platform_watir/platform_object.rb', line 21

def screenshot(file)
  @browser.wd.save_screenshot(file)
end

#select_list_element(locator) ⇒ Object

Select Lists ##



241
242
243
# File 'lib/symbiont/platform_watir/platform_object.rb', line 241

def select_list_element(locator)
  reference_web_object("select_list(locator)", WebObjects::SelectList, locator)
end

#select_radio_for(locator) ⇒ Object



268
269
270
# File 'lib/symbiont/platform_watir/platform_object.rb', line 268

def select_radio_for(locator)
  access_web_object("radio(locator).set", WebObjects::Radio, locator)
end

#set_select_list_value_for(locator, value) ⇒ Object



254
255
256
# File 'lib/symbiont/platform_watir/platform_object.rb', line 254

def set_select_list_value_for(locator, value)
  access_web_object("select_list(locator).select(value)", WebObjects::SelectList, locator, value)
end

#set_text_area_value_for(locator, value) ⇒ Object



207
208
209
# File 'lib/symbiont/platform_watir/platform_object.rb', line 207

def set_text_area_value_for(locator, value)
  access_web_object("text_area(locator).set(value)", WebObjects::TextArea, locator, value)
end

#set_text_field_value_for(locator, value) ⇒ Object



193
194
195
# File 'lib/symbiont/platform_watir/platform_object.rb', line 193

def set_text_field_value_for(locator, value)
  access_web_object("text_field(locator).set(value)", WebObjects::TextField, locator, value)
end

#span_element(locator) ⇒ Object



300
301
302
# File 'lib/symbiont/platform_watir/platform_object.rb', line 300

def span_element(locator)
  reference_web_object("span(locator)", WebObjects::Span, locator, 'span')
end

#span_text_for(locator) ⇒ Object



304
305
306
# File 'lib/symbiont/platform_watir/platform_object.rb', line 304

def span_text_for(locator)
  access_web_object("span(locator).text", WebObjects::Span, locator, nil, 'span')
end

#table_element(locator) ⇒ Object

Table Elements ##



274
275
276
# File 'lib/symbiont/platform_watir/platform_object.rb', line 274

def table_element(locator)
  reference_web_object("table(locator)", WebObjects::Table, locator, 'table')
end

#table_text_for(locator) ⇒ Object



278
279
280
# File 'lib/symbiont/platform_watir/platform_object.rb', line 278

def table_text_for(locator)
  access_web_object("table(locator).text", WebObjects::Table, locator, nil, 'table')
end

#textObject

Page-Level Actions ##



47
48
49
# File 'lib/symbiont/platform_watir/platform_object.rb', line 47

def text
  @browser.text
end

#text_area_element(locator) ⇒ Object

Text Areas ##



199
200
201
# File 'lib/symbiont/platform_watir/platform_object.rb', line 199

def text_area_element(locator)
  reference_web_object("text_area(locator)", WebObjects::TextArea, locator)
end

#text_field_element(locator) ⇒ Object

Text Fields ##



185
186
187
# File 'lib/symbiont/platform_watir/platform_object.rb', line 185

def text_field_element(locator)
  reference_web_object("text_field(locator)", WebObjects::TextField, locator)
end

#titleObject



55
56
57
# File 'lib/symbiont/platform_watir/platform_object.rb', line 55

def title
  @browser.title
end

#uncheck_checkbox_for(locator) ⇒ Object



235
236
237
# File 'lib/symbiont/platform_watir/platform_object.rb', line 235

def uncheck_checkbox_for(locator)
  access_web_object("checkbox(locator).clear", WebObjects::CheckBox, locator)
end

#unordered_list_element(locator) ⇒ Object



340
341
342
# File 'lib/symbiont/platform_watir/platform_object.rb', line 340

def unordered_list_element(locator)
  reference_web_object("ul(locator)", WebObjects::UnorderedList, locator, 'ul')
end

#unordered_list_text_for(locator) ⇒ Object



344
345
346
# File 'lib/symbiont/platform_watir/platform_object.rb', line 344

def unordered_list_text_for(locator)
  access_web_object("ul(locator).text", WebObjects::UnorderedList, locator, nil, 'ul')
end

#unordered_lists_elements(locator) ⇒ Object



348
349
350
# File 'lib/symbiont/platform_watir/platform_object.rb', line 348

def unordered_lists_elements(locator)
  reference_web_object("uls(locator)", WebObjects::UnorderedList, locator, 'ul')
end

#urlObject



17
18
19
# File 'lib/symbiont/platform_watir/platform_object.rb', line 17

def url
  @browser.url
end

#visit(url) ⇒ Object

Browser-Level Actions ##



13
14
15
# File 'lib/symbiont/platform_watir/platform_object.rb', line 13

def visit(url)
  @browser.goto(url)
end

#wait_for(timeout, message = "wait condition not found", &block) ⇒ Object

Platform method to wait for an action to complete in a given time.

See Also:



70
71
72
# File 'lib/symbiont/platform_watir/platform_object.rb', line 70

def wait_for(timeout, message="wait condition not found", &block)
  @browser.wait_until(timeout, message, &block)
end

#will_alert(encloser = nil, &block) ⇒ Object

Platform method to handle an alert message box.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/symbiont/platform_watir/platform_object.rb', line 90

def will_alert(encloser=nil, &block)
  switch_to_frame(encloser)

  yield
  value = nil
  if @browser.alert.exists?
    value = @browser.alert.text
    @browser.alert.ok
  end

  ###
  ##@browser.wd.execute_script("window.alert = function(msg) { window.__lastWatirAlert=msg; }")
  ##yield
  ##value = @browser.wd.execute_script("return window.__lastWatirAlert")

  switch_to_default_content(encloser)
  value
end

#will_confirm(response, encloser = nil, &block) ⇒ Object

Platform method to handle a confirmation message box



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/symbiont/platform_watir/platform_object.rb', line 111

def will_confirm(response, encloser=nil, &block)
  switch_to_frame(encloser)

  yield
  value = nil
  if @browser.alert.exists?
    value = @browser.alert.text
    response ? @browser.alert.ok : @browser.alert.close
  end

  ##@browser.wd.execute_script("window.confirm = function(msg) { window.__lastWatirConfirm=msg; return #{!!response} }")
  ##yield
  ##value = @browser.wd.execute_script("return window.__lastWatirConfirm")

  switch_to_default_content(encloser)
  value
end

#will_prompt(response, encloser = nil, &block) ⇒ Object

Platform method to handle a prompt message box.



131
132
133
134
135
136
137
138
139
# File 'lib/symbiont/platform_watir/platform_object.rb', line 131

def will_prompt(response, encloser=nil, &block)
  switch_to_frame(encloser)
  @browser.wd.execute_script("window.prompt = function(text, value) { window.__lastWatirPrompt = { message: text, default_value: value }; return #{!!response}; }")
  yield
  result = @browser.wd.execute_script("return window.__lastWatirPrompt")
  switch_to_default_content(encloser)
  result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
  result
end

#within_frame(locator, encloser = nil, &block) ⇒ Object



82
83
84
85
86
# File 'lib/symbiont/platform_watir/platform_object.rb', line 82

def within_frame(locator, encloser=nil, &block)
  encloser = [] if encloser.nil?
  encloser << locator
  block.call(encloser)
end

#within_window(locator, &block) ⇒ Object

Platform method to reference web objects in the context of a window.



77
78
79
80
# File 'lib/symbiont/platform_watir/platform_object.rb', line 77

def within_window(locator, &block)
  identifier = {locator.keys.first => /#{Regexp.escape(locator.values.first)}/}
  @browser.window(identifier).use(&block)
end