Class: Celerity::Browser
- Inherits:
- Object
- Includes:
- Celerity::Container, Celerity::XpathSupport
- Defined in:
- lib/celerity/browser.rb,
lib/celerity/watir_compatibility.rb
Overview
Browser
Attribute Summary
- + (Object) attach_timeout Added for Watir compatibility - not in use by Celerity.
- + (Object) speed Added for Watir compatibility - not in use by Celerity.
- + (Object) visible Added for Watir compatibility - not in use by Celerity.
- - (Object) charset Returns the value of attribute charset.
- - (Object) object Returns the value of attribute object.
- - (Object) options readonly Returns the value of attribute options.
- - (Object) page Returns the value of attribute page.
- - (Object) viewer readonly Returns the value of attribute viewer.
- - (Object) visible Added for Watir compatibility - not in use by Celerity.
- - (Object) webclient readonly Returns the value of attribute webclient.
Method Summary
- + (Object) attach(*args) Not implemented.
- + (Object) each Added for Watir compatibility - not in use by Celerity.
- + (Celerity::Browser) start(uri) (also: start_window) Initialize a browser and go to the given URL.
- - (Object) add_checker(checker = nil, &block) {|browser| ... } Add a ‘checker’ proc that will be run on every page load.
- - (Object) add_cookie(domain, name, value, opts = {}) Add a cookie with the given parameters (Celerity only).
- - (Object) add_listener(type, &block) Add a listener block for one of the available types.
- - (Object) assert_exists Check that we have a @page object.
- - (Object) asynchronized(&block) {|browser| ... } Allows you to temporarliy switch to HtmlUnit’s default AjaxController, so ajax calls are performed asynchronously.
- - (String) back Goto back one history item.
- - (Object) bring_to_front Added for Watir compatibility - not in use by Celerity.
- - (Object) clear_cache Clears the cache of “compiled JavaScript files and parsed CSS snippets”.
- - (Object) clear_cookies Clears all cookies.
- - (Object) close Unsets the current page / closes all windows.
- - (Object) confirm(bool, &block) Specify a boolean value to click either ‘OK’ or ‘Cancel’ in any confirm dialogs that might show up during the duration of the given block.
- - (Numeric) contains_text(expected_text) Check if the current page contains the given text.
- - (String) content_type Content-type as in ‘text/html’.
- - (Hash<domain, Hash<name, value>>) cookies Get the cookies for this session.
- - (Object) credentials=(string) Set the credentials used for basic HTTP authentication.
- - (Object) css
- - (Object) css=(bool) Turn on/off CSS loading.
- - (Object) debug_web_connection(name, &blk) Start or stop HtmlUnit’s DebuggingWebConnection.
- - (Object) disable_checker(checker) Remove the given checker from the list of checkers.
- - (Object) disable_event_listener Disable Celerity’s internal WebWindowEventListener.
- - (HtmlUnit::HtmlHtml) document The underlying HtmlUnit document.
- - (Object) enable_event_listener Enable Celerity’s internal WebWindowEventListener.
- - (Object) execute_script(source) Execute the given JavaScript on the current page.
- - (true) exist? (also: #exists?) Checks if we have a page currently loaded.
- - (Object) focused_element Returns the element that currently has the focus (Celerity only).
- - (String) forward Go forward one history item.
- - (String) goto(uri) Goto the given URL.
- - (String) html The HTML content of the current page.
- - (Object) ignore_pattern=(regexp) If a request is made to an URL that matches the pattern set here, Celerity will ignore the request and return an empty page with content type “text/html” instead.
- - (Celerity::Browser) initialize(opts = {}) Creates a browser object.
- - (Object) inspect
- - (IO) io Page contents as an IO, returns nil if no page is loaded.
- - (Object) javascript_enabled
- - (Object) javascript_enabled=(bool) Turn on/off JavaScript execution.
- - (Object) javascript_exceptions
- - (Object) javascript_exceptions=(bool) Turn on/off javascript exceptions.
- - (Symbol) log_level :finest, :finer, :fine, :config, :info, :warning, :severe, or :off, :all.
- - (Object) log_level=(level) Set Java log level (default is :warning, can be any of :all, :finest, :finer, :fine, :config, :info, :warning, :severe, :off).
- - (Object) refresh Refresh the current page.
- - (Object) refresh_handler=(symbol)
- - (Object) remove_cookie(domain, name) Remove the cookie with the given domain and name (Celerity only).
- - (Object) remove_listener(type, block)
- - (Hash) response_headers Response headers as a hash.
- - (Object) resynchronized(&block) {|browser| ... } Allows you to temporarily switch to HtmlUnit’s NicelyResynchronizingAjaxController to resynchronize ajax calls.
- - (Object) secure_ssl=(bool) Turn on/off secure SSL.
- - (Object) send_keys(keys) experimental - should be removed?.
- - (Object) speed=(s) Added for Watir compatibility - not in use by Celerity.
- - (String) status The value of window.status.
- - (Fixnum) status_code Status code of the last request.
- - (Object) status_code_exceptions
- - (Object) status_code_exceptions=(bool) Turn on/off status code exceptions.
- - (String) text A text representation of the current page.
- - (String) title The title of the current page.
- - (Object) trace_javascript(debugger_klass = Celerity::JavascriptDebugger, &blk)
- - (String) url The URL of the current page.
- - (Object) wait Wait for javascript jobs to finish.
- - (Object) wait_until(timeout = 30, &block) {|browser| ... } Wait until the given block evaluates to true (Celerity only).
- - (Object) wait_while(timeout = 30, &block) {|browser| ... } Wait while the given block evaluates to true (Celerity only).
- - (String) xml The XML representation of the DOM.
Methods included from Celerity::Container
#area, #areas, #button, #buttons, #cell, #cells, #check_box, #checkboxes, #container=, #dd, #dds, #div, #divs, #dl, #dls, #dt, #dts, #em, #ems, #file_field, #file_fields, #form, #forms, #frame, #frames, #h1, #h1s, #h2, #h2s, #h3, #h3s, #h4, #h4s, #h5, #h5s, #h6, #h6s, #hidden, #hiddens, #image, #images, #label, #labels, #li, #link, #links, #lis, #map, #maps, #meta, #metas, #ol, #ols, #option, #p, #pre, #pres, #ps, #radio, #radios, #rescue_status_code_exception, #row, #rows, #select_list, #select_lists, #span, #spans, #strong, #strongs, #table, #tables, #tbodies, #tbody, #text_field, #text_fields, #tfoot, #tfoots, #th, #thead, #theads, #ths, #ul, #uls
Methods included from Celerity::ShortInspect
Methods included from Celerity::XpathSupport
#element_by_xpath, #element_from_dom_node, #elements_by_xpath
Constructor Details
- (Celerity::Browser) initialize(opts = {})
Creates a browser object.
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 |
# File 'lib/celerity/browser.rb', line 56 def initialize(opts = {}) unless opts.is_a?(Hash) raise TypeError, "wrong argument type #{opts.class}, expected Hash" end unless (render_types = [:html, :xml, nil, 'html', 'xml']).include?(opts[:render]) raise ArgumentError, "expected one of #{render_types.inspect} for key :render" end = opts.dup # keep the unmodified version around as well opts = opts.dup # we'll delete from opts, so dup to avoid side effects @render_type = opts.delete(:render) || :html @charset = opts.delete(:charset) || "UTF-8" self.log_level = opts.delete(:log_level) || :off @page = nil @error_checkers = [] @browser = self # for Container#browser setup_webclient opts setup_viewer opts.delete(:viewer) raise ArgumentError, "unknown option #{opts.inspect}" unless opts.empty? end |
Attribute Details
+ (Object) attach_timeout
Added for Watir compatibility - not in use by Celerity
6 7 8 |
# File 'lib/celerity/watir_compatibility.rb', line 6 def attach_timeout @attach_timeout end |
+ (Object) speed
Added for Watir compatibility - not in use by Celerity
6 7 8 |
# File 'lib/celerity/watir_compatibility.rb', line 6 def speed @speed end |
+ (Object) visible
Added for Watir compatibility - not in use by Celerity
6 7 8 |
# File 'lib/celerity/watir_compatibility.rb', line 6 def visible @visible end |
- (Object) charset
Returns the value of attribute charset
6 7 8 |
# File 'lib/celerity/browser.rb', line 6 def charset @charset end |
- (Object) object
Returns the value of attribute object
6 7 8 |
# File 'lib/celerity/browser.rb', line 6 def object @object end |
- (Object) options (readonly)
Returns the value of attribute options
7 8 9 |
# File 'lib/celerity/browser.rb', line 7 def end |
- (Object) page
Returns the value of attribute page
6 7 8 |
# File 'lib/celerity/browser.rb', line 6 def page @page end |
- (Object) viewer (readonly)
Returns the value of attribute viewer
7 8 9 |
# File 'lib/celerity/browser.rb', line 7 def viewer @viewer end |
- (Object) visible
Added for Watir compatibility - not in use by Celerity
14 15 16 |
# File 'lib/celerity/watir_compatibility.rb', line 14 def visible @visible end |
- (Object) webclient (readonly)
Returns the value of attribute webclient
7 8 9 |
# File 'lib/celerity/browser.rb', line 7 def webclient @webclient end |
Method Details
+ (Object) attach(*args)
Not implemented. Use ClickableElement#click_and_attach instead.
26 27 28 |
# File 'lib/celerity/browser.rb', line 26 def self.attach(*args) raise NotImplementedError, "use ClickableElement#click_and_attach instead" end |
+ (Object) each
Added for Watir compatibility - not in use by Celerity
10 |
# File 'lib/celerity/watir_compatibility.rb', line 10 def each; end |
+ (Celerity::Browser) start(uri) Also known as: start_window
Initialize a browser and go to the given URL
16 17 18 19 20 |
# File 'lib/celerity/browser.rb', line 16 def self.start(uri) browser = new browser.goto(uri) browser end |
- (Object) add_checker(checker = nil, &block) {|browser| ... }
Add a ‘checker’ proc that will be run on every page load
562 563 564 565 566 567 568 569 570 |
# File 'lib/celerity/browser.rb', line 562 def add_checker(checker = nil, &block) if block_given? @error_checkers << block elsif Proc === checker @error_checkers << checker else raise ArgumentError, "argument must be a Proc or block" end end |
- (Object) add_cookie(domain, name, value, opts = {})
Add a cookie with the given parameters (Celerity only)
340 341 342 343 344 345 346 347 348 349 350 351 |
# File 'lib/celerity/browser.rb', line 340 def (domain, name, value, opts = {}) path = opts.delete(:path) || "/" max_age = opts.delete(:expires) || (Time.now + 60*60*24) # not sure if this is correct secure = opts.delete(:secure) || false raise(ArgumentError, "unknown option: #{opts.inspect}") unless opts.empty? = HtmlUnit::Util::Cookie.new(domain, name, value, path, max_age, secure) @webclient.getCookieManager.addCookie end |
- (Object) add_listener(type, &block)
Add a listener block for one of the available types. (Celerity only) Types map to HtmlUnit interfaces like this:
:status => StatusHandler :alert => AlertHandler ( window.alert() ) :web_window_event => WebWindowListener :html_parser => HTMLParserListener :incorrectness => IncorrectnessListener :confirm => ConfirmHandler ( window.confirm() ) :prompt => PromptHandler ( window.prompt() )
Examples:
browser.add_listener(:status) { |page, | ... } browser.add_listener(:alert) { |page, | ... } browser.add_listener(:web_window_event) { |web_window_event| ... } browser.add_listener(:html_parser) { |, url, line, column, key| ... } browser.add_listener(:incorrectness) { |, origin| ... } browser.add_listener(:confirm) { |page, | ...; true } browser.add_listener(:prompt) { |page, | ... }
528 529 530 |
# File 'lib/celerity/browser.rb', line 528 def add_listener(type, &block) listener.add_listener(type, &block) end |
- (Object) assert_exists
Check that we have a @page object.
745 746 747 |
# File 'lib/celerity/browser.rb', line 745 def assert_exists raise UnknownObjectException, "no page loaded" unless exist? end |
- (Object) asynchronized(&block) {|browser| ... }
Allows you to temporarliy switch to HtmlUnit’s default AjaxController, so ajax calls are performed asynchronously. This is useful if you have created the Browser with :resynchronize => true, but want to switch it off temporarily.
469 470 471 472 473 474 |
# File 'lib/celerity/browser.rb', line 469 def asynchronized(&block) old_controller = @webclient.ajaxController @webclient.setAjaxController(::HtmlUnit::AjaxController.new) yield self @webclient.setAjaxController(old_controller) end |
- (String) back
Goto back one history item
258 259 260 261 262 263 |
# File 'lib/celerity/browser.rb', line 258 def back @webclient.getCurrentWindow.getHistory.back refresh_page_from_window url end |
- (Object) bring_to_front
Added for Watir compatibility - not in use by Celerity
17 |
# File 'lib/celerity/watir_compatibility.rb', line 17 def bring_to_front; true end |
- (Object) clear_cache
Clears the cache of “compiled JavaScript files and parsed CSS snippets“
307 308 309 |
# File 'lib/celerity/browser.rb', line 307 def clear_cache @webclient.cache.clear end |
- (Object) clear_cookies
Clears all cookies. (Celerity only)
299 300 301 |
# File 'lib/celerity/browser.rb', line 299 def @webclient.getCookieManager.clearCookies end |
- (Object) close
Unsets the current page / closes all windows
126 127 128 129 130 |
# File 'lib/celerity/browser.rb', line 126 def close @page = nil @webclient.closeAllWindows @viewer.close end |
- (Object) confirm(bool, &block)
Specify a boolean value to click either ‘OK’ or ‘Cancel’ in any confirm dialogs that might show up during the duration of the given block.
(Celerity only)
546 547 548 549 550 551 552 |
# File 'lib/celerity/browser.rb', line 546 def confirm(bool, &block) blk = lambda { bool } listener.add_listener(:confirm, &blk) yield listener.remove_listener(:confirm, blk) end |
- (Numeric) contains_text(expected_text)
Check if the current page contains the given text.
240 241 242 243 |
# File 'lib/celerity/browser.rb', line 240 def contains_text(expected_text) return nil unless exist? super end |
- (String) content_type
Content-type as in ‘text/html’
216 217 218 219 220 |
# File 'lib/celerity/browser.rb', line 216 def content_type return '' unless @page @page.getWebResponse.getContentType end |
- (Hash<domain, Hash<name, value>>) cookies
Get the cookies for this session. (Celerity only)
317 318 319 320 321 322 323 324 325 326 |
# File 'lib/celerity/browser.rb', line 317 def result = Hash.new { |hash, key| hash[key] = {} } = @webclient.getCookieManager.getCookies .each do || result[.getDomain][.getName] = .getValue end result end |
- (Object) credentials=(string)
Set the credentials used for basic HTTP authentication. (Celerity only)
Example:
browser.credentials = "username:password"
115 116 117 118 119 120 |
# File 'lib/celerity/browser.rb', line 115 def credentials=(string) user, pass = string.split(":") dcp = HtmlUnit::DefaultCredentialsProvider.new dcp.addCredentials(user, pass) @webclient.setCredentialsProvider(dcp) end |
- (Object) css
672 673 674 |
# File 'lib/celerity/browser.rb', line 672 def css @webclient.cssEnabled end |
- (Object) css=(bool)
Turn on/off CSS loading
668 669 670 |
# File 'lib/celerity/browser.rb', line 668 def css=(bool) @webclient.cssEnabled = bool end |
- (Object) debug_web_connection(name, &blk)
Start or stop HtmlUnit’s DebuggingWebConnection. (Celerity only) The output will go to /tmp/«name»
484 485 486 487 488 489 490 491 492 |
# File 'lib/celerity/browser.rb', line 484 def debug_web_connection(name, &blk) old_wc = @webclient.getWebConnection @webclient.setWebConnection HtmlUnit::Util::DebuggingWebConnection.new(old_wc, name) res = yield @webclient.setWebConnection old_wc res end |
- (Object) disable_checker(checker)
Remove the given checker from the list of checkers
577 578 579 |
# File 'lib/celerity/browser.rb', line 577 def disable_checker(checker) @error_checkers.delete(checker) end |
- (Object) disable_event_listener
Disable Celerity’s internal WebWindowEventListener
777 778 779 780 781 782 783 784 785 786 |
# File 'lib/celerity/browser.rb', line 777 def disable_event_listener listener.remove_listener(:web_window_event, @event_listener) if block_given? result = yield enable_event_listener result end end |
- (HtmlUnit::HtmlHtml) document
The underlying HtmlUnit document.
249 250 251 |
# File 'lib/celerity/browser.rb', line 249 def document @object end |
- (Object) enable_event_listener
Enable Celerity’s internal WebWindowEventListener
763 764 765 766 767 768 769 |
# File 'lib/celerity/browser.rb', line 763 def enable_event_listener @event_listener ||= lambda do |event| self.page = @page ? @page.getEnclosingWindow.getEnclosedPage : event.getNewPage end listener.add_listener(:web_window_event, &@event_listener) end |
- (Object) execute_script(source)
Execute the given JavaScript on the current page.
378 379 380 381 |
# File 'lib/celerity/browser.rb', line 378 def execute_script(source) assert_exists @page.executeJavaScript(source.to_s).getJavaScriptResult end |
- (true) exist? Also known as: exists?
Checks if we have a page currently loaded.
629 630 631 |
# File 'lib/celerity/browser.rb', line 629 def exist? !!@page end |
- (Object) focused_element
Returns the element that currently has the focus (Celerity only)
753 754 755 |
# File 'lib/celerity/browser.rb', line 753 def focused_element element_from_dom_node(page.getFocusedElement()) end |
- (String) forward
Go forward one history item
270 271 272 273 274 275 |
# File 'lib/celerity/browser.rb', line 270 def forward @webclient.getCurrentWindow.getHistory.forward refresh_page_from_window url end |
- (String) goto(uri)
Goto the given URL
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/celerity/browser.rb', line 93 def goto(uri) uri = "http://#{uri}" unless uri =~ %r{://} request = HtmlUnit::WebRequestSettings.new(::Java::JavaNet::URL.new(uri)) request.setCharset(@charset) rescue_status_code_exception do self.page = @webclient.getPage(request) end url() end |
- (String) html
The HTML content of the current page
161 162 163 |
# File 'lib/celerity/browser.rb', line 161 def html @page ? @page.getWebResponse.getContentAsString(@charset) : '' end |
- (Object) ignore_pattern=(regexp)
If a request is made to an URL that matches the pattern set here, Celerity will ignore the request and return an empty page with content type “text/html” instead.
This is useful to block unwanted requests (like ads/banners).
616 617 618 619 620 621 622 |
# File 'lib/celerity/browser.rb', line 616 def ignore_pattern=(regexp) unless regexp.kind_of?(Regexp) raise TypeError, "expected Regexp, got #{regexp.inspect}:#{regexp.class}" end Celerity::IgnoringWebConnection.new(@webclient, regexp) end |
- (Object) inspect
82 83 84 |
# File 'lib/celerity/browser.rb', line 82 def inspect short_inspect :exclude => %w[@webclient @browser @object @options @listener @event_listener] end |
- (IO) io
Page contents as an IO, returns nil if no page is loaded.
226 227 228 229 230 |
# File 'lib/celerity/browser.rb', line 226 def io return nil unless @page @page.getWebResponse.getContentAsStream.to_io end |
- (Object) javascript_enabled
711 712 713 |
# File 'lib/celerity/browser.rb', line 711 def javascript_enabled @webclient.isJavaScriptEnabled end |
- (Object) javascript_enabled=(bool)
Turn on/off JavaScript execution
707 708 709 |
# File 'lib/celerity/browser.rb', line 707 def javascript_enabled=(bool) @webclient.setJavaScriptEnabled(bool) end |
- (Object) javascript_exceptions
644 645 646 |
# File 'lib/celerity/browser.rb', line 644 def javascript_exceptions @webclient.throwExceptionOnScriptError end |
- (Object) javascript_exceptions=(bool)
Turn on/off javascript exceptions
640 641 642 |
# File 'lib/celerity/browser.rb', line 640 def javascript_exceptions=(bool) @webclient.throwExceptionOnScriptError = bool end |
- (Symbol) log_level
:finest, :finer, :fine, :config, :info, :warning, :severe, or :off, :all
587 588 589 |
# File 'lib/celerity/browser.rb', line 587 def log_level Celerity::Util.logger_for('com.gargoylesoftware.htmlunit').level.to_s.downcase.to_sym end |
- (Object) log_level=(level)
Set Java log level (default is :warning, can be any of :all, :finest, :finer, :fine, :config, :info, :warning, :severe, :off)
597 598 599 600 601 602 603 604 605 606 607 |
# File 'lib/celerity/browser.rb', line 597 def log_level=(level) log_level = java.util.logging.Level.const_get(level.to_s.upcase) [ 'com.gargoylesoftware.htmlunit', 'com.gargoylesoftware.htmlunit.html', 'com.gargoylesoftware.htmlunit.javascript', 'org.apache.commons.httpclient' ].each { |package| Celerity::Util.logger_for(package).level = log_level } level end |
- (Object) refresh
Refresh the current page
290 291 292 293 |
# File 'lib/celerity/browser.rb', line 290 def refresh assert_exists @page.refresh end |
- (Object) refresh_handler=(symbol)
676 677 678 679 680 681 682 683 684 685 686 687 688 689 |
# File 'lib/celerity/browser.rb', line 676 def refresh_handler=(symbol) handler = case symbol when :waiting HtmlUnit::WaitingRefreshHandler.new when :threaded HtmlUnit::ThreadedRefreshHandler.new when :immediate HtmlUnit::ImmediateRefreshHandler.new else raise ArgumentError, "expected :waiting, :threaded or :immediate" end @webclient.setRefreshHandler handler end |
- (Object) remove_cookie(domain, name)
Remove the cookie with the given domain and name (Celerity only)
362 363 364 365 366 367 368 369 370 371 |
# File 'lib/celerity/browser.rb', line 362 def (domain, name) cm = @webclient.getCookieManager = cm.getCookies.find { |c| c.getDomain == domain && c.getName == name } if .nil? raise CookieNotFoundError, "no cookie with domain #{domain.inspect} and name #{name.inspect}" end cm.removeCookie() end |
- (Object) remove_listener(type, block)
532 533 534 |
# File 'lib/celerity/browser.rb', line 532 def remove_listener(type, block) listener.remove_listener(type, block) end |
- (Hash) response_headers
Response headers as a hash
198 199 200 201 202 |
# File 'lib/celerity/browser.rb', line 198 def response_headers return {} unless @page Hash[*@page.getWebResponse.getResponseHeaders.map { |obj| [obj.name, obj.value] }.flatten] end |
- (Object) resynchronized(&block) {|browser| ... }
Allows you to temporarily switch to HtmlUnit’s NicelyResynchronizingAjaxController to resynchronize ajax calls.
@browser.resynchronized do |b| b.link(:id, 'trigger_ajax_call').click end
453 454 455 456 457 458 |
# File 'lib/celerity/browser.rb', line 453 def resynchronized(&block) old_controller = @webclient.ajaxController @webclient.setAjaxController(::HtmlUnit::NicelyResynchronizingAjaxController.new) yield self @webclient.setAjaxController(old_controller) end |
- (Object) secure_ssl=(bool)
Turn on/off secure SSL
697 698 699 |
# File 'lib/celerity/browser.rb', line 697 def secure_ssl=(bool) @webclient.useInsecureSSL = !bool end |
- (Object) send_keys(keys)
experimental - should be removed?
384 385 386 387 388 389 390 391 392 393 394 395 396 397 |
# File 'lib/celerity/browser.rb', line 384 def send_keys(keys) keys = keys.gsub(/\s*/, '').scan(/((?:\{[A-Z]+?\})|.)/u).flatten keys.each do |key| element = @page.getFocusedElement case key when "{TAB}" @page.tabToNextElement when /\w/ element.type(key) else raise NotImplementedError end end end |
- (Object) speed=(s)
Added for Watir compatibility - not in use by Celerity
19 |
# File 'lib/celerity/watir_compatibility.rb', line 19 def speed=(s) s end |
- (String) status
The value of window.status
153 154 155 |
# File 'lib/celerity/browser.rb', line 153 def status execute_script "window.status" # avoid the listener overhead end |
- (Fixnum) status_code
Status code of the last request
208 209 210 |
# File 'lib/celerity/browser.rb', line 208 def status_code @page.getWebResponse.getStatusCode end |
- (Object) status_code_exceptions
658 659 660 |
# File 'lib/celerity/browser.rb', line 658 def status_code_exceptions @webclient.throwExceptionOnFailingStatusCode end |
- (Object) status_code_exceptions=(bool)
Turn on/off status code exceptions
654 655 656 |
# File 'lib/celerity/browser.rb', line 654 def status_code_exceptions=(bool) @webclient.throwExceptionOnFailingStatusCode = bool end |
- (String) text
A text representation of the current page
179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/celerity/browser.rb', line 179 def text return '' unless @page if @page.respond_to?("getContent") string = @page.getContent.strip elsif doc = @page.documentElement string = doc.asText.strip else string = '' end # Celerity::Util.normalize_text(string) string end |
- (String) title
The title of the current page
145 146 147 |
# File 'lib/celerity/browser.rb', line 145 def title @page ? @page.getTitleText : '' end |
- (Object) trace_javascript(debugger_klass = Celerity::JavascriptDebugger, &blk)
494 495 496 497 498 499 |
# File 'lib/celerity/browser.rb', line 494 def trace_javascript(debugger_klass = Celerity::JavascriptDebugger, &blk) context_factory = @webclient.getJavaScriptEngine.getContextFactory context_factory.setDebugger debugger_klass.new yield context_factory.setDebugger nil end |
- (String) url
The URL of the current page
136 137 138 139 |
# File 'lib/celerity/browser.rb', line 136 def url assert_exists @page.getWebResponse.getRequestUrl.toString end |
- (Object) wait
Wait for javascript jobs to finish
281 282 283 284 |
# File 'lib/celerity/browser.rb', line 281 def wait assert_exists @webclient.waitForBackgroundJavaScript(10000) end |
- (Object) wait_until(timeout = 30, &block) {|browser| ... }
Wait until the given block evaluates to true (Celerity only)
407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/celerity/browser.rb', line 407 def wait_until(timeout = 30, &block) returned = nil Timeout.timeout(timeout) do until returned = yield(self) refresh_page_from_window sleep 0.1 end end returned end |
- (Object) wait_while(timeout = 30, &block) {|browser| ... }
Wait while the given block evaluates to true (Celerity only)
428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/celerity/browser.rb', line 428 def wait_while(timeout = 30, &block) returned = nil Timeout.timeout(timeout) do while returned = yield(self) refresh_page_from_window sleep 0.1 end end returned end |
- (String) xml
The XML representation of the DOM
169 170 171 172 173 |
# File 'lib/celerity/browser.rb', line 169 def xml return '' unless @page return @page.asXml if @page.respond_to?(:asXml) return text # fallback to text (for exampel for "plain/text" pages) end |