Jump To …

browser.coffee

Browser options you can set when creating new browser, or on browser instance.

undefined

Global options you can set on Browser and will be inherited by each new browser.

undefined

Use the browser to open up new windows and load documents.

The browser maintains state for cookies and localStorage.

undefined

Make sure we don't blow up Node when we get a JS error, but dump error to console. Also, catch any errors reported while processing resources/JavaScript.

undefined

Default (not global) options

undefined

Send this referer.

undefined

You can set the browser window.name property

undefined

Sets the browser options.

undefined

Returns all errors reported while loading this window.

undefined

Global options

undefined

True to have Zombie report what it's doing.

undefined

Which parser to use (HTML5 by default). For example: Browser.htmlParser = require("html5").HTML5 // HTML5, forgiving Browser.htmlParser = require("htmlparser") // Faster, stricter

undefined

True to load external stylesheets.

undefined

Maximum time to wait (visit, wait, etc).

undefined

Proxy URL.

Example Browser.proxy = "http://myproxy:8080" browser.visit("site", function(error, browser) { })

undefined

Run scripts included in or loaded from the page. Defaults to true.

undefined

If true, supress console.log output from scripts.

undefined

User agent string sent to server.

undefined

You can use visit with a path, and it will make a request relative to this host/URL.

undefined

Tells wait and any function that uses wait how long to wait for, executing timers. Defaults to 0.5 seconds.

undefined

Additional headers to be sent with each HTTP request

undefined

Changes the browser options, and calls the function with a callback (reset). When you're done processing, call the reset function to bring options back to their previous values.

See visit if you want to see this method in action.

undefined

Return a new browser with a snapshot of this browser's state. Any changes to the forked browser's state do not affect this browser.

undefined

Windows

undefined

Returns the currently open window

undefined

Open new browser window. Options are undocumented, use at your own peril.

undefined

browser.error => Error

Returns the last error reported while loading this window.

undefined

Events

undefined

Waits for the browser to complete loading resources and processing JavaScript events.

You can pass a callback as the last argument. Without a callback, this method returns a promise.

With duration as the first argument, this method waits for the specified time (in milliseconds) and any resource/JavaScript to complete processing. Duration can also be a function, called after each event to determine whether or not to proceed.

Without duration, Zombie makes best judgement by waiting up to 5 seconds for the page to load resources (scripts, XHR requests, iframes), process DOM events, and fire timeouts events.

undefined

Fire a DOM event. You can use this to simulate a DOM event, e.g. clicking a link. These events will bubble up and can be cancelled. Like wait this method either takes a callback or returns a promise.

name - Even name (e.g click) target - Target element (e.g a link) callback - Wait for events to be processed, then call me (optional)

undefined

Dispatch asynchronously. Returns true if preventDefault was set.

undefined

Accessors

undefined

browser.queryAll(selector, context?) => Array

Evaluates the CSS selector against the document (or context node) and return array of nodes. (Unlike document.querySelectorAll that returns a node list).

undefined

browser.query(selector, context?) => Element

Evaluates the CSS selector against the document (or context node) and return an element.

undefined

browser.querySelector(selector) => Element

Select a single element (first match) and return it.

selector - CSS selector

Returns an Element or null

undefined

browser.querySelectorAll(selector) => NodeList

Select multiple elements and return a static node list.

selector - CSS selector

Returns a NodeList or null

undefined

browser.text(selector, context?) => String

Returns the text contents of the selected elements.

selector - CSS selector (if missing, entire document) context - Context element (if missing, uses document)

Returns a string

undefined

browser.html(selector?, context?) => String

Returns the HTML contents of the selected elements.

selector - CSS selector (if missing, entire document) context - Context element (if missing, uses document)

Returns a string

undefined

Deprecated please use queryAll instead.

undefined

browser.xpath(expression, context?) => XPathResult

Evaluates the XPath expression against the document (or context node) and return the XPath result. Shortcut for document.evaluate.

undefined

browser.document => Document

Returns the main window's document. Only valid after opening a document (see browser.open).

undefined

browser.body => Element

Returns the body Element of the current document.

undefined

browser.statusCode => Number

Returns the status code of the request for loading the window.

undefined

browser.success => Boolean

True if the status code is 2xx.

undefined

browser.redirected => Boolean

Returns true if the request for loading the window followed a redirect.

undefined

source => String

Returns the unmodified source of the document loaded by the browser

undefined

close

Close all windows, dispose of all resources. You want to call this if you're running out of memory.

undefined

Navigation

undefined

browser.visit(url, callback?)

browser.visit(url, options, callback)

Loads document from the specified URL, processes events and calls the callback. If the second argument are options, uses these options for the duration of the request and resets the options afterwards.

The callback is called with null, the browser, status code and array of resource/JavaScript errors.

undefined

browser.load(html, callback)

Loads the HTML, processes events and calls the callback.

Without a callback, returns a promise.

undefined

Find (first of any) errors caught during document.write

undefined

Call callback or resolve promise

undefined

Otherwise wait for all events to process, wait handles errors

undefined

browser.location => Location

Return the location of the current document (same as window.location).

undefined

browser.location = url

Changes document location, loads new document if necessary (same as setting window.location).

undefined

browser.link(selector) : Element

Finds and returns a link by its text content or selector.

undefined

If the link has already been queried, return itself

undefined

browser.clickLink(selector, callback)

Clicks on a link. Clicking on a link can trigger other events, load new page, etc: use a callback to be notified of completion. Finds link by text content or selector.

selector - CSS selector or link text callback - Called with two arguments: error and browser

undefined

Return the history object.

undefined

Navigate back in history.

undefined

Reloads current page.

undefined

Returns a new Credentials object for the specified host. These authentication credentials will only apply when making requests to that particular host (hostname:port).

You can also set default credentials by using the host '*'.

If you need to get the credentials without setting them, call with true as the second argument.

undefined

Legacy support, remove in the future.

undefined

browser.saveHistory() => String

Save history to a text string. You can use this to load the data later on using browser.loadHistory.

undefined

browser.loadHistory(String)

Load history from a text string (e.g. previously created using browser.saveHistory.

undefined

Forms

undefined

browser.field(selector) : Element

Find and return an input field (INPUT, TEXTAREA or SELECT) based on a CSS selector, field name (its name attribute) or the text value of a label associated with that field (case sensitive, but ignores leading/trailing spaces).

undefined

If the field has already been queried, return itself

undefined

Try more specific selector first.

undefined

Use field name (case sensitive).

undefined

Try finding field from label.

undefined

Label can either reference field or enclose it

undefined

browser.fill(selector, value, callback) => this

Fill in a field: input field or text area.

selector - CSS selector, field name or text of the field label value - Field value

Without callback, returns this.

undefined

browser.check(selector, callback) => this

Checks a checkbox.

selector - CSS selector, field name or text of the field label

Without callback, returns this.

undefined

browser.uncheck(selector, callback) => this

Unchecks a checkbox.

selector - CSS selector, field name or text of the field label

Without callback, returns this.

undefined

browser.choose(selector, callback) => this

Selects a radio box option.

selector - CSS selector, field value or text of the field label

Returns this.

undefined

browser.select(selector, value, callback) => this

Selects an option.

selector - CSS selector, field name or text of the field label value - Value (or label) or option to select

Without callback, returns this.

undefined

browser.selectOption(option, callback) => this

Selects an option.

option - option to select

Without callback, returns this.

undefined

browser.unselect(selector, value, callback) => this

Unselects an option.

selector - CSS selector, field name or text of the field label value - Value (or label) or option to unselect

Without callback, returns this.

undefined

browser.unselectOption(option, callback) => this

Unselects an option.

option - option to unselect

Without callback, returns this.

undefined

browser.attach(selector, filename, callback) => this

Attaches a file to the specified input field. The second argument is the file name.

Without callback, returns this.

undefined

browser.button(selector) : Element

Finds a button using CSS selector, button name or button text (BUTTON or INPUT element).

selector - CSS selector, button name or text of BUTTON element

undefined

If the button has already been queried, return itself

undefined

browser.pressButton(selector, callback)

Press a button (button element or input of type submit). Typically this will submit the form. Use the callback to wait for the from submission, page to load and all events run their course.

selector - CSS selector, button name or text of BUTTON element callback - Called with two arguments: null and browser

undefined

browser.focused => element

Returns the element in focus.

undefined

Cookies and storage

undefined

Returns all the cookies for this domain/path. Domain defaults to hostname of currently open page. Path defaults to "/".

undefined

Save cookies to a text string. You can use this to load them back later on using browser.loadCookies.

undefined

Load cookies from a text string (e.g. previously created using browser.saveCookies.

undefined

Returns local Storage based on the document origin (hostname/port). This is the same storage area you can access from any document of that origin.

undefined

Returns session Storage based on the document origin (hostname/port). This is the same storage area you can access from any document of that origin.

undefined

Save local/session storage to a text string. You can use this to load the data later on using browser.loadStorage.

undefined

Load local/session stroage from a text string (e.g. previously created using browser.saveStorage.

undefined

Scripts

undefined

Evaluates a JavaScript expression in the context of the current window and returns the result. When evaluating external script, also include filename.

You can also use this to evaluate a function in the context of the window: for timers and asynchronous callbacks (e.g. XHR).

undefined

Interaction

undefined

browser.onalert(fn)

Called by window.alert with the message.

undefined

browser.onconfirm(question, response)

browser.onconfirm(fn)

The first form specifies a canned response to return when window.confirm is called with that question. The second form will call the function with the question and use the respone of the first function to return a value (true or false).

The response to the question can be true or false, so all canned responses are converted to either value. If no response available, returns false.

undefined

browser.onprompt(message, response)

browser.onprompt(fn)

The first form specifies a canned response to return when window.prompt is called with that message. The second form will call the function with the message and default value and use the response of the first function to return a value or false.

The response to a prompt can be any value (converted to a string), false to indicate the user cancelled the prompt (returning null), or nothing to have the prompt return the default value or an empty string.

undefined

browser.prompted(message) => boolean

Returns true if user was prompted with that message (window.alert, window.confirm or window.prompt)

undefined

Debugging

undefined

browser.viewInBrowser(name?)

Views the current document in a real Web browser. Uses the default system browser on OS X, BSD and Linux. Probably errors on Windows.

undefined

browser.lastRequest => HTTPRequest

Returns the last request sent by this browser. The object will have the properties url, method, headers, and body.

undefined

browser.lastResponse => HTTPResponse

Returns the last response received by this browser. The object will have the properties url, status, headers and body. Long bodies may be truncated.

undefined

browser.lastError => Object

Returns the last error received by this browser in lieu of response.

undefined

Zombie can spit out messages to help you figure out what's going on as your code executes.

To spit a message to the console when running in debug mode, call this method with one or more values (same as console.log). You can also call it with a function that will be evaluated only when running in debug mode.

For example: browser.log("Opening page:", url); browser.log(function() { return "Opening page: " + url });

undefined

Dump information to the consolt: Zombie version, current URL, history, cookies, event loop, etc. Useful for debugging and submitting error reports.

undefined

Represents credentials for a given host.

undefined

Apply security credentials to the outgoing request headers.

undefined

Use HTTP Basic authentication. Requires two arguments, username and password.

undefined

Use OAuth 2.0 Bearer (recent drafts). Requires one argument, the access token.

undefined

Use OAuth 2.0 (early drafts). Requires one argument, the access token.

undefined

Reset these credentials.

undefined