Permalink
Browse files

First documentation you can actually use.

  • Loading branch information...
1 parent 3bab241 commit f35b8e2ab49c685b17efc45bcc7a0fb6c286e55d @assaf committed Dec 22, 2010
Showing with 236 additions and 68 deletions.
  1. +6 −0 CHANGELOG
  2. +165 −18 README.md
  3. +1 −1 TODO.md
  4. +11 −1 doc/screen.css
  5. +52 −47 lib/zombie/browser.coffee
  6. +1 −1 package.json
View
@@ -1,9 +1,15 @@
+Version 0.6.4 2010-12-21
+
+ First documentation you can actually use.
+
+
Version 0.6.3 2010-12-21
Fixed documentation link.
man zombie
+
Version 0.6.2 2010-12-21
First NPM release.
View
183 README.md
@@ -1,35 +1,173 @@
zombie.js(1) -- Superfast headless full stack testing framework using Node.js
==========================================================================
-The Bite
---------
+## The Bite
If you're going to write an insanely fast, headless test tool, how can you not
call it Zombie? Zombie it is.
Zombie.js is a lightweight framefork for testing client-side JavaScript code in
a simulated environment. No browser required.
-Zombie.js runs on [Node.js](http://nodejs.org/), so it's insanely fast. It
-uses [JSDOM](http://jsdom.org/) to simulate a brower, so it can't find
-incompatibility issues in IE 7.0, but it can spot bugs in your code.
+Let's try to sign up to a page and see what happens:
-You don't have to, but I really recommend running Zombie.js with
-[Vows](http://vowsjs.org/) , an outstanding BDD test framework for Node.js.
+ var zombie = require("zombie");
+ // Load the page from localhost
+ zombie.visit("http://localhost:3000/", function (browser) {
-Using
------
+ // Fill email, password and submit form
+ browser.
+ fill("email", "zombie@underworld.dead").
+ fill("password", "eat-the-living").
+ pressButton("Sign Me Up!", function(browser) {
-Coming.
+ // Form submitted, new page loaded.
+ assert.equal(browser.text("title"), "Welcome To Brains Depot");
-See the documentation for [Sizzle.js](https://github.com/jeresig/sizzle/wiki).
+ })
-[Source code/API Documentation](source/browser.html)
+ });
+Well, that was easy.
-Guts
-----
+
+### Getting Around
+
+A browser has one window open, and typically one document open in that window.
+The `Browser` class adds many high-level functions on top of what you can already
+do with windows and documents.
+
+Callbacks are called either with an `Error` object or `null`, `Browser`.
+
+#### Browser.visit(url, callback)
+
+Shortcut for creating new browser and calling `browser.visit` on it.
+
+#### browser.body => Element
+
+Returns the body Element of the current document.
+
+#### browser.check(field) => this
+
+Checks a checkbox.
+
+#### browser.choose(field) => this
+
+Selects a radio box option.
+
+#### 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.
+
+#### browser.clock
+
+The current system clock according to the browser (see also `browser.now`).
+
+#### browser.cookies(domain, path?) => Cookies
+
+Returns all the cookies for this domain/path. Path defaults to "/".
+
+#### browser.document => Document
+
+Returns the main window's document. Only valid after opening a document (see `browser.open`).
+
+#### browser.find(selector, context?) => [Elements]
+
+Returns an array of all the elements that match the selector. Without context,
+searches through the entire document.
+
+#### browser.fill(field, value) => this
+
+Fill in a field: input field or text area.
+
+#### browser.fire(name, target, calback?)
+
+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. With a callback, this
+function will call `wait`.
+
+#### browser.html(selector?, context?) => String
+
+Returns the HTML contents of the selected elements (see also `browser.find`).
+
+#### browser.last_error => Object
+
+Returns the last error received by this browser in lieu of response.
+
+#### browser.last_request => Object
+
+Returns the last request sent by this browser.
+
+#### browser.last_response => Object
+
+Returns the last response received by this browser.
+
+#### brower.localStorage(host) => Storage
+
+Returns local Storage based on the document origin (hostname/port).
+
+#### browser.location => Location
+
+Return the location of the current document (same as `window.location.href`).
+
+#### browser.location = url
+
+Changes document location, loads new document if necessary (same as setting
+`window.location`).
+
+#### browser.now => Date
+
+The current system time according to the browser (see also `browser.clock`).
+
+#### browser.open() => Window
+
+Open new browser window.
+
+#### browser.pressButton(name, 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.
+
+#### browser.select(field, value) => this
+
+Selects an option.
+
+#### brower.sessionStorage(host) => Storage
+
+Returns session Storage based on the document origin (hostname/port).
+
+#### browser.text(selector, context?) => String
+
+Returns the text contents of the selected elements (see also `browser.find`).
+
+#### browser.uncheck(field) => this
+
+Unchecks a checkbox.
+
+#### browser.visit(url, callback)
+
+Loads document from the specified URL, processes events and calls the callback.
+
+#### browser.wait(terminator, callback)
+
+Process all events from the queue. This includes resource loading, XHR
+requests, timeout and interval timers. Calls the callback when done.
+
+The terminator is optional and can be one of:
+* `null`, missing -- process all events
+* Number -- process that number of events
+* Function -- called after each event, returns false to stop processing
+
+#### browser.window => Window
+
+Returns the main window.
+
+
+## Guts
Zombie.js is written in
[CoffeeScript](http://jashkenas.github.com/coffee-script/), a language
@@ -86,8 +224,7 @@ To generate the documentation
$ open html/index.html
-Feeding
--------
+## Feeding
* Find [assaf/zombie on Github](http://github.com/assaf/zombie)
* Fork the project
@@ -98,8 +235,7 @@ Feeding
Check out the outstanding [to-dos](todo.html).
-Brains
-------
+## Brains
Zombie.js is copyright of [Assaf Arkin](http://labnotes.org), released under the MIT License.
@@ -108,3 +244,14 @@ Zombie.js is written in
[Node.js](http://nodejs.org/).
[Sizzle.js](http://sizzlejs.com/) is copyright of John Resig, released under the MIT, BSD and GPL.
+
+
+## See Also
+
+[Annotated Source Code](source/browser.html) for Zombie.js.
+
+[Sizzle.js](https://github.com/jeresig/sizzle/wiki) documentation.
+
+[Vows](http://vowsjs.org/) You don't have to, but I really recommend
+running Zombie.js with Vows, an outstanding BDD test framework for
+Node.js.
View
@@ -25,4 +25,4 @@ TODO
* Enhance DOM with find/filter/html/text methods on elements and node lists.
-* Documentation.
+* More documentation.
View
@@ -3,15 +3,25 @@ body {
font-size: 14pt;
width: 40em;
margin: 1em auto;
+ color: #222;
}
h1, h2, h3, h4 {
font-family: "Gill Sans", "Gill Sans MT", Calibri, sans-serif;
color: #660000;
}
+h1, h2, h3 { color: #600; }
h1 { font-size: 22pt; }
h2 { font-size: 20pt; }
h3 { font-size: 18pt; }
-h4 { font-size: 16pt; }
+h4 {
+ font-size: 16pt;
+ color: #666;
+}
+pre, code {
+ font-family: "Menlo", "Consolas", "New Courier", Courier, monospace;
+ font-size: 12pt;
+ color: #060;
+}
.title {
text-align: right;
Oops, something went wrong.

0 comments on commit f35b8e2

Please sign in to comment.