Class: RWebSpec::WebBrowser
- Inherits:
-
Object
- Object
- RWebSpec::WebBrowser
- Defined in:
- lib/rwebspec/web_browser.rb
Overview
Wrapping WATIR IE and FireWatir Firefox
Instance Attribute Summary collapse
-
#context ⇒ Object
Returns the value of attribute context.
Class Method Summary collapse
-
.attach_browser(how, what, options = {}) ⇒ Object
Attach to existing browser.
- .close_all_browsers(browser_type = :ie) ⇒ Object
-
.is_windows? ⇒ Boolean
is it running in MS Windows platforms?.
-
.new_from_existing(underlying_browser, web_context = nil) ⇒ Object
for popup windows.
- .reuse(base_url, options) ⇒ Object
Instance Method Summary collapse
-
#area(*args) ⇒ Object
Wrapp of Watir’s area to support Firefox and Watir.
- #base_url=(new_base_url) ⇒ Object
- #begin_at(relative_url) ⇒ Object
- #browser_opened? ⇒ Boolean
- #celerity ⇒ Object
-
#check_checkbox(checkBoxName, values = nil) ⇒ Object
Check a checkbox Usage: check_checkbox(“agree”) check_checkbox(“agree”, “true”).
-
#clear_radio_option(radio_group, radio_option) ⇒ Object
(also: #clear_radio_button)
Clear a radio button Usage: click_radio_option(“country”, “Australia”).
-
#click_button_with_caption(caption, opts = {}) ⇒ Object
(also: #click_button, #click_button_with_text)
Click a button with caption Usage: click_button_with_caption(“Confirm payment”).
-
#click_button_with_id(id, opts = {}) ⇒ Object
Click a button with give HTML id Usage: click_button_with_id(“btn_sumbit”).
-
#click_button_with_name(name, opts = {}) ⇒ Object
Click a button with give name Usage: click_button_with_name(“confirm”).
-
#click_button_with_value(value, opts = {}) ⇒ Object
Click a button with value Usage: click_button_with_value(“Confirm payment”).
-
#click_link_with_id(link_id, opts = {}) ⇒ Object
links.
- #click_link_with_text(text, opts = {}) ⇒ Object (also: #click_link)
-
#click_radio_option(radio_group, radio_option) ⇒ Object
(also: #click_radio_button)
Click a radio button Usage: click_radio_option(“country”, “Australia”).
-
#close_browser ⇒ Object
(also: #close)
Close the browser window.
- #contains_text(text) ⇒ Object
-
#dump_response(stream = nil) ⇒ Object
— For deubgging —.
-
#element(how, what) ⇒ Object
-
how - symbol - how we access the element.
-
-
#element_by_id(elem_id) ⇒ Object
Deprecated: using Watir style directly instead.
- #element_source(elementId) ⇒ Object
- #element_value(elementId) ⇒ Object
-
#elements(how, what) ⇒ Object
this is the main method for accessing generic html elements by an attribute.
-
#enter_text_into_field_with_name(name, text) ⇒ Object
(also: #set_form_element, #enter_text)
text fields.
-
#expect_page(page_clazz, argument = nil) ⇒ Object
Verify the next page following an operation.
-
#firefox ⇒ Object
return underlying firefox browser object, raise error if not running using Firefox.
- #full_url(relative_url) ⇒ Object
-
#goto_page(page) ⇒ Object
Go to a page Usage: open_browser(“www.itest2.com” .… goto_page(“/purchase”) # full url => www.itest.com/purchase.
-
#goto_url(url) ⇒ Object
Go to a URL directly goto_url(“www.itest2.com/downloads”).
-
#ie ⇒ Object
return underlying browser.
-
#initialize(base_url = nil, existing_browser = nil, options = {}) ⇒ WebBrowser
constructor
A new instance of WebBrowser.
- #initialize_celerity_browser(base_url, options) ⇒ Object
- #initialize_firefox_browser(existing_browser, base_url, options) ⇒ Object
- #initialize_ie_browser(existing_browser, options) ⇒ Object
- #is_firefox? ⇒ Boolean
-
#javascript_dialog ⇒ Object
Watir 1.9.
-
#locate_input_element(how, what, types, value = nil) ⇒ Object
Returns the specified ole object for input elements on a web page.
-
#map(how, what = nil) ⇒ Object
This is the main method for accessing map tags - msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true * how - symbol - how we access the map, * what - string, integer or regular expression - what we are looking for,.
-
#method ⇒ Object
Delegate to Watir.
- #modal_dialog(how = nil, what = nil) ⇒ Object
-
#new_popup_window(options, browser = "ie") ⇒ Object
Attach a Watir::IE instance to a popup window.
-
#page_source ⇒ Object
(also: #html_body, #html)
return HTML of current web page.
- #page_title ⇒ Object
-
#save_page(file_name = nil) ⇒ Object
Save current web page source to file usage: save_page(“/tmp/01.html”) save_page() => # will save to “20090830112200.html”.
- #select_file_for_upload(file_field, file_path) ⇒ Object
-
#select_option(selectName, option) ⇒ Object
Select a dropdown list by name Usage: select_option(“country”, “Australia”).
- #show_all_objects ⇒ Object
-
#start_clicker(button, waitTime = 9, user_input = nil) ⇒ Object
A Better Popup Handler using the latest Watir version.
- #start_window(url = nil) ⇒ Object
-
#submit(buttonName = nil) ⇒ Object
submit first submit button.
-
#text ⇒ Object
return plain text of current web page.
-
#uncheck_checkbox(checkBoxName, values = nil) ⇒ Object
Check a checkbox Usage: uncheck_checkbox(“agree”) uncheck_checkbox(“agree”, “false”).
-
#url ⇒ Object
current url.
-
#wait_before_and_after ⇒ Object
A convenience method to wait at both ends of an operation for the browser to catch up.
-
#wait_for_browser ⇒ Object
Some browsers (i.e. IE) need to be waited on before more actions can be performed.
Constructor Details
#initialize(base_url = nil, existing_browser = nil, options = {}) ⇒ WebBrowser
Returns a new instance of WebBrowser.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/rwebspec/web_browser.rb', line 48 def initialize(base_url = nil, existing_browser = nil, = {}) = {:speed => "zippy", :visible => true, :highlight_colour => 'yellow', :close_others => true } = .merge @context = Context.new base_url if base_url case RUBY_PLATFORM when /java/i # Java, maybe firewatir or celerity puts "Ruby java platform" raise "Not supported, no FireWatir or Celerity detected" unless $firewatir_loaded || $celerity_loaded if $firewatir_loaded && $celerity_loaded then # choose one out of two, :default to celerity if [:firefox] then initialize_firefox_browser(existing_browser, base_url, ) else initialize_celerity_browser(base_url, ) end elsif $firewatir_loaded initialize_firefox_browser(existing_browser, base_url, ) else initialize_celerity_browser(base_url, ) end when /mswin|windows|mingw/i raise "Not supported, no Watir or FireWatir detected" unless $watir_loaded || $firewatir_loaded if $firewatir_loaded && [:firefox] then initialize_firefox_browser(existing_browser, base_url, ) else initialize_ie_browser(existing_browser, ) end else raise "Not supported, no FireWatirdetected" unless $firewatir_loaded initialize_firefox_browser(existing_browser, base_url, ) end end |
Instance Attribute Details
#context ⇒ Object
Returns the value of attribute context.
46 47 48 |
# File 'lib/rwebspec/web_browser.rb', line 46 def context @context end |
Class Method Details
.attach_browser(how, what, options = {}) ⇒ Object
Attach to existing browser
Usage:
WebBrowser.attach_browser(:title, "iTest2")
WebBrowser.attach_browser(:url, "http://www.itest2.com")
WebBrowser.attach_browser(:url, "http://www.itest2.com", {:browser => "Firefox", :base_url => "http://www.itest2.com"})
WebBrowser.attach_browser(:title, /agileway\.com\.au\/attachment/) # regular expression
600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/rwebspec/web_browser.rb', line 600 def self.attach_browser(how, what, ={}) = {:browser => "IE"} = .merge() site_context = Context.new([:base_url]) if [:base_url] if ([:browser] == "Firefox") ff = FireWatir::Firefox.attach(how, what) return WebBrowser.new_from_existing(ff, site_context) else return WebBrowser.new_from_existing(Watir::IE.attach(how, what), site_context) end end |
.close_all_browsers(browser_type = :ie) ⇒ Object
331 332 333 334 335 336 337 338 |
# File 'lib/rwebspec/web_browser.rb', line 331 def self.close_all_browsers(browser_type = :ie) if browser_type == :ie Watir::IE.close_all elsif browser_type == :firefox # raise "not supported in FireFox yet." FireWatir::Firefox.new.close_all end end |
.is_windows? ⇒ Boolean
is it running in MS Windows platforms?
700 701 702 |
# File 'lib/rwebspec/web_browser.rb', line 700 def self.is_windows? RUBY_PLATFORM.downcase.include?("mswin") or RUBY_PLATFORM.downcase.include?("mingw") end |
.new_from_existing(underlying_browser, web_context = nil) ⇒ Object
for popup windows
159 160 161 |
# File 'lib/rwebspec/web_browser.rb', line 159 def self.new_from_existing(, web_context = nil) return WebBrowser.new(web_context ? web_context.base_url : nil, , {:close_others => false}) end |
.reuse(base_url, options) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/rwebspec/web_browser.rb', line 146 def self.reuse(base_url, ) if self.is_windows? && $ITEST2_BROWSER != "Firefox" Watir::IE.each do |browser_window| return WebBrowser.new(base_url, browser_window, ) end #puts "no browser instance found" WebBrowser.new(base_url, nil, ) else WebBrowser.new(base_url, nil, ) end end |
Instance Method Details
#area(*args) ⇒ Object
Wrapp of Watir’s area to support Firefox and Watir
Note: FireWatir does not support area directly, treat it as text_field
179 180 181 182 183 184 185 |
# File 'lib/rwebspec/web_browser.rb', line 179 def area(*args) if is_firefox? text_field(*args) else @browser.send("area", *args) end end |
#base_url=(new_base_url) ⇒ Object
299 300 301 302 303 304 305 |
# File 'lib/rwebspec/web_browser.rb', line 299 def base_url=(new_base_url) if @context @conext.base_url = new_base_url return end @context = Context.new base_url end |
#begin_at(relative_url) ⇒ Object
348 349 350 |
# File 'lib/rwebspec/web_browser.rb', line 348 def begin_at(relative_url) @browser.goto full_url(relative_url) end |
#browser_opened? ⇒ Boolean
352 353 354 355 356 357 358 |
# File 'lib/rwebspec/web_browser.rb', line 352 def browser_opened? begin @browser != nil rescue => e return false end end |
#celerity ⇒ Object
671 672 673 674 |
# File 'lib/rwebspec/web_browser.rb', line 671 def celerity raise "can't call this as it is configured to use Celerity" unless RUBY_PLATFORM =~ /java/ @browser end |
#check_checkbox(checkBoxName, values = nil) ⇒ Object
Check a checkbox Usage:
check_checkbox("agree")
check_checkbox("agree", "true")
508 509 510 511 512 513 514 515 516 517 |
# File 'lib/rwebspec/web_browser.rb', line 508 def check_checkbox(checkBoxName, values=nil) if values values.class == Array ? arys = values : arys = [values] arys.each {|cbx_value| checkbox(:name, checkBoxName, cbx_value).set } else checkbox(:name, checkBoxName).set end end |
#clear_radio_option(radio_group, radio_option) ⇒ Object Also known as:
Clear a radio button
Usage:
click_radio_option("country", "Australia")
546 547 548 |
# File 'lib/rwebspec/web_browser.rb', line 546 def clear_radio_option(radio_group, radio_option) radio(:name, radio_group, radio_option).clear end |
#click_button_with_caption(caption, opts = {}) ⇒ Object Also known as: ,
Click a button with caption Usage:
("Confirm payment")
463 464 465 466 467 468 469 |
# File 'lib/rwebspec/web_browser.rb', line 463 def (caption, opts={}) if opts && opts[:index] wait_before_and_after { (:caption => caption, :index => opts[:index]).click } else wait_before_and_after { (:caption, caption).click } end end |
#click_button_with_id(id, opts = {}) ⇒ Object
Click a button with give HTML id Usage:
("btn_sumbit")
441 442 443 444 445 446 447 |
# File 'lib/rwebspec/web_browser.rb', line 441 def (id, opts = {}) if opts && opts[:index] wait_before_and_after { (:id => id, :index => opts[:index]).click } else wait_before_and_after { (:id, id).click } end end |
#click_button_with_name(name, opts = {}) ⇒ Object
Click a button with give name Usage:
("confirm")
452 453 454 455 456 457 458 |
# File 'lib/rwebspec/web_browser.rb', line 452 def (name, opts={}) if opts && opts[:index] wait_before_and_after { (:name => name, :index => opts[:index]).click } else wait_before_and_after { (:name, name).click } end end |
#click_button_with_value(value, opts = {}) ⇒ Object
Click a button with value Usage:
("Confirm payment")
476 477 478 479 480 481 482 |
# File 'lib/rwebspec/web_browser.rb', line 476 def (value, opts={}) if opts && opts[:index] wait_before_and_after { (:value => value, :index => opts[:index]).click } else wait_before_and_after { (:value, value).click } end end |
#click_link_with_id(link_id, opts = {}) ⇒ Object
links
420 421 422 423 424 425 426 |
# File 'lib/rwebspec/web_browser.rb', line 420 def click_link_with_id(link_id, opts = {}) if opts && opts[:index] wait_before_and_after { link(:id => link_id, :index => opts[:index]).click } else wait_before_and_after { link(:id, link_id).click } end end |
#click_link_with_text(text, opts = {}) ⇒ Object Also known as: click_link
428 429 430 431 432 433 434 |
# File 'lib/rwebspec/web_browser.rb', line 428 def click_link_with_text(text, opts = {}) if opts && opts[:index] wait_before_and_after { link(:text => text, :index => opts[:index]).click } else wait_before_and_after { link(:text, text).click } end end |
#click_radio_option(radio_group, radio_option) ⇒ Object Also known as:
Click a radio button
Usage:
click_radio_option("country", "Australia")
538 539 540 |
# File 'lib/rwebspec/web_browser.rb', line 538 def click_radio_option(radio_group, radio_option) radio(:name, radio_group, radio_option).set end |
#close_browser ⇒ Object Also known as: close
Close the browser window. Useful for automated test suites to reduce test interaction.
318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/rwebspec/web_browser.rb', line 318 def close_browser case @browser.class.to_s when "FireWatir::Firefox" @browser.close when "Watir::IE" @browser.getIE.quit else puts "#{@browser.class} can't close, ignore" end sleep 2 end |
#contains_text(text) ⇒ Object
259 260 261 |
# File 'lib/rwebspec/web_browser.rb', line 259 def contains_text(text) @browser.contains_text(text); end |
#dump_response(stream = nil) ⇒ Object
For deubgging
633 634 635 |
# File 'lib/rwebspec/web_browser.rb', line 633 def dump_response(stream = nil) stream.nil? ? puts(page_source) : stream.puts(page_source) end |
#element(how, what) ⇒ Object
-
how - symbol - how we access the element. Supports all values except :index and :xpath
-
what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns an Watir::Element object
Typical Usage
element(:class, /foo/) # access the first element with class 'foo'. We can use a string in place of the regular expression
element(:id, "11") # access the first element that matches an id
203 204 205 |
# File 'lib/rwebspec/web_browser.rb', line 203 def element(how, what) return @browser.element(how, what) end |
#element_by_id(elem_id) ⇒ Object
Deprecated: using Watir style directly instead
552 553 554 555 556 557 558 559 560 561 |
# File 'lib/rwebspec/web_browser.rb', line 552 def element_by_id(elem_id) if is_firefox? # elem = @browser.document.getElementById(elem_id) # elem = div(:id, elem_id) || label(:id, elem_id) || button(:id, elem_id) || # span(:id, elem_id) || hidden(:id, elem_id) || link(:id, elem_id) || radio(:id, elem_id) elem = browser.element_by_xpath("//*[@id='#{elem_id}']") else elem = @browser.document.getElementById(elem_id) end end |
#element_source(elementId) ⇒ Object
573 574 575 576 577 |
# File 'lib/rwebspec/web_browser.rb', line 573 def element_source(elementId) elem = element_by_id(elementId) assert_not_nil(elem, "HTML element: #{elementId} not exists") elem.innerHTML end |
#element_value(elementId) ⇒ Object
563 564 565 566 567 568 569 570 571 |
# File 'lib/rwebspec/web_browser.rb', line 563 def element_value(elementId) if is_firefox? then elem = element_by_id(elementId) elem ? elem.invoke('innerText') : nil else elem = element_by_id(elementId) elem ? elem.invoke('innerText') : nil end end |
#elements(how, what) ⇒ Object
this is the main method for accessing generic html elements by an attribute
Returns a HTMLElements object
Typical usage:
elements(:class, 'test').each { |l| puts l.to_s } # iterate through all elements of a given attribute
elements(:alt, 'foo')[1].to_s # get the first element of a given attribute
elements(:id, 'foo').length # show how many elements are foung in the collection
217 218 219 |
# File 'lib/rwebspec/web_browser.rb', line 217 def elements(how, what) return @browser.elements(how, what) end |
#enter_text_into_field_with_name(name, text) ⇒ Object Also known as: set_form_element, enter_text
text fields
406 407 408 409 410 411 412 413 |
# File 'lib/rwebspec/web_browser.rb', line 406 def enter_text_into_field_with_name(name, text) if is_firefox? wait_before_and_after { text_field(:name, name).value = text } sleep 0.3 else wait_before_and_after { text_field(:name, name).set(text) } end end |
#expect_page(page_clazz, argument = nil) ⇒ Object
Verify the next page following an operation.
Typical usage:
browser.expect_page HomePage
691 692 693 694 695 696 697 |
# File 'lib/rwebspec/web_browser.rb', line 691 def expect_page(page_clazz, argument = nil) if argument page_clazz.new(self, argument) else page_clazz.new(self) end end |
#firefox ⇒ Object
return underlying firefox browser object, raise error if not running using Firefox
666 667 668 669 |
# File 'lib/rwebspec/web_browser.rb', line 666 def firefox raise "can't call this as it is configured to use IE" unless is_firefox? @browser end |
#full_url(relative_url) ⇒ Object
340 341 342 343 344 345 346 |
# File 'lib/rwebspec/web_browser.rb', line 340 def full_url(relative_url) if @context && @context.base_url @context.base_url + relative_url else relative_url end end |
#goto_page(page) ⇒ Object
Go to a page
Usage:
open_browser("http://www.itest2.com"
....
goto_page("/purchase") # full url => http://www.itest.com/purchase
395 396 397 |
# File 'lib/rwebspec/web_browser.rb', line 395 def goto_page(page) @browser.goto full_url(page); end |
#goto_url(url) ⇒ Object
Go to a URL directly
goto_url("http://www.itest2.com/downloads")
401 402 403 |
# File 'lib/rwebspec/web_browser.rb', line 401 def goto_url(url) @browser.goto url end |
#ie ⇒ Object
return underlying browser
660 661 662 663 |
# File 'lib/rwebspec/web_browser.rb', line 660 def ie raise "can't call this as it is configured to use Firefox" if is_firefox? @browser end |
#initialize_celerity_browser(base_url, options) ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/rwebspec/web_browser.rb', line 105 def initialize_celerity_browser(base_url, ) = { :proxy => nil, :browser => :firefox, :resynchronize => true, :log_level => :off } = .merge .each { |k, v| .delete(k) unless .keys.include?(k)} @browser = Celerity::Browser.new() @browser.goto(base_url) end |
#initialize_firefox_browser(existing_browser, base_url, options) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rwebspec/web_browser.rb', line 88 def initialize_firefox_browser(existing_browser, base_url, ) if existing_browser then @browser = existing_browser return end # JSSH is running, 9997 begin require 'net/telnet' firefox_jssh = Net::Telnet::new("Host" => "127.0.0.1", "Port" => 9997) FireWatir::Firefox.firefox_started = true rescue => e puts "The firefox brower with JSSH is not available, #{e}" sleep 1 end @browser = FireWatir::Firefox.start(base_url) end |
#initialize_ie_browser(existing_browser, options) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/rwebspec/web_browser.rb', line 113 def initialize_ie_browser(existing_browser, ) if existing_browser then @browser = existing_browser if $ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED then @browser.set_slow_speed if $ITEST2_TYPING_SPEED == 'slow' @browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast' else @browser.speed = :zippy end return end @browser = Watir::IE.new if $ITEST2_EMULATE_TYPING && $ITEST2_TYPING_SPEED then @browser.set_slow_speed if $ITEST2_TYPING_SPEED == 'slow' @browser.set_fast_speed if $ITEST2_TYPING_SPEED == 'fast' else @browser.speed = :zippy end @browser.activeObjectHighLightColor = [:highlight_colour] @browser.visible = [:visible] unless $HIDE_IE #NOTE: close_others fails if RUBY_VERSION =~ /^1\.8/ && [:close_others] then begin @browser.close_others rescue => e1 puts "Failed to close others" end else puts "close other browser instances not working yet in Ruby 1.9.1 version of Watir" end end |
#is_firefox? ⇒ Boolean
307 308 309 310 311 312 313 314 |
# File 'lib/rwebspec/web_browser.rb', line 307 def is_firefox? return false unless $firewatir_loaded begin @browser.class == FireWatir::Firefox rescue => e return false end end |
#javascript_dialog ⇒ Object
Watir 1.9
585 586 587 |
# File 'lib/rwebspec/web_browser.rb', line 585 def javascript_dialog @browser.javascript_dialog end |
#locate_input_element(how, what, types, value = nil) ⇒ Object
Returns the specified ole object for input elements on a web page.
This method is used internally by Watir and should not be used externally. It cannot be marked as private because of the way mixins and inheritance work in watir
* how - symbol - the way we look for the object. Supported values are
- :name
- :id
- :index
- :value etc
* what - string that we are looking for, ex. the name, or id tag attribute or index of the object we are looking for.
* types - what object types we will look at.
* value - used for objects that have one name, but many values. ex. radio lists and checkboxes
237 238 239 |
# File 'lib/rwebspec/web_browser.rb', line 237 def locate_input_element(how, what, types, value=nil) @browser.locate_input_element(how, what, types, value) end |
#map(how, what = nil) ⇒ Object
This is the main method for accessing map tags - msdn.microsoft.com/workshop/author/dhtml/reference/objects/map.asp?frame=true
* how - symbol - how we access the map,
* what - string, integer or regular expression - what we are looking for,
Valid values for ‘how’ are listed in the Watir Wiki - wiki.openqa.org/display/WTR/Methods+supported+by+Element
returns a map object
Typical Usage
map(:id, /list/) # access the first map that matches list.
map(:index,2) # access the second map on the page
map(:title, "A Picture") # access a map using the tooltip text. See http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/title_1.asp?frame=true
255 256 257 |
# File 'lib/rwebspec/web_browser.rb', line 255 def map(how, what=nil) @browser.map(how, what) end |
#method ⇒ Object
Delegate to Watir
167 168 169 170 171 |
# File 'lib/rwebspec/web_browser.rb', line 167 [:button, :cell, :checkbox, :div, :form, :frame, :h1, :h2, :h3, :h4, :h5, :h6, :hidden, :image, :li, :link, :map, :pre, :row, :radio, :select_list, :span, :table, :text_field, :paragraph, :file_field, :label].each do |method| define_method method do |*args| @browser.send(method, *args) end end |
#modal_dialog(how = nil, what = nil) ⇒ Object
187 188 189 |
# File 'lib/rwebspec/web_browser.rb', line 187 def modal_dialog(how=nil, what=nil) @browser.modal_dialog(how, what) end |
#new_popup_window(options, browser = "ie") ⇒ Object
Attach a Watir::IE instance to a popup window.
Typical usage
new_popup_window(:url => "http://www.google.com/a.pdf")
616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/rwebspec/web_browser.rb', line 616 def new_popup_window(, browser = "ie") if is_firefox? raise "not implemented" else if [:url] Watir::IE.attach(:url, [:url]) elsif [:title] Watir::IE.attach(:title, [:title]) else raise 'Please specify title or url of new pop up window' end end end |
#page_source ⇒ Object Also known as: html_body, html
return HTML of current web page
264 265 266 267 |
# File 'lib/rwebspec/web_browser.rb', line 264 def page_source @browser.html() #@browser.document.body end |
#page_title ⇒ Object
277 278 279 280 281 282 283 284 285 286 |
# File 'lib/rwebspec/web_browser.rb', line 277 def page_title case @browser.class.to_s when "FireWatir::Firefox" @browser.title when "Watir::IE" @browser.document.title else @browser.title end end |
#save_page(file_name = nil) ⇒ Object
Save current web page source to file
usage:
save_page("/tmp/01.html")
save_page() => # will save to "20090830112200.html"
680 681 682 683 684 |
# File 'lib/rwebspec/web_browser.rb', line 680 def save_page(file_name = nil) file_name ||= Time.now.strftime("%Y%m%d%H%M%S") + ".html" puts "about to save page: #{File.expand_path(file_name)}" if $DEBUG File.open(file_name, "w").puts page_source end |
#select_file_for_upload(file_field, file_path) ⇒ Object
579 580 581 582 |
# File 'lib/rwebspec/web_browser.rb', line 579 def select_file_for_upload(file_field, file_path) normalized_file_path = RUBY_PLATFORM.downcase.include?("mingw") ? file_path.gsub("/", "\\") : file_path file_field(:name, file_field).set(normalized_file_path) end |
#select_option(selectName, option) ⇒ Object
Select a dropdown list by name Usage:
select_option("country", "Australia")
487 488 489 |
# File 'lib/rwebspec/web_browser.rb', line 487 def select_option(selectName, option) select_list(:name, selectName).select(option) end |
#show_all_objects ⇒ Object
221 222 223 |
# File 'lib/rwebspec/web_browser.rb', line 221 def show_all_objects @browser.show_all_objects end |
#start_clicker(button, waitTime = 9, user_input = nil) ⇒ Object
A Better Popup Handler using the latest Watir version. Posted by [email protected]
wiki.openqa.org/display/WTR/FAQ#FAQ-HowdoIattachtoapopupwindow%3F
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/rwebspec/web_browser.rb', line 641 def start_clicker( , waitTime= 9, user_input=nil) # get a handle if one exists hwnd = @browser.enabled_popup(waitTime) if (hwnd) # yes there is a popup w = WinClicker.new if ( user_input ) w.setTextValueForFileNameField( hwnd, "#{user_input}" ) end # I put this in to see the text being input it is not necessary to work sleep 3 # "OK" or whatever the name on the button is w.clickWindowsButton_hwnd( hwnd, "#{button}" ) # # this is just cleanup w = nil end end |
#start_window(url = nil) ⇒ Object
589 590 591 |
# File 'lib/rwebspec/web_browser.rb', line 589 def start_window(url = nil) @browser.start_window(url); end |
#submit(buttonName = nil) ⇒ Object
submit first submit button
492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/rwebspec/web_browser.rb', line 492 def submit( = nil) if (.nil?) then .each { || next if .type != 'submit' .click return } else () end end |
#text ⇒ Object
return plain text of current web page
273 274 275 |
# File 'lib/rwebspec/web_browser.rb', line 273 def text @browser.text end |
#uncheck_checkbox(checkBoxName, values = nil) ⇒ Object
Check a checkbox Usage:
uncheck_checkbox("agree")
uncheck_checkbox("agree", "false")
523 524 525 526 527 528 529 530 531 532 |
# File 'lib/rwebspec/web_browser.rb', line 523 def uncheck_checkbox(checkBoxName, values = nil) if values values.class == Array ? arys = values : arys = [values] arys.each {|cbx_value| checkbox(:name, checkBoxName, cbx_value).clear } else checkbox(:name, checkBoxName).clear end end |
#url ⇒ Object
current url
295 296 297 |
# File 'lib/rwebspec/web_browser.rb', line 295 def url @browser.url end |
#wait_before_and_after ⇒ Object
A convenience method to wait at both ends of an operation for the browser to catch up.
374 375 376 377 378 |
# File 'lib/rwebspec/web_browser.rb', line 374 def wait_before_and_after wait_for_browser yield wait_for_browser end |
#wait_for_browser ⇒ Object
Some browsers (i.e. IE) need to be waited on before more actions can be performed. Most action methods in Watir::Simple already call this before and after.
363 364 365 366 367 368 369 |
# File 'lib/rwebspec/web_browser.rb', line 363 def wait_for_browser if $celerity_loaded then # puts "ignore, using celerity" else @browser.waitForIE unless is_firefox? end end |