Module: Druid
- Includes:
- Assist, ElementLocators, PagePopulator
- Defined in:
- lib/druid.rb,
lib/druid/assist.rb,
lib/druid/elements.rb,
lib/druid/accessors.rb,
lib/druid/elements/div.rb,
lib/druid/page_factory.rb,
lib/druid/elements/form.rb,
lib/druid/elements/link.rb,
lib/druid/elements/span.rb,
lib/druid/elements/image.rb,
lib/druid/elements/table.rb,
lib/druid/page_populator.rb,
lib/druid/elements/button.rb,
lib/druid/elements/option.rb,
lib/druid/nested_elements.rb,
lib/druid/element_locators.rb,
lib/druid/elements/element.rb,
lib/druid/elements/heading.rb,
lib/druid/elements/check_box.rb,
lib/druid/elements/list_item.rb,
lib/druid/elements/paragraph.rb,
lib/druid/elements/table_row.rb,
lib/druid/elements/text_area.rb,
lib/druid/elements/file_field.rb,
lib/druid/elements/table_cell.rb,
lib/druid/elements/text_field.rb,
lib/druid/elements/select_list.rb,
lib/druid/elements/hidden_field.rb,
lib/druid/elements/ordered_list.rb,
lib/druid/elements/radio_button.rb,
lib/druid/elements/unordered_list.rb
Overview
set of methods that provide access to the elements on the web pages.
Defined Under Namespace
Modules: Accessors, Assist, ElementLocators, Elements, NestedElements, PageFactory, PagePopulator
Instance Attribute Summary collapse
-
#driver ⇒ Watir::Browser
readonly
include Watir::AlertHelper.
Class Method Summary collapse
Instance Method Summary collapse
-
#alert(&block) ⇒ String
Override the normal alert popup so it does not occurr.
-
#attach_to_window(identifier, &block) ⇒ Object
Attach to a running window.
-
#back ⇒ Object
Go back to the previous page.
-
#call_block(&block) ⇒ Object
def switch_to_frame(frame_identifiers) unless frame_identifiers.nil? frame_identifiers.each do |frame| frame_id = frame.values.first value = frame_id.values.first driver.wd.switch_to.frame(value) end end end.
-
#clear_cookies ⇒ Object
Clear the cookies from the browser.
-
#confirm(response, &block) ⇒ String
Override the normal confirm popup so it does not occurr.
-
#current_url ⇒ Object
get the current page url.
-
#forward ⇒ Object
Go forward to the next page.
-
#html ⇒ Object
Returns the html of the current page.
-
#in_frame(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame or iframe.
-
#in_iframe(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame or iframe.
-
#initialize(driver, visit = false) ⇒ Object
Construct a new druid.
-
#modal_dialog(&block) ⇒ Object
Override the normal showModalDialog call is it opens a window instead of a dialog.
-
#navigate_to(url) ⇒ Object
navigate to the provided url.
-
#prompt(answer, &block) ⇒ String
Override the normal prompt popup so it does not occurr.
-
#refresh ⇒ Object
Refresh current page.
-
#save_screenshot(file_name) ⇒ Object
Save the current screenshot to the provided path.
-
#text ⇒ Object
Returns the text of the current page.
-
#title ⇒ Object
Returns the title of the current page.
-
#wait_until(timeout = 30, message = nil, &block) ⇒ Object
Wait until the block returns true or times out.
Methods included from PagePopulator
Methods included from ElementLocators
#button_element, #cell_element, #checkbox_element, #div_element, #file_field_element, #form_element, #h1_element, #h2_element, #h3_element, #h4_element, #h5_element, #h6_element, #hidden_field_element, #image_element, #link_element, #list_item_element, #ordered_list_element, #paragraph_element, #radio_button_element, #select_list_element, #span_element, #table_element, #text_area_element, #text_field_element, #unordered_list_element
Methods included from Assist
#button_for, #cell_for, #cell_text_for, #check_checkbox, #checkbox_checked?, #checkbox_for, #clear_radio, #click_button_for, #click_link_for, #div_for, #div_text_for, #file_field_for, #file_field_value_set, #form_for, #h1_for, #h1_text_for, #h2_for, #h2_text_for, #h3_for, #h3_text_for, #h4_for, #h4_text_for, #h5_for, #h5_text_for, #h6_for, #h6_text_for, #hidden_field_for, #hidden_field_value_for, #image_for, #link_for, #list_item_for, #list_item_text_for, #ordered_list_for, #paragraph_for, #paragraph_text_for, #radio_button_for, #radio_selected?, #select_list_for, #select_list_value_for, #select_list_value_set, #select_radio, #span_for, #span_text_for, #table_for, #text_area_for, #text_area_value_for, #text_area_value_set, #text_field_for, #text_field_value_for, #text_field_value_set, #uncheck_checkbox, #unordered_list_for
Instance Attribute Details
#driver ⇒ Watir::Browser (readonly)
include Watir::AlertHelper
43 44 45 |
# File 'lib/druid.rb', line 43 def driver @driver end |
Class Method Details
.included(cls) ⇒ Object
62 63 64 |
# File 'lib/druid.rb', line 62 def self.included(cls) cls.extend Druid::Accessors end |
Instance Method Details
#alert(&block) ⇒ String
Override the normal alert popup so it does not occurr.
150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/druid.rb', line 150 def alert(&block) # switch_to_frame(frame) yield value = nil if driver.alert.exists? value = driver.alert.text driver.alert.ok end # switch_to_default_content(frame) value end |
#attach_to_window(identifier, &block) ⇒ Object
Attach to a running window. You can locate the window using either the window’s title or url or index, If it failes to connect to a window it will pause for 1 second and try again.
be the entire url - it can just be the page name like index.html
218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/druid.rb', line 218 def attach_to_window(identifier, &block) if identifier.keys.first == :url win_id = {identifier.keys.first => /#{Regexp.escape(identifier.values.first)}/} else win_id = {identifier.keys.first => identifier.values.first} end begin driver.window(win_id).use &block rescue sleep 1 driver.window(win_id).use &block end end |
#back ⇒ Object
Go back to the previous page
113 114 115 |
# File 'lib/druid.rb', line 113 def back driver.back end |
#call_block(&block) ⇒ Object
def switch_to_frame(frame_identifiers)
unless frame_identifiers.nil?
frame_identifiers.each do |frame|
frame_id = frame.values.first
value = frame_id.values.first
driver.wd.switch_to.frame(value)
end
end
end
324 325 326 |
# File 'lib/druid.rb', line 324 def call_block(&block) block.arity == 1 ? block.call(self) : self.instance_eval(&block) end |
#clear_cookies ⇒ Object
Clear the cookies from the browser
259 260 261 |
# File 'lib/druid.rb', line 259 def driver. end |
#confirm(response, &block) ⇒ String
Override the normal confirm popup so it does not occurr
174 175 176 177 178 179 180 181 182 |
# File 'lib/druid.rb', line 174 def confirm(response, &block) yield value = nil if driver.alert.exists? value = driver.alert.text response ? driver.alert.ok : driver.alert.close end value end |
#current_url ⇒ Object
get the current page url
78 79 80 |
# File 'lib/druid.rb', line 78 def current_url driver.url end |
#forward ⇒ Object
Go forward to the next page
120 121 122 |
# File 'lib/druid.rb', line 120 def forward driver.forward end |
#html ⇒ Object
Returns the html of the current page
92 93 94 |
# File 'lib/druid.rb', line 92 def html driver.html end |
#in_frame(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame or iframe. A frame parameter is passed to the block and must be passed to the other calls to Druid. You can nest calls to in_frame by passing the frame to the next level.
286 287 288 289 290 |
# File 'lib/druid.rb', line 286 def in_frame(identifier, frame=nil, &block) frame = [] if frame.nil? frame << {frame: identifier} block.call(frame) end |
#in_iframe(identifier, frame = nil, &block) ⇒ Object
Identify an element as existing within a frame or iframe. A frame parameter is passed to the block and must be passed to the other calls to Druid. You can nest calls to in_frame by passing the frame to the next level.
308 309 310 311 312 |
# File 'lib/druid.rb', line 308 def in_iframe(identifier, frame=nil, &block) frame = [] if frame.nil? frame << {iframe: identifier} block.call(frame) end |
#initialize(driver, visit = false) ⇒ Object
Construct a new druid. Upon initialization of the page it will call a method named initialize_page if it exists
51 52 53 54 55 56 57 58 59 |
# File 'lib/druid.rb', line 51 def initialize(driver, visit=false) if driver.is_a? Watir::Browser @driver ||= driver initialize_page if respond_to?(:initialize_page) goto if visit && respond_to?(:goto) else raise ArgumentError, "expect Watir::Browser" end end |
#modal_dialog(&block) ⇒ Object
Override the normal showModalDialog call is it opens a window instead of a dialog. You will need to attach to the new window in order to continue.
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/druid.rb', line 243 def modal_dialog(&block) script = %Q{ window.showModalDialog = function(sURL, vArguments, sFeatures) { window.dialogArguments = vArguments; modalWin = window.open(sURL, 'modal', sFeatures); return modalWin; } } driver.execute_script script yield if block_given? end |
#navigate_to(url) ⇒ Object
navigate to the provided url
71 72 73 |
# File 'lib/druid.rb', line 71 def navigate_to url driver.goto url end |
#prompt(answer, &block) ⇒ String
Override the normal prompt popup so it does not occurr
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/druid.rb', line 196 def prompt(answer, &block) yield value = nil if driver.alert.exists? value = driver.alert.text driver.alert.set answer driver.alert.ok end value end |
#refresh ⇒ Object
Refresh current page
106 107 108 |
# File 'lib/druid.rb', line 106 def refresh driver.refresh end |
#save_screenshot(file_name) ⇒ Object
Save the current screenshot to the provided path. File is saved as a png file.
266 267 268 |
# File 'lib/druid.rb', line 266 def save_screenshot(file_name) driver.screenshot.save(file_name) end |
#text ⇒ Object
Returns the text of the current page
85 86 87 |
# File 'lib/druid.rb', line 85 def text driver.text end |
#title ⇒ Object
Returns the title of the current page
99 100 101 |
# File 'lib/druid.rb', line 99 def title driver.title end |
#wait_until(timeout = 30, message = nil, &block) ⇒ Object
Wait until the block returns true or times out
135 136 137 |
# File 'lib/druid.rb', line 135 def wait_until(timeout = 30, = nil, &block) driver.wait_until(timeout, , &block) end |