Permalink
Browse files

`Zombie` and `Browser` are no longer distinct namespaces. What you

require is the `Browser` class that also includes all the methods
previously defined for `Zombie`.
  • Loading branch information...
assaf committed Dec 17, 2011
1 parent 3f933b3 commit 39f70ed16eee41d637c15f3402ab53e456b65388
View
@@ -3,11 +3,27 @@ zombie.js-changelog(7) -- Changelog
## Version 0.12.5 2011-12-16
+`Zombie` and `Browser` are no longer distinct namespaces. What you require is the `Browser` class that also includes
+all the methods previously defined for `Zombie`. For example:
+
+ var Browser = require("zombie")
+
+ // This setting applies to all browsers
+ Browser.debug = true
+ // Create and use a new browser instance
+ var browser = new Browser()
+ browser.visit("http://localhost:3001", function() {
+ ...
+ })
+
Added `browser.history` for accessing history for the current window, `browser.back` for navigating to the previous page
and `browser.reload` for reloading the current page.
Fixed a bug whereby navigating back in push-state history would reload document.
+ 363 Tests
+ 2.4 sec to complete
+
## Version 0.12.4 2011-12-16
View
@@ -11,21 +11,22 @@ required.
Let's try to sign up to a page and see what happens:
- var zombie = require("zombie");
+ var Browser = require("zombie");
var assert = require("assert");
// Load the page from localhost
- zombie.visit("http://localhost:3000/", function (e, browser, status) {
+ browser = new Browser()
+ browser.visit("http://localhost:3000/", function () {
// Fill email, password and submit form
- browser.
+ zombie.
fill("email", "zombie@underworld.dead").
fill("password", "eat-the-living").
- pressButton("Sign Me Up!", function(e, browser, status) {
+ pressButton("Sign Me Up!", function() {
// Form submitted, new page loaded.
- assert.ok(browser.success);
- assert.equal(browser.text("title"), "Welcome To Brains Depot");
+ assert.ok(zombie.success);
+ assert.equal(zombie.text("title"), "Welcome To Brains Depot");
})
@@ -44,7 +45,7 @@ On OS X start by installing XCode, or use the [OSX GCC installer](https://github
Next, assuming you're using the mighty [Homebrew](http://mxcl.github.com/homebrew/):
$ brew install node
- $ node --version
+ $ node --versi")
v0.6.2
$ curl http://npmjs.org/install.sh | sudo sh
$ npm --version
@@ -73,8 +74,13 @@ troubleshooting.
To start off we're going to need a browser. A browser maintains state across requests: history, cookies, HTML 5 local
and session stroage, etc. A browser has a main window, and typically a document loaded into that window.
-You can create a new `zombie.Browser` and point it at a document, either by setting the `location` property or calling
-its `visit` function. As a shortcut, you can just call the `zombie.visit` function with a URL and callback.
+You can create a new `Browser` and point it at a document, either by setting the `location` property or calling
+its `visit` function. As a shortcut, you can just call the `Browser.visit` function with a URL and callback:
+
+ Browser.visit("http://localhost:3000/", function (e, browser) {
+ // The browser argument is an instance of Browser class
+ ...
+ })
The browser will load the document and if the document includes any scripts, also load and execute these scripts. It
will then process some events, for example, anything your scripts do on page load. All of that, just like a real
@@ -193,7 +199,7 @@ Let's combine all of that into one example:
fill("Profession", "Living dead").
select("Born", "1968").
uncheck("Send me the newsletter").
- pressButton("Sign me up", function(e, browser, status) {
+ pressButton("Sign me up", function() {
// Make sure we got redirected to thank you page.
assert.equal(browser.location.pathname, "/thankyou");
@@ -234,8 +240,9 @@ Zombie.js supports the following:
**Step 1:** Run Zombie with debugging turned on, the trace will help figure out what it's doing. For example:
- var browser = new zombie.Browser({ debug: true });
- browser.visit("http://thedead", function(e, browser, status) {
+ Browser.debug = true
+ var browser = new Browser()
+ browser.visit("http://thedead", function() {
console.log(status, browser.errors);
...
});
View
@@ -11,20 +11,22 @@ session stroage. A browser has a main window, and typically a document loaded i
You can pass options when initializing a new browser, for example:
- browser = new zombie.Browser({ debug: true })
+ var Browser = require("zombie")
+
+ var browser = new Browser({ debug: true })
browser.runScripts = false
Or on existing browser for the duration of a page load:
- zombie.visit("http://localhost:3000/", { debug: true, runScripts: false },
+ Browser.visit("http://localhost:3000/", { debug: true, runScripts: false },
function (e, browser, status) {
...
});
You can also set options globally for all browsers to inherit:
- Zombie.site = "http://localhost:3000"
- Zombie.loadCSS = false
+ Browser.site = "http://localhost:3000"
+ Browser.loadCSS = false
### Browser Options
View
@@ -50,7 +50,7 @@ call to `visit` (the second argument being the options).
For example:
- zombie.visit("http://thedead", { debug: true}, function(err, browser) {
+ Browser.visit("http://thedead", { debug: true}, function(err, browser) {
console.log(browser.errors);
...
});
View
@@ -3,17 +3,17 @@ require "./forms"
require "./xpath"
{ deprecated } = require("./helpers")
-{ Cache } = require("./cache")
-{ Console } = require("./console")
-{ Cookies } = require("./cookies")
+Cache = require("./cache")
+Console = require("./console")
+Cookies = require("./cookies")
{ EventEmitter } = require("events")
-{ EventLoop } = require("./eventloop")
-{ History } = require("./history")
+EventLoop = require("./eventloop")
+History = require("./history")
{ HTML5 } = require("html5")
Interact = require("./interact")
JSDom = require("jsdom")
-{ Resources } = require("./resources")
-{ Storages } = require("./storage")
+Resources = require("./resources")
+Storages = require("./storage")
URL = require("url")
XHR = require("./xhr")
if process.version < "v0.5.0"
@@ -115,7 +115,7 @@ class Browser extends EventEmitter
for name in BROWSER_OPTIONS
value = options[name]
if typeof value == "undefined"
- value = exports[name]
+ value = Browser[name]
unless typeof value == "undefined"
@[name] = value
else
@@ -908,6 +908,5 @@ class Screen
@prototype.__defineGetter__ "pixelDepth", -> 24
-exports.Browser = Browser
-exports.version = VERSION # Backwards compatible
-exports.VERSION = VERSION
+Browser.VERSION = VERSION
+module.exports = Browser
View
@@ -1,4 +1,4 @@
# Simple HTTP cache.
class Cache
-exports.Cache = Cache
+module.exports = Cache
@@ -1,7 +1,7 @@
-try
- Util = require("util")
-catch e
+if process.version < "v0.5.0"
Util = require("sys")
+else
+ Util = require("util")
class Console
@@ -63,4 +63,4 @@ class Console
return (if @_output then @_output.join("\n") else "")
-exports.Console = Console
+module.exports = Console
@@ -222,4 +222,4 @@ HTML.HTMLDocument.prototype.__defineSetter__ "cookie", (cookie)->
@parentWindow.cookies.update cookie
-exports.Cookies = Cookies
+module.exports = Cookies
@@ -131,4 +131,4 @@ class EventLoop
"Waiting: #{@_waiting.length}" ]
-exports.EventLoop = EventLoop
+module.exports = EventLoop
@@ -296,4 +296,4 @@ HTML.HTMLDocument.prototype.__defineSetter__ "location", (url)->
@parentWindow.location = url
-exports.History = History
+module.exports = History
View
@@ -3,8 +3,7 @@ if process.version >= "v0.5.0"
else
Util = require("sys")
-Zombie = require("./browser")
-Browser = Zombie.Browser
+Browser = require("./browser")
# ### zombie.visit(url, callback)
@@ -58,11 +57,12 @@ console.log = ->
process.stdout.write formatted.join(" ") + "\n"
-Zombie.listen = listen
-Zombie.visit = visit
+Browser.listen = listen
+Browser.visit = visit
# Default to debug mode if environment variable `DEBUG` is set.
-Zombie.debug = !!process.env.DEBUG
+Browser.debug = !!process.env.DEBUG
+Browser.Browser = Browser
# Export the globals from browser.coffee
-module.exports = Zombie
+module.exports = Browser
@@ -369,4 +369,4 @@ STATUS =
505: "HTTP Version Not Supported"
-exports.Resources = Resources
+module.exports = Resources
@@ -209,4 +209,4 @@ class Storages
throw "Unkown storage type #{type}"
-exports.Storages = Storages
+module.exports = Storages
View
@@ -1,4 +1,4 @@
-{ Vows, assert, brains, Zombie, Browser } = require("./helpers")
+{ Vows, assert, brains, Browser } = require("./helpers")
JSDOM = require("jsdom")
@@ -31,7 +31,7 @@ Vows.describe("Browser").addBatch(
"open page":
- Zombie.wants "http://localhost:3003/browser/scripted"
+ Browser.wants "http://localhost:3003/browser/scripted"
"should create HTML document": (browser)->
assert.instanceOf browser.document, JSDOM.dom.level3.html.HTMLDocument
"should load document from server": (browser)->
@@ -170,7 +170,7 @@ Vows.describe("Browser").addBatch(
assert.equal err.message, "Cannot read property 'wrong' of undefined"
"source":
- Zombie.wants "http://localhost:3003/browser/scripted"
+ Browser.wants "http://localhost:3003/browser/scripted"
"should return the unmodified page": (browser)->
assert.equal browser.source,
"""
@@ -202,14 +202,14 @@ Vows.describe("Browser").addBatch(
"global":
topic: ->
- Zombie.site = "http://localhost:3003"
+ Browser.site = "http://localhost:3003"
browser = new Browser
browser.wants "/browser/scripted", @callback
"should set browser options from global options": (browser)->
assert.equal browser.site, "http://localhost:3003"
assert.equal browser.document.title, "Awesome"
teardown: ->
- Zombie.site = null
+ Browser.site = null
"content selection":
@@ -455,7 +455,7 @@ Vows.describe("Browser").addBatch(
"URL without path":
- Zombie.wants "http://localhost:3003"
+ Browser.wants "http://localhost:3003"
"should resolve URL": (browser)->
assert.equal browser.location.href, "http://localhost:3003/"
"should load page": (browser)->
View
@@ -1,4 +1,4 @@
-{ Vows, assert, brains, Browser, Zombie } = require("./helpers")
+{ Vows, assert, brains, Browser } = require("./helpers")
brains.get "/cookies", (req, res)->
@@ -27,7 +27,7 @@ brains.get "/cookies_redirect", (req, res)->
Vows.describe("Cookies").addBatch(
"get cookies":
- Zombie.wants "http://localhost:3003/cookies"
+ Browser.wants "http://localhost:3003/cookies"
"cookies":
topic: (browser)->
browser.cookies("localhost", "/cookies")
@@ -72,7 +72,7 @@ Vows.describe("Cookies").addBatch(
"get cookies and redirect":
- Zombie.wants "http://localhost:3003/cookies_redirect"
+ Browser.wants "http://localhost:3003/cookies_redirect"
"cookies":
topic: (browser)->
browser.cookies("localhost", "/")
Oops, something went wrong.

0 comments on commit 39f70ed

Please sign in to comment.