antimony

drive firefox from node.js
git clone https://wehaveforgeathome.hates.computer/antimony.git
Log | Files | Refs | Submodules | LICENSE

(3088B)


      1 Antimony
      2 ==
      3 
      4 Antimony is automated testing in the browser done right.
      5 
      6 Ways in which Antimony kicks Selenium's ass:
      7 
      8 * *Fast fast fast.* Selenium works everywhere in every language, sort of. Antimony works on one browser in one language in 964 lines of code.
      9 * *Speaks your language.* Antimony runs Javascript in the browser, because that's what runs in the browser. If you want to generate Javascript from some other language in order to test how languages which don't work in the browser might sort of work in the browser, that's between you and your god.
     10 * *Async.* The browser runs Javascript and Javascript is async, so why aren't your tests?
     11 * *Knows it's an extension.* Firefox extensions run with all kinds of permissions and access, so why tie one hand behind your back and pretend you don't have the keys to the Mustang? Feel free to run tests from the context of the page most of the time, but when you want to really tear it up, Antimony has you covered.
     12 
     13 Setup
     14 ===
     15 
     16 * clone the repo `git clone git://github.com/borderstylo/antimony.git`
     17 * start the server `nodes server.js`
     18 * build the extension `make`
     19 * open antimony.xpi in firefox
     20 
     21 Testing with Curl
     22 ===
     23 
     24 You can interact with antimony by POSTing to http://localhost:1235/client
     25 
     26 *Example:*
     27 
     28     $ curl -d '{"type":"page","url":"http://google.com","script":"function (callback) { callback(document.title); }"}' http://localhost:1235/client
     29     {"res":"Google"}
     30 
     31 *Arguments:*
     32 
     33 * type: where to run the script. "page" or "browser". optional (defaults to "browser")
     34 * url: which page to run the script on (required when type: "page", ignored otherwise)
     35 * script: string function to run. function should take a callback argument and call it (return values are ignored).
     36 
     37 Testing with the Client Library
     38 ===
     39 
     40 In addition to raw POSTs, there is a nice library in node.js for running tests.
     41 
     42 *Example:*
     43 
     44     var Client = require('./vendor/antimony/client');
     45     var client = new Client('localhost:1235');
     46 
     47     client.runOnPage(
     48       'http://google.com',
     49       function (callback) {
     50         callback(document.title);
     51       },
     52       function (title) {
     53         console.log(title) // Google
     54       }
     55     );
     56 
     57 Clients take a host as a constructor argument.
     58 
     59 runOnPage takes three arguments:
     60 
     61 * the url to run the test on
     62 * a function to run on the page. two things to keep in mind with these functions is that they don't have a closure and should take a callback argument
     63 * a callback to pass the results to
     64 
     65 Extras
     66 ===
     67 
     68 In addition to the usual goodies you'll expect to be in scope (like window and document for the page and Components for the browser), Antimony provides a require a la CommonJS and a $ a la jQuery. See [commonjs-ffext](https://github.com/borderstylo/commonjs-ffext) and [windex](https://github.com/borderstylo/windex) for details.
     69 
     70 TODO
     71 ===
     72 
     73 * ANY. ERROR. HANDLING. Antimony should return a 5** status code and a description of the Javascript error. This is a big pain at the moment, because it means you need to keep an eye on the console in the browser when running tests.