Setup
Install Node
$ curl -O http://nodejs.org/dist/node-v0.4.12.tar.gz
$ ./configure
$ make && make install
Install NPM
$ curl http://npmjs.org/install.sh | sh
Install Jellyfish
$ npm install jellyfish
Basic Usage
Start Client REPL
jellyfish shell
Write a Script
var jellyfish = require('jellyfish')
, assert = require('assert');
// init a browser
//createFirefox
//createChrome
//createZombie
//createSafari
//createSauce
//createWebdriver
//these can also take a URL string param
var browser = jellyfish.createFirefox();
browser.on('result', function(res) {
console.log(browser.name + ' : '+browser.tid + ' - \x1b[33m%s\x1b[0m', JSON.stringify(res));
});
// goto a web site
browser.go("http://www.jelly.io")
// verify the title
.js("document.title", function(o) {
assert.equal(o.result, "Jelly.io: Jellyfish Home")
})
// run some local javascript
//create a file called test.js containing
//alerted: Jellyfish local file loaded successfully!
/*.jsfile("./test.js", function(o) {
assert.equal(o.result,
"alerted: Jellyfish local file loaded successfully!")
})*/
// run some remote javascript, stop the browser, then exit
.jsurl("http://jelly.io/test.js", function(o) {
assert.equal(o.result,
"alerted: Jellyfish remote file loaded successfully!")
browser.stop(function() {
setTimeout(process.exit(), 2000);
})
});
Walkthrough
Require
var jellyfish = require('jellyfish')
, assert = require('assert');
Instantiate - /firefox/chrome/zombie/
var browser = jellyfish.createFirefox();
Run Code
Raw JavaScript
browser.js("document.title", function(o) {
assert.equal(o.result, "Jelly.io: Jellyfish Home")
});
Local JavaScript
browser.jsfile("./test.js", function(o) {
assert.equal(o.result,
"alerted: Jellyfish local file loaded succesfully!")
});
Remote JavaScript
browser.jsurl("http://jelly.io/test.js", function(o) {
assert.equal(o.result,
"alerted: Successfully ran some remote javascript in Jellyfish!")
});
Reporting
var jellyfish = require('jellyfish')
var browser = jellyfish.createFirefox(function(){
browser.couch({uri:'my couch url', port:5984, db:'mydbname'})
});
// You can just do browser.couch() and it will default to:
// {uri:'localhost', port:5984, db:'jellyfish'}
// Do stuff and it will automatically get reported to couch!
Browser Helpers
Go - To a URL
browser.go("http://jelly.io")
To - Frame title
browser.to("Jelly.io: Jellyfish Home")
Frames - List
browser.frames()
jQuery - Always
You can always use the injected jQuery, called $jfQ