Class: Fluent::Platforms::WatirWebDriver::PlatformObject

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver) ⇒ PlatformObject

Returns a new instance of PlatformObject.



8
9
10
# File 'lib/fluent/platform_watir/platform_object.rb', line 8

def initialize(driver)
  @driver = driver
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



6
7
8
# File 'lib/fluent/platform_watir/platform_object.rb', line 6

def driver
  @driver
end

Instance Method Details

#access_web_element(action, locator, value = nil) ⇒ Any

This method is called by any platform methods that require accessing a web object with the intent of manipulating it or getting information from it.

Parameters:

  • action (String)

    the driver logic to be sent to the browser

  • locator (Hash)

    the specific web object selector

  • value (String) (defaults to: nil)

    any specific information that must be sent to the web object

Returns:

  • (Any)

    the information or object returned by the action



341
342
343
344
# File 'lib/fluent/platform_watir/platform_object.rb', line 341

def access_web_element(action, locator, value=nil)
  encloser = locator.delete(:frame)
  driver.instance_eval("#{enclosed_by(encloser)}#{action}")
end

#button(locator) ⇒ Object



97
98
99
# File 'lib/fluent/platform_watir/platform_object.rb', line 97

def button(locator)
  reference_web_element('button(locator)', WebElements::Button, locator)
end

#button_click(locator) ⇒ Object



101
102
103
# File 'lib/fluent/platform_watir/platform_object.rb', line 101

def button_click(locator)
  access_web_element('button(locator).click', locator)
end

#cell(locator) ⇒ Object Also known as: td



229
230
231
# File 'lib/fluent/platform_watir/platform_object.rb', line 229

def cell(locator)
  reference_web_element('td(locator)', WebElements::Cell, locator)
end

#cell_text(locator) ⇒ Object



233
234
235
# File 'lib/fluent/platform_watir/platform_object.rb', line 233

def cell_text(locator)
  access_web_element('td(locator).text', locator)
end

#checkbox(locator) ⇒ Object



129
130
131
# File 'lib/fluent/platform_watir/platform_object.rb', line 129

def checkbox(locator)
  reference_web_element('checkbox(locator)', WebElements::CheckBox, locator)
end

#checkbox_check(locator) ⇒ Object



137
138
139
# File 'lib/fluent/platform_watir/platform_object.rb', line 137

def checkbox_check(locator)
  access_web_element('checkbox(locator).set', locator)
end

#checkbox_check_state(locator) ⇒ Object



133
134
135
# File 'lib/fluent/platform_watir/platform_object.rb', line 133

def checkbox_check_state(locator)
  access_web_element('checkbox(locator).set?', locator)
end

#checkbox_uncheck(locator) ⇒ Object



141
142
143
# File 'lib/fluent/platform_watir/platform_object.rb', line 141

def checkbox_uncheck(locator)
  access_web_element('checkbox(locator).clear', locator)
end

#div(locator) ⇒ Object



181
182
183
# File 'lib/fluent/platform_watir/platform_object.rb', line 181

def div(locator)
  reference_web_element('div(locator)', WebElements::Div, locator)
end

#div_text(locator) ⇒ Object



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

def div_text(locator)
  access_web_element('div(locator).text', locator)
end

#enclosed_by(encloser) ⇒ Object



346
347
348
349
350
351
352
353
# File 'lib/fluent/platform_watir/platform_object.rb', line 346

def enclosed_by(encloser)
  return if encloser.nil?

  key = encloser[0].keys.first
  value = encloser[0].values.first
  
  "frame(:#{key} => '#{value}')."
end

#form(locator) ⇒ Object



301
302
303
# File 'lib/fluent/platform_watir/platform_object.rb', line 301

def form(locator)
  reference_web_element('form(locator)', WebElements::Form, locator)
end

#h1(locator) ⇒ Object



253
254
255
# File 'lib/fluent/platform_watir/platform_object.rb', line 253

def h1(locator)
  reference_web_element('h1(locator)', WebElements::Heading, locator)
end

#h1_text(locator) ⇒ Object



257
258
259
# File 'lib/fluent/platform_watir/platform_object.rb', line 257

def h1_text(locator)
  access_web_element('h1(locator).text', locator)
end

#h2(locator) ⇒ Object



261
262
263
# File 'lib/fluent/platform_watir/platform_object.rb', line 261

def h2(locator)
  reference_web_element('h2(locator)', WebElements::Heading, locator)
end

#h2_text(locator) ⇒ Object



265
266
267
# File 'lib/fluent/platform_watir/platform_object.rb', line 265

def h2_text(locator)
  access_web_element('h2(locator).text', locator)
end

#h3(locator) ⇒ Object



269
270
271
# File 'lib/fluent/platform_watir/platform_object.rb', line 269

def h3(locator)
  reference_web_element('h3(locator)', WebElements::Heading, locator)
end

#h3_text(locator) ⇒ Object



273
274
275
# File 'lib/fluent/platform_watir/platform_object.rb', line 273

def h3_text(locator)
  access_web_element('h3(locator).text', locator)
end

#h4(locator) ⇒ Object



277
278
279
# File 'lib/fluent/platform_watir/platform_object.rb', line 277

def h4(locator)
  reference_web_element('h4(locator)', WebElements::Heading, locator)
end

#h4_text(locator) ⇒ Object



281
282
283
# File 'lib/fluent/platform_watir/platform_object.rb', line 281

def h4_text(locator)
  access_web_element('h4(locator).text', locator)
end

#h5(locator) ⇒ Object



285
286
287
# File 'lib/fluent/platform_watir/platform_object.rb', line 285

def h5(locator)
  reference_web_element('h5(locator)', WebElements::Heading, locator)
end

#h5_text(locator) ⇒ Object



289
290
291
# File 'lib/fluent/platform_watir/platform_object.rb', line 289

def h5_text(locator)
  access_web_element('h5(locator).text', locator)
end

#h6(locator) ⇒ Object



293
294
295
# File 'lib/fluent/platform_watir/platform_object.rb', line 293

def h6(locator)
  reference_web_element('h6(locator)', WebElements::Heading, locator)
end

#h6_text(locator) ⇒ Object



297
298
299
# File 'lib/fluent/platform_watir/platform_object.rb', line 297

def h6_text(locator)
  access_web_element('h6(locator).text', locator)
end

#hidden(locator) ⇒ Object



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

def hidden(locator)
  reference_web_element('hidden(locator)', WebElements::Hidden, locator)
end

#hidden_value(locator) ⇒ Object



249
250
251
# File 'lib/fluent/platform_watir/platform_object.rb', line 249

def hidden_value(locator)
  access_web_element('hidden(locator).value', locator)
end

#image(locator) ⇒ Object Also known as: img



305
306
307
# File 'lib/fluent/platform_watir/platform_object.rb', line 305

def image(locator)
  reference_web_element('image(locator)', WebElements::Image, locator)
end

#label(locator) ⇒ Object



237
238
239
# File 'lib/fluent/platform_watir/platform_object.rb', line 237

def label(locator)
  reference_web_element('label(locator)', WebElements::Label, locator)
end

#label_text(locator) ⇒ Object



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

def label_text(locator)
  access_web_element('label(locator).text', locator)
end

Generator Actions ##



89
90
91
# File 'lib/fluent/platform_watir/platform_object.rb', line 89

def link(locator)
  reference_web_element('link(locator)', WebElements::Link, locator)
end


93
94
95
# File 'lib/fluent/platform_watir/platform_object.rb', line 93

def link_click(locator)
  access_web_element('link(locator).click', locator)
end

#list_item(locator) ⇒ Object Also known as: li



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

def list_item(locator)
  reference_web_element('li(locator)', WebElements::ListItem, locator)
end

#list_item_text(locator) ⇒ Object



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

def list_item_text(locator)
  access_web_element('li(locator).text', locator)
end

#markupObject

Page-Level Actions ##



40
41
42
# File 'lib/fluent/platform_watir/platform_object.rb', line 40

def markup
  driver.html
end

#ordered_list(locator) ⇒ Object Also known as: ol



197
198
199
# File 'lib/fluent/platform_watir/platform_object.rb', line 197

def ordered_list(locator)
  reference_web_element('ol(locator)', WebElements::OrderedList, locator)
end

#ordered_list_text(locator) ⇒ Object



201
202
203
# File 'lib/fluent/platform_watir/platform_object.rb', line 201

def ordered_list_text(locator)
  access_web_element('ol(locator).text', locator)
end

#paragraph(locator) ⇒ Object Also known as: p



173
174
175
# File 'lib/fluent/platform_watir/platform_object.rb', line 173

def paragraph(locator)
  reference_web_element('p(locator)', WebElements::Paragraph, locator)
end

#paragraph_text(locator) ⇒ Object



177
178
179
# File 'lib/fluent/platform_watir/platform_object.rb', line 177

def paragraph_text(locator)
  access_web_element('p(locator).text', locator)
end

#radio(locator) ⇒ Object Also known as: radio_button



161
162
163
# File 'lib/fluent/platform_watir/platform_object.rb', line 161

def radio(locator)
  reference_web_element('radio(locator)', WebElements::Radio, locator)
end

#radio_check_state(locator) ⇒ Object



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

def radio_check_state(locator)
  access_web_element('radio(locator).set?', locator)
end

#radio_select(locator) ⇒ Object



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

def radio_select(locator)
  access_web_element('radio(locator).set', locator)
end

#reference_web_element(action, object, locator) ⇒ Object

This method is called by any platform methods that require getting an object reference.

Parameters:

  • action (String)

    the driver logic to be sent to the browser

  • object (Object)

    the type of web object that will receive the action

  • locator (Hash)

    the specific web object selector

Returns:

  • (Object)

    the web object identified by the action



327
328
329
330
331
# File 'lib/fluent/platform_watir/platform_object.rb', line 327

def reference_web_element(action, object, locator)
  encloser = locator.delete(:frame)
  element_object = driver.instance_eval("#{enclosed_by(encloser)}#{action}")
  object.new(element_object, :platform => :watir_webdriver)
end

#refreshObject



26
27
28
# File 'lib/fluent/platform_watir/platform_object.rb', line 26

def refresh
  driver.refresh
end

#remove_cookiesObject



22
23
24
# File 'lib/fluent/platform_watir/platform_object.rb', line 22

def remove_cookies
  driver.cookies.clear
end

#run_script(script) ⇒ Object



30
31
32
# File 'lib/fluent/platform_watir/platform_object.rb', line 30

def run_script(script)
  driver.execute_script(script)
end

#screenshot(file) ⇒ Object



34
35
36
# File 'lib/fluent/platform_watir/platform_object.rb', line 34

def screenshot(file)
  driver.wd.save_screenshot(file)
end

#select_list(locator) ⇒ Object



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

def select_list(locator)
  reference_web_element('select_list(locator)', WebElements::SelectList, locator)
end

#select_list_get_selected(locator) ⇒ Object



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

def select_list_get_selected(locator)
  access_web_element('select_list(locator).selected_options[0].text', locator)
end

#select_list_get_value(locator) ⇒ Object



157
158
159
# File 'lib/fluent/platform_watir/platform_object.rb', line 157

def select_list_get_value(locator)
  access_web_element('select_list(locator).value', locator)
end

#select_list_set(locator, value) ⇒ Object



153
154
155
# File 'lib/fluent/platform_watir/platform_object.rb', line 153

def select_list_set(locator, value)
  access_web_element('select_list(locator).select(value)', locator, value)
end

#span(locator) ⇒ Object



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

def span(locator)
  reference_web_element('span(locator)', WebElements::Span, locator)
end

#span_text(locator) ⇒ Object



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

def span_text(locator)
  access_web_element('span(locator).text', locator)
end

#table(locator) ⇒ Object



221
222
223
# File 'lib/fluent/platform_watir/platform_object.rb', line 221

def table(locator)
  reference_web_element('table(locator)', WebElements::Table, locator)
end

#table_text(locator) ⇒ Object



225
226
227
# File 'lib/fluent/platform_watir/platform_object.rb', line 225

def table_text(locator)
  access_web_element('table(locator).text', locator)
end

#textObject



48
49
50
# File 'lib/fluent/platform_watir/platform_object.rb', line 48

def text
  driver.text
end

#text_area(locator) ⇒ Object Also known as: textarea



117
118
119
# File 'lib/fluent/platform_watir/platform_object.rb', line 117

def text_area(locator)
  reference_web_element('textarea(locator)', WebElements::TextArea, locator)
end

#text_area_get(locator) ⇒ Object



125
126
127
# File 'lib/fluent/platform_watir/platform_object.rb', line 125

def text_area_get(locator)
  access_web_element('textarea(locator).value', locator)
end

#text_area_set(locator, value) ⇒ Object



121
122
123
# File 'lib/fluent/platform_watir/platform_object.rb', line 121

def text_area_set(locator, value)
  access_web_element('textarea(locator).set(value)', locator, value)
end

#text_field(locator) ⇒ Object Also known as: textfield



105
106
107
# File 'lib/fluent/platform_watir/platform_object.rb', line 105

def text_field(locator)
  reference_web_element('text_field(locator)', WebElements::TextField, locator)
end

#text_field_get(locator) ⇒ Object



113
114
115
# File 'lib/fluent/platform_watir/platform_object.rb', line 113

def text_field_get(locator)
  access_web_element('text_field(locator).value', locator)
end

#text_field_set(locator, value) ⇒ Object



109
110
111
# File 'lib/fluent/platform_watir/platform_object.rb', line 109

def text_field_set(locator, value)
  access_web_element('text_field(locator).set(value)', locator, value)
end

#titleObject



44
45
46
# File 'lib/fluent/platform_watir/platform_object.rb', line 44

def title
  driver.title
end

#unordered_list(locator) ⇒ Object Also known as: ul



205
206
207
# File 'lib/fluent/platform_watir/platform_object.rb', line 205

def unordered_list(locator)
  reference_web_element('ul(locator)', WebElements::UnorderedList, locator)
end

#unordered_list_text(locator) ⇒ Object



209
210
211
# File 'lib/fluent/platform_watir/platform_object.rb', line 209

def unordered_list_text(locator)
  access_web_element('ul(locator).text', locator)
end

#urlObject



18
19
20
# File 'lib/fluent/platform_watir/platform_object.rb', line 18

def url
  driver.url
end

#visit(url) ⇒ Object

Browser-Level Actions ##



14
15
16
# File 'lib/fluent/platform_watir/platform_object.rb', line 14

def visit(url)
  driver.goto(url)
end

#wait_until(timeout, message = 'wait condition was not found', &block) ⇒ Object



52
53
54
# File 'lib/fluent/platform_watir/platform_object.rb', line 52

def wait_until(timeout, message='wait condition was not found', &block)
  driver.wait_until(timeout, message, &block)
end

#will_alert(&block) ⇒ Object

Encloser Actions ##



58
59
60
61
62
63
64
65
66
# File 'lib/fluent/platform_watir/platform_object.rb', line 58

def will_alert(&block)
  yield
  value = nil
  if driver.alert.exists?
    value = driver.alert.text
    driver.alert.ok
  end
  value
end

#will_confirm(response, &block) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'lib/fluent/platform_watir/platform_object.rb', line 68

def will_confirm(response, &block)
  yield
  value = nil
  if driver.alert.exists?
    value = driver.alert.text
    response ? driver.alert.ok : driver.alert.close
  end
  value
end

#will_prompt(response, &block) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/fluent/platform_watir/platform_object.rb', line 78

def will_prompt(response, &block)
  cmd = "window.prompt = function(text, value) {window.__lastWatirPrompt = {message: text, default_value: value}; return '#{response}';}"
  driver.wd.execute_script(cmd)
  yield
  result = driver.wd.execute_script('return window.__lastWatirPrompt')
  result && result.dup.each_key { |k| result[k.to_sym] = result.delete(k) }
  result
end