From 302c23881f36106d4dd5d17d24f1d17c63322a65 Mon Sep 17 00:00:00 2001 From: Evan Mezeske Date: Mon, 19 Mar 2012 21:47:28 -0700 Subject: [PATCH] Fix things for the newest PhantomJS. Fixes #57. --- example-projects/advanced/README.md | 20 +++++++++++++------ example-projects/advanced/phantom/repl.js | 12 ++++++++++- .../advanced/phantom/unit-test.js | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/example-projects/advanced/README.md b/example-projects/advanced/README.md index 0ab45a3c..511330f9 100644 --- a/example-projects/advanced/README.md +++ b/example-projects/advanced/README.md @@ -20,6 +20,18 @@ Set up and start the server like this: Now, point your web browser at `http://localhost:3000`, and see the web app in action! +## PhantomJS + +[PhantomJS] (http://www.phantomjs.org) is a headless Webkit browser, which can be automated +via Javascript. It provides a Javascript execution environment with access to all browser +features (the DOM, etc), without opening a browser GUI. + +The tests and the "phantom-*" REPLs require PhantomJS 1.3 or newer to be installed. +The process for accomplishing This is OS dependent. See [PhantomJS] (http://www.phantomjs.org) +for information on installing it on your OS. + +If you do not plan to run the tests and only want to use the rhino or firefox REPLs, you can skip this step. + ## Running the Tests To run the unit tests: @@ -36,8 +48,8 @@ be compiled, so they have their own entry in the `:builds` configuration. Note all of the `:source-path` entries from the `:builds` are added to the classpath, so the tests can `:require` ClojureScript namespaces from, e.g., the `src-cljs` directory. -The example configuration uses [PhantomJS] (http://www.phantomjs.org) to run the tests. -See the `phantom/unit-test.js` file for details on how this works. +See the `phantom/unit-test.js` file for more details on how PhantomJS is configured to +make this work. ## Connecting Firefox to a REPL @@ -64,10 +76,6 @@ need to have your app running in the background: ## Connecting PhantomJS to a REPL -[PhantomJS] (http://www.phantomjs.org) is a headless Webkit browser, which can be automated -via Javascript. It provides a Javascript execution environment with access to all browser -features (the DOM, etc), without opening a browser GUI. - To try out a PhantomJS-based REPL, first start the Ring server in one terminal: $ lein ring server-headless 3000 diff --git a/example-projects/advanced/phantom/repl.js b/example-projects/advanced/phantom/repl.js index a4b91bbf..a67a6f5a 100644 --- a/example-projects/advanced/phantom/repl.js +++ b/example-projects/advanced/phantom/repl.js @@ -3,8 +3,9 @@ if (phantom.args.length != 1) { phantom.exit(1); } -var page = new WebPage(); +var page = require('webpage').create(); var url = phantom.args[0]; +var page_opened = false; page.onConsoleMessage = function (message) { console.log("App console: " + message); @@ -13,6 +14,15 @@ page.onConsoleMessage = function (message) { console.log("Loading URL: " + url); page.open(url, function (status) { + // FIXME: This is a horrible, ridiculous hack. For some reason, PhantomJS calls + // page.open() twice, and if doesn't return immediately the second time, + // things break. Reference: + // http://code.google.com/p/phantomjs/issues/detail?id=353&q=wait&sort=-type + if (page_opened) { + return; + } + page_opened = true; + if (status != "success") { console.log('Failed to open ' + url); phantom.exit(1); diff --git a/example-projects/advanced/phantom/unit-test.js b/example-projects/advanced/phantom/unit-test.js index 89923ce8..1c8fa48b 100644 --- a/example-projects/advanced/phantom/unit-test.js +++ b/example-projects/advanced/phantom/unit-test.js @@ -3,7 +3,7 @@ if (phantom.args.length != 1) { phantom.exit(1); } -var page = new WebPage(); +var page = require('webpage').create(); var url = phantom.args[0]; page.onConsoleMessage = function (message) {