Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
f7d97089
...
f7d9708961396737ba2ce79ee82262833ddbe791
authored
2013-08-19 20:25:11 +0200
by
Mickaël Andrieu
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add a better sample of nodejs modules integration
https://github.com/n1k0/casperjs/pull/587
1 parent
4d6f5ef5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
5 deletions
docs/writing_modules.rst
docs/writing_modules.rst
View file @
f7d9708
...
...
@@ -33,15 +33,42 @@ From your root casper script::
.. hint::
CasperJS is able to call nodejs modules in the same way that phantomjs, take a look at the example below::
CasperJS is able to call nodejs modules in the same way that phantomjs, take a look at the example below.
// underscoreByNpm.js
require('underscore').uniq([1, 2, 3, 2, 3]) );
With:
First, install a module using npm_ :
.. _npm: https://npmjs.org/
.. code-block:: text
$ npm install underscore
Then, you can access it using ``require`` function::
//npm-underscore-test.js
var _ = require('underscore');
var casper = require('casper').create();
var urls = _.uniq([
'http://google.com/',
'http://docs.casperjs.org/',
'http://google.com/'
]);
casper.start().eachThen(urls, function(response) {
this.thenOpen(response.data, function(response) {
this.echo(this.getTitle());
});
});
casper.run();
Finaly, you’ll probably get something like this:
.. code-block:: text
$ casperjs npm-underscore-test.js
Google
CasperJS documentation ÔÇö CasperJS 1.1.0-DEV documentation
...
...
Please
register
or
sign in
to post a comment