Commit Graph

208 Commits (ea8a5b9a8d525919f4b0819ec12ab54e82f8e6a2)

Author SHA1 Message Date
Ariya Hidayat 9c0888d54d Fix potential hang in the example scripts due to missing exit() call.
Patch by Jônatas Pedraza <jonatas.nona@gmail.com> and Vivek Galatage
<vivekgalatage@gmail.com>.

http://code.google.com/p/phantomjs/issues/detail?id=922
2012-12-16 23:02:44 -08:00
fastclemmy 3b2a1c27a1 Update examples/pizza.coffee.
Guess the DOM has changed a little. No more class .address but an (incorrectly used) <address> tag instead. (same pull request as the vanilla JS example)

http://code.google.com/p/phantomjs/issues/detail?id=921
2012-12-16 14:20:57 -08:00
fastclemmy 8f14ef027e Fix examples/pizza.js.
Guess the DOM has changed a little. No more class .address but an (incorrectly used) <address> tag instead.

http://code.google.com/p/phantomjs/issues/detail?id=921
2012-12-16 14:19:57 -08:00
James M. Greene e8380e42d7 Added CoffeeScript examples where missing, minor other fixes
Added CoffeeScript examples where missing, minor other fixes such as spacing standardization (2 spaces is the standard in CoffeeScript via Ruby). Also a small set of minor JS example fixes and additional comments.

Fixes http://code.google.com/p/phantomjs/issues/detail?id=907
2012-12-06 14:29:37 -06:00
James M. Greene f61635f2d4 Adding 'WebPage#close' calls where appropriate in example scripts.
Fixes http://code.google.com/p/phantomjs/issues/detail?id=903
2012-12-06 08:27:06 -08:00
Ivan De Marino e521dc16e7 Adding a simple example to help understand events.
Lots of discussions on the ML could be easily put
to rest if people could run something like this
and see the result.
It's not a real fix or improvement, just a "cute"
example and as such I didn't raise a "proper"
issue.
2012-10-16 21:50:53 -07:00
Ariya Hidayat 7921cb00e1 Remove non-working weather example.
The example stops working since the request is blocked. It needs a
rewrite to use a different service.

http://code.google.com/p/phantomjs/issues/detail?id=794
2012-09-22 13:39:19 -07:00
Ian Oxley e85140e80f Non-zero exit code if any test fails.
In the callback function passed to `waitFor`, the call to `page.evaluate`
returns a 1 or 0, and this is then passed to `phantom.exit` (with a 1
indicating at least one test failed, 0 indicating all tests passed).

http://code.google.com/p/phantomjs/issues/detail?id=792
2012-09-21 00:12:52 -07:00
Ian Oxley 1dbd371540 Added 'tests passed' message.
If all tests pass, a message indicating this is output to the console.

http://code.google.com/p/phantomjs/issues/detail?id=792
2012-09-21 00:12:30 -07:00
Ian Oxley be767ee983 Test failure CSS selectors changed.
Changed the CSS selectors used to identify failed tests.

The old selector was `div.jasmine_reporter > div.suite.failed`,
but this no longer seems to match any elements.

The new selector is `.results > #details > .specDetails.failed`. For each
failing test the `.description` and `.resultMessage.fail` elements are
used to output the failures to the console.

http://code.google.com/p/phantomjs/issues/detail?id=792
2012-09-21 00:11:43 -07:00
Ian Oxley 2662d5875b Changed CSS selector used when checking for whether tests have finished.
When using the jasmine 1.2.0 standalone version, `.runner .description`
doesn't seem to match any elements.

I noticed pending tests can be found using the CSS selector
`.symbolSummary .pending`, so changed the testFx callback to check
that no elements are left matching this selector.

http://code.google.com/p/phantomjs/issues/detail?id=792
2012-09-21 00:11:24 -07:00
Ivan De Marino 26583740c8 Made the "Callbacks injection" recursive.
Before this, only the first level of child frames had the possibility to use
the Callbacks object. Now is injected recursively in all of them.

This is an extension of coverage for [Issue #683](http://code.google.com/p/phantomjs/issues/detail?id=683).
2012-09-18 22:46:14 +01:00
Ilya Grigorik fafa01d6ba Add missing pageref attribute to HAR and end-time.
http://code.google.com/p/phantomjs/issues/detail?id=733

Squashed commit of the following:

commit c6b984442c8631ac13308f5d72fd35973bd964d1
Author: Ilya Grigorik <ilya@igvita.com>
Date:   Sun Aug 26 12:23:03 2012 -0700

    add onLoad to pageTimings

commit d2bb53cd7340e920c62bed557bef4e3a1cdc62b2
Author: Ilya Grigorik <ilya@igvita.com>
Date:   Sun Aug 26 12:01:57 2012 -0700

    add mising pageref attr to each entry
2012-08-28 09:17:54 -07:00
Ariya Hidayat 1602394efb detectsniff example: Fix usage text.
http://code.google.com/p/phantomjs/issues/detail?id=680
2012-07-25 01:37:25 -07:00
Ariya Hidayat 281d291cfb Use the new Twitter handle for the examples.
http://code.google.com/p/phantomjs/issues/detail?id=609
2012-07-15 02:13:35 -07:00
Ariya Hidayat 0632658afe Add a simple example to show how the module system works.
http://code.google.com/p/phantomjs/issues/detail?id=47
2012-07-13 07:58:05 -07:00
Ariya Hidayat 91d31ffe9e Fix Twitter-related examples to work with the new site.
http://code.google.com/p/phantomjs/issues/detail?id=609
2012-06-20 22:55:04 -07:00
Ivan De Marino f386f7d484 Adding the ability to switch between frames.
1. Passing JavaScript eval and other related actions to the CurrentFrame, not the MainFrame.
2. Added different methods to navigate between frames
3. With a call to "window.frames[0].focus()", the "currentFrame" changes: commands after that are sent to the new frame under focus.
4. The navigation between frames allows to walk over the "tree of frames" contained in the page.

This commit also adds examples (both in JS and CoffeeScript) and Unit Test.

http://code.google.com/p/phantomjs/issues/detail?id=573
2012-06-15 00:07:53 -07:00
Ivan De Marino caf13651b7 Adding "window.phantomCallback()" within the page context.
The callback is harmless: if the user registers a "page.onCallback = [Function]",
that will receive any JS type passed via "phantomCallback()".
Also, if the handler for ".onCallback" returns a value, that is passed back as a
return value of "phantomCallback()".

Also, added "page.onConfirm" and "page.onPrompt".
This solves [Issue #133](http://code.google.com/p/phantomjs/issues/detail?id=133).
2012-06-14 23:29:13 -07:00
Milian Wolff 5c2e330a15 Make QWebPage::zoomFactor accessible to PhantomJS scripts.
This adds a new WebPage::zoomFactor property, which can be used to
zoom the page, i.e.:

page.zoomFactor = 1.5; // zoom by 50% in
page.zoomFactor = 0.5; // zoom by 50% out

The rasterize.js example is adapted to take an optional fourth argument
to set the zoom factor. Furthermore, the webpage-spec is extended with
a simple test case for the new property.

ISSUE: 579 (http://code.google.com/p/phantomjs/issues/detail?id=579)
2012-06-08 11:05:54 +02:00
Ariya Hidayat ca60a58596 Fix a wrong module require in imagebin example.
http://code.google.com/p/phantomjs/issues/detail?id=536
http://code.google.com/p/phantomjs/issues/detail?id=276
2012-05-17 23:41:33 -07:00
Brikou CARRE 1125b86e72 Fixed missing exit code when errornous.
http://code.google.com/p/phantomjs/issues/detail?id=544
2012-05-17 23:35:02 -07:00
Milian Wolff bf029ae65a Properly handle fourth CLI parameter in rasterize.js example.
After the change to system.args which has the app as first element,
the rasterize example was not properly adapted. Due to that, one
could not pass a size parameter to it anymore, resulting in PDFs
without page breaks.

ISSUE: 523 (http://code.google.com/p/phantomjs/issues/detail?id=523)
2012-05-02 15:31:46 +02:00
Milian Wolff b3d74c9a6c Extend printheaderfooter.js example documentation
The comment now explains how to delegate the header/footer setup
to the loaded HTML page by giving an explicit HTML example that
defines the required PhantomJSPrinting object

ISSUE: 512 (http://code.google.com/p/phantomjs/issues/detail?id=512)
2012-04-30 16:52:28 +07:00
Milian Wolff 24a9665c4d Make it possible to print pages with user-defined headers/footers.
Usage:

page.paperSize = {
  margin: "1cm",
  header: {
    height: "1cm",
    contents: phantom.callback(function(pageNum, numPages) {
      return "<h1>" + pageNum + " / " + numPages + "</h1>";
    })
  },
  footer: {
    height: "0.5cm",
    contents: phantom.callback(function(pageNum, numPages) {
      return "<h2>" + pageNum + " / " + numPages + "</h1>";
    })
  }
};

Note: The contents can return arbitrary HTML but since we cannot
re-layout the whole website for every page, the header/footers
must have the static height defined in the height property.

Note: The new example printheaderfooter.js shows the usage. It
also shows how one could delegate the above to a JavaScript
function on the loaded website, which allows one to print pages
and let the actually printed page decide how the header/footer
should look like.

Note: The page-counter can be reset by adding the class "phantomjs_reset_pagination"
to HTML block-elements that should reset the counter.

ISSUE: 410 (http://code.google.com/p/phantomjs/issues/detail?id=410)
2012-04-14 22:04:34 -07:00
Ariya Hidayat 26b28d7842 printenv.js: New example to show system.env.
This is very similar to Unix common 'printenv'.

http://code.google.com/p/phantomjs/issues/detail?id=271
2012-03-15 01:33:27 -07:00
Ariya Hidayat b7d7cfc542 Update more examples to use system.args.
http://code.google.com/p/phantomjs/issues/detail?id=276
2012-03-15 01:11:30 -07:00
execjosh b73ec44796 Update examples to use system.args.
Also update coffee-script script path names in usage messages.

http://code.google.com/p/phantomjs/issues/detail?id=276
2012-03-15 01:11:30 -07:00
Ariya Hidayat 6c7b0207f4 Make 'Keep Alive' option to use camel case.
Change 'keep-alive' to 'keepAlive' in the option for the server.
This allows setting the value (in JS object literal) without quoting.

http://code.google.com/p/phantomjs/issues/detail?id=429
2012-03-14 10:52:57 -07:00
Milian Wolff 7b909bfe45 Add example for keep-alive enabled webserver.
See examples/serverkeepalive.js.

http://code.google.com/p/phantomjs/issues/detail?id=416
2012-03-13 19:01:24 -07:00
Ariya Hidayat 74d4a6bd90 Change tweets.js example to official HeadlessPhantom Twitter account.
http://code.google.com/p/phantomjs/issues/detail?id=425
2012-03-12 21:35:40 -07:00
Brian Donovan f34e8b1528 Without arguments, functions must use parentheses in CoffeeScript.
http://code.google.com/p/phantomjs/issues/detail?id=326
2012-03-05 21:34:52 -08:00
Ariya Hidayat 1ae3c5aa2b Change follow.* example to Twitter accounts of PhantomJS contributors.
http://code.google.com/p/phantomjs/issues/detail?id=405
2012-03-04 21:49:47 -08:00
Chris Smith ddc0a7d623 Fix jasmine example terminating too early against jasmine 1.1.0.
The .finished-at element that was being checked for is present all
the time during the test run, so the waitFor call ended too early.

http://code.google.com/p/phantomjs/issues/detail?id=402
2012-03-01 08:17:51 -08:00
Milian Wolff 61eb86782b Filesystem module should allow reading and writing binary files.
CommonJS proposal: http://wiki.commonjs.org/wiki/Filesystem/A.
It's called "raw".

http://code.google.com/p/phantomjs/issues/detail?id=400

Squashed commit of the following:

commit dd5fab4778bb7b67f1eca26a07d430aadd458c6e
Author: Milian Wolff <milian.wolff@kdab.com>
Date:   Thu Feb 23 16:19:21 2012 +0100

    the "mode" string is now properly parsed, and not only the first
    char evaluated. This allows us to do fancy things like

    fs.open(file, "rw+"); // read/write/append

    Furthermore .read() is adapted such that it will always return the
    full file contents, no matter where we have seeked to before (i.e.
    by passing + we seek to the end, hence read() would always return
    an empty string).

    To open a binary file, pass "b" in the mode string to fs.open, e.g.:

    fs.open(file, "rb"); // read binary
    fs.open(file, "wb"); // write binary
    fs.open(file, "rwb+"); // read/write binary, append

    alternatively, one can use these shortcuts:

    fs.write(file, contents, "b"); // write binary
    fs.read(file, "b"); // read binary

    Unit tests are extended and the echoToFile.js example fixed (it did not
    close the file, which lead to the contents never getting written
    on-disk since flush() is never called).

    Also note that the FileSystem::open method was cleaned up and at least
    one memory leak (if QFile* could not open) was fixed. The code should
    now also be more C++-like.

commit 41139951138491459accefab22d48eba7b0b9900
Author: Milian Wolff <milian.wolff@kdab.com>
Date:   Wed Feb 15 16:39:23 2012 +0100

    use QString instead of QByteArray for raw binary data

    QByteArray is simply unusable in JavaScript, since functions like
    e.g. window.btoa expect a string. Also there is no sane way to
    create a byte array in javascript, as ArrayBuffer e.g. is not
    supported by QScript (at least there is no conversion in place).

    If we use QString and some custom read/write code this all works
    as expected though, we can use window.btoa to base64 encode binary
    data and we can create random binary data using String.fromCharCode

    also adds a unit test

commit e45673486ef27daf916902153217f9e5001b68c9
Author: Milian Wolff <milian.wolff@kdab.com>
Date:   Wed Feb 15 14:39:15 2012 +0100

    make it possible to read/write raw/binary files

    this adds File::readRaw and File::writeRaw functions,
    as well as 'shimmed' versions FS::readRaw and FS::writeRaw

    these functions directly use QFile and QByteArray instead of
    QTextStream and QString, making it possible to read and write
    binary data, e.g. images and such.
2012-02-29 07:55:00 -08:00
Ariya Hidayat 4515332d9d Merge remote-tracking branch 'KDAB/printing-margin' 2012-02-23 07:56:45 -08:00
Milian Wolff a638a07339 js-ify, rename and extend print-margins property
Now the left/top/right/bottom print margins can be set separately
using the pageSize.margin property. You can either use

pageSize.margin = "10px"

or use a map to set the margins separately:

pageSize.margin = {
  left: "10px",
  top: "5cm",
  right: "7in",
  bottom: "13mm"
};

pageSize.border is now a synonym for pageSize.margin to keep
compatibility to existing scripts.

ISSUE: 388 (http://code.google.com/p/phantomjs/issues/detail?id=388)
2012-02-23 14:25:16 +01:00
Milian Wolff 1411ebdff6 make POST/PUT data accessible from phantomjs server scripts
For POST and PUT request we now read all data as defined by
the Content-Length header into request.rawData property.
This property is a QByteArray which neatly maps to an array
in javascript.

For POST requests with Content-Type = applicaiton/x-www-form-urlencoded
we furthermore provide a parsed, easy-to-use request.post property.
This one is a QVariantMap of the decoded form data.

There is a new postserver.js example that shows the usage.

The unit test is extended to test the new (and old) features
of the server.

TODO: test that verifies proper decoding of UTF8 data, which
is not yet possible since I see no way to do a post-request
using phantomjs with an explicitly defined charset

ISSUE: 340 (http://code.google.com/p/phantomjs/issues/detail?id=340)
2012-02-15 18:41:51 -08:00
Leo Franchi bbce8920d0 Make Mongoose webserver asynchronous.
This allows for asynchronous reply handling, which is much more logical when dealing with the async
nature of PhantomJS like page.open(). This uses a async patch from Andy Rahn's Mongoose close,
available here: http://code.google.com/r/andyrahn-async/

This is from https://github.com/ariya/phantomjs/pull/202.

http://code.google.com/p/phantomjs/issues/detail?id=326
2012-02-14 23:08:38 -08:00
Ariya Hidayat 5528c046db Some API changes in the WebServer module.
Trying to match http://nodejs.org/docs/latest/api/http.html.

For the server response:

  * Change writeBody to write
  * Change writeHeaders to writeHead

For the request object, 'headers' is now an object containing all
key-value pairs of the actual HTTP headers.

'queryString' is folded into 'url' key.

Non-standard keys in the request: isSSL, remotePort, remoteIP,
remoteUser, are disabled in the mean-time (will be revisited after 1.4
release).

Implementation-wise, the request object is now a simple key-value pair
using QVariant, as opposed to the heavy QObject instance.

http://code.google.com/p/phantomjs/issues/detail?id=115
2011-12-19 18:38:21 -08:00
Ariya Hidayat feafb4f5a3 Add the CoffeeScript version of simpleserver.
This is for the new simpleserver example introduced in commit 9eae7f1.

http://code.google.com/p/phantomjs/issues/detail?id=115
2011-12-19 17:55:27 -08:00
Ariya Hidayat 9eae7f101b Add a simpler example for the WebServer module.
This does nothing but to start an HTTP server on the given port.
The request is merely dumped back as the formatted response.

This example is useful for simple troubleshooting.

http://code.google.com/p/phantomjs/issues/detail?id=115
2011-12-19 08:28:06 -08:00
Ariya Hidayat 6983f6bdf1 Update Sencha folks. 2011-12-19 01:14:31 -08:00
Milian Wolff bd2052631f basic unit testing for WebServer.listen 2011-11-15 13:45:11 +01:00
Milian Wolff a6bde751a9 extend WebServerResponse API 2011-11-15 13:45:11 +01:00
Milian Wolff 705eda8823 add read-properties to WebServerRequest 2011-11-15 13:45:11 +01:00
Milian Wolff 245eec551f make it possible to access the request headers 2011-11-15 13:45:11 +01:00
Milian Wolff f30bfa9fb7 extend WebServerRequest API 2011-11-15 13:45:11 +01:00
Milian Wolff 0abdc7f9ed very basic response + request handling for WebServer
the api is very limited but already makes the server.js example
do something useful with the server
2011-11-15 13:45:11 +01:00
Milian Wolff 73705e484b first work towards a WebServer
this is the minimal server that gets properly embedded into
the phantomjs space but the .listen api is missing actually
useful options (incoming request and ability to write to client)
2011-11-15 13:44:47 +01:00