You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 4, 2023. It is now read-only.
CasperJS ships with a built-in command line parser on top of PhantomJS' one, located in the ``cli`` module; it exposes passed arguments as **positional ones** and **named options**
8
10
@@ -85,10 +87,15 @@ Last but not least, you can still use all PhantomJS standard CLI options as you
85
87
Hint To remember what the native phantomjs available cli options are,
86
88
run the ``phantomjs --help`` command.
87
89
90
+
91
+
.. index:: Raw values
92
+
88
93
Raw parameter values
89
94
--------------------
90
95
91
-
Added in 1.0 By default, the cli object will process every passed argument & cast them to the appropriate detected type; example script::
96
+
.. versionadded:: 1.0
97
+
98
+
By default, the cli object will process every passed argument & cast them to the appropriate detected type; example script::
Copy file name to clipboardExpand all lines: debugging.rst
+30-6Lines changed: 30 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,18 @@
1
1
.. _debugging:
2
2
3
+
.. index:: Bugs, Debugging
4
+
3
5
=========
4
6
Debugging
5
7
=========
6
8
7
9
Here's are a few tips for debugging your casper scripts.
8
10
9
-
Use the verbose mode
10
-
--------------------
11
11
12
-
By default & by design, a ``Casper`` instance won't print anything to the console. This can be very limitating & frustrating when creating or debugging scripts, so a good practice is to always start coding a scrip using these settings::
12
+
Use the :index:`verbose` mode
13
+
-----------------------------
14
+
15
+
By default & by design, a ``Casper`` instance won't print anything to the console. This can be very limitating & frustrating when creating or debugging scripts, so a good practice is to always start coding a script using these :index:`settings`::
13
16
14
17
var casper = require('casper').create({
15
18
verbose: true,
@@ -22,8 +25,9 @@ The ``verbose`` setting will tell Casper to write every logged message at the ``
22
25
23
26
Output will then be pretty verbose, and will potentially display sensitive informations onto the console. **Use with care on production.**
24
27
25
-
Hook in the deep using events
26
-
-----------------------------
28
+
29
+
Hook in the deep using :index:`events`
30
+
--------------------------------------
27
31
28
32
:doc:`Events <events-filters>` are a very powerful features of CasperJS, and you should probably give it a look if you haven't already.
29
33
@@ -43,11 +47,31 @@ Listening to an event is dead easy::
43
47
44
48
Ensure to check the :ref:`full list <events_list>` of all the other available events.
45
49
50
+
51
+
.. _debugging_dump:
52
+
53
+
Dump serialized values to the console
54
+
-------------------------------------
55
+
56
+
Sometimes it's helpful to inspect a variable, especially Object contents. The :ref:`utils_dump() <utils_dump>` function can achieve just that::
57
+
58
+
require('utils').dump({
59
+
foo: {
60
+
bar: 42
61
+
},
62
+
});
63
+
64
+
.. note::
65
+
66
+
:ref:`utils_dump() <utils_dump>` won't be able to serialize function nor complex cyclic structures though.
67
+
68
+
46
69
Localize yourself in modules
47
70
----------------------------
48
71
49
72
If you're creating Casper modules, a cool thing to know is that there's a special built-in variable available in every module, ``__file__``, which contains the absolute path to current javascript file (the module file).
50
73
74
+
51
75
Name your closures
52
76
------------------
53
77
@@ -73,6 +97,6 @@ Probably one of the most easy but effective best practice, always name your clos
73
97
});
74
98
});
75
99
76
-
That way, everytime one is failing, its name will be printed out in the *stack trace*, **so you can more easily locate it within your code**.
100
+
That way, everytime one is failing, its name will be printed out in the :index:`stack trace`, **so you can more easily locate it within your code**.
77
101
78
102
Note that this one also applies for all your other Javascript works, of course ;)
Copy file name to clipboardExpand all lines: events-filters.rst
+42-27Lines changed: 42 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,8 @@ Events & filters
6
6
CasperJS provides an `event handler <#events>`_ very similar to the `nodejs <http://nodejs.org>`_' `one <https://github.com/joyent/node/blob/master/lib/events.js>`_; actually it borrows most of its codebase. CasperJS also adds `filters <#filters>`_, which are basically ways to alter values asynchronously.
7
7
8
8
9
+
.. index:: ! events
10
+
9
11
Events
10
12
------
11
13
@@ -20,9 +22,7 @@ Using events is pretty much straightforward if you're a node developer, or if yo
20
22
Emitting you own events
21
23
+++++++++++++++++++++++
22
24
23
-
Of course you can emit your own events, using the ``Casper.emit()`` method:
24
-
25
-
::
25
+
Of course you can emit your own events, using the ``Casper.emit()`` method::
26
26
27
27
var casper = require('casper').create();
28
28
@@ -48,15 +48,16 @@ Events reference
48
48
49
49
**Arguments:** ``None``
50
50
51
-
Emitted when the embedded browser is asked to go back a step in its
52
-
history.
51
+
Emitted when the embedded browser is asked to go back a step in its history.
53
52
54
53
``capture.saved``
55
54
~~~~~~~~~~~~~~~~~
56
55
57
56
**Arguments:** ``targetFile``
58
57
59
-
Emitted when a screenshot image has been captured.
58
+
Emitted when a :index:`screenshot` image has been captured.
59
+
60
+
.. index:: click
60
61
61
62
``click``
62
63
~~~~~~~~~
@@ -72,13 +73,17 @@ Emitted when the ``Casper.click()`` method has been called.
72
73
73
74
Emitted when the ``Casper.die()`` method has been called.
74
75
76
+
.. index:: download
77
+
75
78
``downloaded.file``
76
79
~~~~~~~~~~~~~~~~~~~
77
80
78
81
**Arguments:** ``targetPath``
79
82
80
83
Emitted when a file has been downloaded by :ref:`Casper.download() <casper_download>`; ``target`` will contain the path to the downloaded file.
81
84
85
+
.. index:: error
86
+
82
87
``error``
83
88
~~~~~~~~~
84
89
@@ -88,13 +93,17 @@ Emitted when a file has been downloaded by :ref:`Casper.download() <casper_downl
88
93
89
94
Emitted when an error hasn't been caught. Do basically what PhantomJS' ``onError()`` native handler does.
90
95
96
+
.. index:: exit
97
+
91
98
``exit``
92
99
~~~~~~~~
93
100
94
101
**Arguments:** ``status``
95
102
96
103
Emitted when the ``Casper.exit()`` method has been called.
97
104
105
+
.. index:: fill
106
+
98
107
``fill``
99
108
~~~~~~~~
100
109
@@ -109,21 +118,23 @@ Emitted when a form is filled using the ``Casper.fill()`` method.
109
118
110
119
Emitted when the embedded browser is asked to go forward a step in its history.
111
120
121
+
.. index:: auth
122
+
112
123
``http.auth``
113
124
~~~~~~~~~~~~~
114
125
115
126
**Arguments:** ``username, password``
116
127
117
128
Emitted when http authentication parameters are set.
118
129
130
+
.. index:: HTTP
131
+
119
132
``http.status.[code]``
120
133
~~~~~~~~~~~~~~~~~~~~~~
121
134
122
135
**Arguments:** ``resource``
123
136
124
-
Emitted when any given HTTP reponse is received with the status code specified by ``[code]``, eg.:
125
-
126
-
::
137
+
Emitted when any given HTTP reponse is received with the status code specified by ``[code]``, eg.::
127
138
128
139
casper.on('http.status.404', function(resource) {
129
140
casper.echo(resource.url + ' is 404');
@@ -150,14 +161,14 @@ Emitted when PhantomJS' ``WebPage.onLoadFinished`` event callback has been calle
150
161
151
162
Emitted when PhantomJS' ``WebPage.onLoadFinished`` event callback is called.
152
163
164
+
.. index:: log
165
+
153
166
``log``
154
167
~~~~~~~
155
168
156
169
**Arguments:** ``entry``
157
170
158
-
Emitted when the ``Casper.log()`` method has been called. The ``entry`` parameter is an Object like this:
159
-
160
-
::
171
+
Emitted when the ``Casper.log()`` method has been called. The ``entry`` parameter is an Object like this::
161
172
162
173
{
163
174
level: "debug",
@@ -166,6 +177,8 @@ Emitted when the ``Casper.log()`` method has been called. The ``entry`` paramete
166
177
date: "a javascript Date instance"
167
178
}
168
179
180
+
..index:: click
181
+
169
182
``mouse.click``
170
183
~~~~~~~~~~~~~~~
171
184
@@ -203,14 +216,14 @@ Emitted when the mouse releases the left button over something or somewhere.
203
216
204
217
Emitted each time a navigation operation has been requested. Available navigation types are: ``LinkClicked``, ``FormSubmitted``, ``BackOrForward``, ``Reload``, ``FormResubmitted`` and ``Other``.
205
218
219
+
.. index:: HTTP
220
+
206
221
``open``
207
222
~~~~~~~~
208
223
209
224
``location, settings``
210
225
211
-
Emitted when an HTTP request is sent. First callback arg is the location, second one is a request settings Object of the form:
212
-
213
-
::
226
+
Emitted when an HTTP request is sent. First callback arg is the location, second one is a request settings Object of the form::
214
227
215
228
{
216
229
method: "post",
@@ -229,9 +242,7 @@ Emitted when PhantomJS' ``WebPage`` object used by CasperJS has been created.
229
242
230
243
**Arguments:** ``message, trace``
231
244
232
-
Emitted when retrieved page leaved a Javascript error uncaught:
233
-
234
-
::
245
+
Emitted when retrieved page leaved a Javascript error uncaught::
235
246
236
247
casper.on("page.error", function(msg, trace) {
237
248
this.echo("Error: " + msg, "ERROR");
@@ -244,13 +255,17 @@ Emitted when retrieved page leaved a Javascript error uncaught:
244
255
245
256
Emitted when PhantomJS' ``WebPage`` object used by CasperJS has been initialized.
246
257
258
+
.. index:: HTTP
259
+
247
260
``page.resource.received``
248
261
~~~~~~~~~~~~~~~~~~~~~~~~~~
249
262
250
263
**Arguments:** ``response``
251
264
252
265
Emitted when the HTTP response corresponding to current required url has been received.
253
266
267
+
.. index:: HTTP
268
+
254
269
``page.resource.requested``
255
270
~~~~~~~~~~~~~~~~~~~~~~~~~~~
256
271
@@ -391,6 +406,8 @@ Emitted when the execution time of the script has reached the ``Casper.options.t
391
406
392
407
Added in 1.0 Emitted each time the current page url changes.
393
408
409
+
.. index:: viewport
410
+
394
411
``viewport.changed``
395
412
~~~~~~~~~~~~~~~~~~~~
396
413
@@ -420,12 +437,12 @@ Emitted when a ``Casper.wait()`` operation starts.
420
437
Emitted when the execution time of a ``Casper.wait*()`` operation has exceeded the value of ``Casper.options.stepTimeout``.
421
438
422
439
440
+
.. index:: filters
441
+
423
442
Filters
424
443
-------
425
444
426
-
Filters allow you to alter some values asynchronously. Sounds obscure? Let's take a simple example and imagine you would like to alter every single url opened by CasperJS to append a ``foo=42`` query string parameter:
427
-
428
-
::
445
+
Filters allow you to alter some values asynchronously. Sounds obscure? Let's take a simple example and imagine you would like to alter every single url opened by CasperJS to append a ``foo=42`` query string parameter::
429
446
430
447
var casper = require('casper').create();
431
448
@@ -440,6 +457,8 @@ Here'a the list of all available filters with their expected return value:
440
457
Filters reference
441
458
+++++++++++++++++
442
459
460
+
.. index:: screenshot
461
+
443
462
``capture.target_filename``
444
463
~~~~~~~~~~~~~~~~~~~~~~~~~~~
445
464
@@ -485,9 +504,7 @@ Allows to alter every url before it being opened.
485
504
486
505
.. versionadded:: 1.0
487
506
488
-
Allows to react on a javascript ``confirm()`` call:
489
-
490
-
::
507
+
Allows to react on a javascript ``confirm()`` call::
491
508
492
509
casper.setFilter("page.confirm", function(msg) {
493
510
return msg === "Do you like vbscript?" ? false : true;
@@ -502,9 +519,7 @@ Allows to react on a javascript ``confirm()`` call:
502
519
503
520
.. versionadded:: 1.0
504
521
505
-
Allows to react on a javascript ``prompt()`` call:
506
-
507
-
::
522
+
Allows to react on a javascript ``prompt()`` call::
Copy file name to clipboardExpand all lines: extending.rst
+6-1Lines changed: 6 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
.. _extending:
2
2
3
+
.. index:: extending, inheritance, prototype
4
+
3
5
=========
4
6
Extending
5
7
=========
@@ -92,7 +94,10 @@ But that's just plain old *monkey-patching* the ``casper`` object, and you may p
92
94
93
95
**Don't forget to call ``Casper``'s parent constructor!**
94
96
95
-
Note Of course this approach is bit more verbose than the easy *monkey-patching* one, so please ensure you're not just overengineering stuff by subclassing the ``Casper`` class.
97
+
Of course this approach is bit more verbose than the easy *monkey-patching* one, so please ensure you're not just overengineering stuff by subclassing the ``Casper`` class.
0 commit comments