Class Celerity::Browser
In: lib/celerity/watir_compatibility.rb
lib/celerity/browser.rb
Parent: Object

Methods

Included Modules

Container XpathSupport

External Aliases

start -> start_window
  Added for Watir compatibility - not in use by Celerity

Attributes

attach_timeout  [RW]  Added for Watir compatibility - not in use by Celerity
charset  [RW] 
object  [RW] 
options  [R] 
page  [RW] 
speed  [RW]  Added for Watir compatibility - not in use by Celerity
viewer  [R] 
visible  [RW]  Added for Watir compatibility - not in use by Celerity
visible  [RW]  Added for Watir compatibility - not in use by Celerity
webclient  [R] 

Public Class methods

Added for Watir compatibility - not in use by Celerity

Creates a browser object.

@see Celerity::Container for an introduction to the main API.

@option opts :browser [:internet_explorer, :firefox, :firefox3] (:firefox3) Set the BrowserVersion used by HtmlUnit. Defaults to Firefox 3. @option opts :charset [String] ("UTF-8") Specify the charset that webclient will use for requests. @option opts :css [Boolean] (true) Enable/disable CSS. Enabled by default. @option opts :ignore_pattern [Regexp] See Browser#ignore_pattern= @option opts :javascript_enabled [Boolean] (true) Enable/disable JavaScript evaluation. Enabled by default. @option opts :javascript_exceptions [Boolean] (false) Raise exceptions on script errors. Disabled by default. @option opts :log_level [Symbol] (:warning) @see log_level= @option opts :proxy [String] (nil) Proxy server to use, in address:port format. @option opts :refresh_handler [:immediate, :waiting, :threaded] (:immediate) Set HtmlUnit‘s refresh handler. @option opts :render [:html, :xml] (:html) What DOM representation to send to connected viewers. @option opts :resynchronize [Boolean] (false) Use HtmlUnit::NicelyResynchronizingAjaxController to resynchronize Ajax calls. @option opts :secure_ssl [Boolean] (true) Enable/disable secure SSL. Enabled by default. @option opts :status_code_exceptions [Boolean] (false) Raise exceptions on failing status codes (404 etc.). Disabled by default. @option opts :user_agent [String] Override the User-Agent set by the :browser option @option opts :default_wait [Integer] The default number of seconds to wait when Browser#wait is called. @option opts :viewer [String, false] ("127.0.0.1:6429") Connect to a CelerityViewer if available.

@return [Celerity::Browser] An instance of the browser.

@api public

Initialize a browser and go to the given URL

@param [String] uri The URL to go to. @return [Celerity::Browser] instance.

Public Instance methods

Add a ‘checker’ proc that will be run on every page load

@param [Proc] checker The proc to be run (can also be given as a block) @yieldparam [Celerity::Browser] browser The current browser object. @raise [ArgumentError] if no Proc or block was given.

Add a cookie with the given parameters (Celerity only)

@param [String] domain @param [String] name @param [String] value

@option opts :path [String] ("/") A path @option opts :expires [Time] (1 day from now) An expiration date @option opts :secure [Boolean] (false)

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, message| ... }
  browser.add_listener(:alert) { |page, message| ... }
  browser.add_listener(:web_window_event) { |web_window_event| ... }
  browser.add_listener(:html_parser) { |message, url, line, column, key| ... }
  browser.add_listener(:incorrectness) { |message, origin| ... }
  browser.add_listener(:confirm) { |page, message| ...; true }
  browser.add_listener(:prompt) { |page, message| ... }

@param [Symbol] type One of the above symbols. @param [Proc] block A block to be executed for events of this type.

Check that we have a @page object.

@raise [UnknownObjectException] if no page is loaded. @api private

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.

@yieldparam [Celerity::Browser] browser The current browser object. @see Celerity::Browser#new

Goto back one history item @return [String] The url of the resulting page.

Added for Watir compatibility - not in use by Celerity

Set the maximum number of files to cache.

Clears the cache of "compiled JavaScript files and parsed CSS snippets"

Unsets the current page / closes all windows

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)

@param [Boolean] bool true to click ‘OK’, false to click ‘cancel’ @param [Proc] block A block that will trigger the confirm() call(s).

Check if the current page contains the given text.

@param [String, Regexp] expected_text The text to look for. @return [Numeric, nil] The index of the matched text, or nil if it isn‘t found. @raise [TypeError]

@return [String] content-type as in ‘text/html‘

Get the cookies for this session. (Celerity only)

@return [Hash<domain, Hash<name, value>>]

Set the credentials used for basic HTTP authentication. (Celerity only)

Example:

  browser.credentials = "username:password"

@param [String] A string with username / password, separated by a colon

Turn on/off CSS loading

@param [Bool]

Start or stop HtmlUnit‘s DebuggingWebConnection. (Celerity only) The output will go to /tmp/«name»

@param [String] name directory name @param [block] blk block to execute

Remove the given checker from the list of checkers @param [Proc] checker The Proc to disable.

Disable Celerity‘s internal WebWindowEventListener

@api private

@return [HtmlUnit::HtmlHtml] the underlying HtmlUnit document.

Enable Celerity‘s internal WebWindowEventListener

@api private

Execute the given JavaScript on the current page. @return [Object] The resulting Object

Checks if we have a page currently loaded. @return [true, false]

exists?()

Alias for exist?

Returns the element that currently has the focus (Celerity only)

Go forward one history item @return [String] The url of the resulting page.

Goto the given URL

@param [String] uri The url. @param [Hash] (optional) a Hash of HTTP headers to use for the request.

@return [String] The url.

@return [String] the HTML content of the current page

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).

@return [IO, nil] page contents as an IO, returns nil if no page is loaded.

Turn on/off JavaScript execution

@param [Bool]

Turn on/off javascript exceptions

@param [Bool]

:finest, :finer, :fine, :config, :info, :warning, :severe, or :off, :all

@return [Symbol] the current log level

Set Java log level (default is :warning, can be any of :all, :finest, :finer, :fine, :config, :info, :warning, :severe, :off)

@param [Symbol] level The new log level.

Sets the current page object for the browser

@param [HtmlUnit::HtmlPage] value The page to set. @api private

Refresh the current page

Remove the cookie with the given domain and name (Celerity only)

@param [String] domain @param [String] name

@raise [CookieNotFoundError] if the cookie doesn‘t exist

@return [Hash] response headers as a hash

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

@yieldparam [Celerity::Browser] browser The current browser object. @see Celerity::Browser#new for how to configure the browser to always use this.

Turn on/off secure SSL

@param [Bool]

experimental - should be removed?

Added for Watir compatibility - not in use by Celerity

@return [String] the value of window.status

@return [Fixnum] status code of the last request

Turn on/off status code exceptions

@param [Bool]

@return [String] a text representation of the current page

@return [String] the title of the current page

@return [String] the URL of the current page

Open the JavaScript debugger GUI

Wait for javascript jobs to finish

Wait until the given block evaluates to true (Celerity only)

@param [Fixnum] timeout Number of seconds to wait before timing out (default: 30). @yieldparam [Celerity::Browser] browser The browser instance. @see Celerity::Browser#resynchronized

Wait while the given block evaluates to true (Celerity only)

@param [Fixnum] timeout Number of seconds to wait before timing out (default: 30). @yieldparam [Celerity::Browser] browser The browser instance. @see Celerity::Browser#resynchronized

@return [String] the XML representation of the DOM

[Validate]