refs #15 - added Casper.options.onResourceRequested() and Casper.options.onResou…
…rceReceived() callbacks
Showing
2 changed files
with
30 additions
and
1 deletions
... | @@ -49,6 +49,8 @@ | ... | @@ -49,6 +49,8 @@ |
49 | onError: null, | 49 | onError: null, |
50 | onLoadError: null, | 50 | onLoadError: null, |
51 | onPageInitialized: null, | 51 | onPageInitialized: null, |
52 | onResourceReceived: null, | ||
53 | onResourceRequested: null, | ||
52 | onStepComplete: null, | 54 | onStepComplete: null, |
53 | onStepTimeout: null, | 55 | onStepTimeout: null, |
54 | onTimeout: null, | 56 | onTimeout: null, |
... | @@ -1714,6 +1716,9 @@ | ... | @@ -1714,6 +1716,9 @@ |
1714 | casper.loadInProgress = false; | 1716 | casper.loadInProgress = false; |
1715 | }; | 1717 | }; |
1716 | page.onResourceReceived = function(resource) { | 1718 | page.onResourceReceived = function(resource) { |
1719 | if (isType(casper.options.onResourceReceived, "function")) { | ||
1720 | casper.options.onResourceReceived(casper, resource); | ||
1721 | } | ||
1717 | if (resource.url === casper.requestUrl && resource.stage === "start") { | 1722 | if (resource.url === casper.requestUrl && resource.stage === "start") { |
1718 | casper.currentHTTPStatus = resource.status; | 1723 | casper.currentHTTPStatus = resource.status; |
1719 | if (isType(casper.options.httpStatusHandlers, "object") && resource.status in casper.options.httpStatusHandlers) { | 1724 | if (isType(casper.options.httpStatusHandlers, "object") && resource.status in casper.options.httpStatusHandlers) { |
... | @@ -1722,6 +1727,11 @@ | ... | @@ -1722,6 +1727,11 @@ |
1722 | casper.currentUrl = resource.url; | 1727 | casper.currentUrl = resource.url; |
1723 | } | 1728 | } |
1724 | }; | 1729 | }; |
1730 | page.onResourceRequested = function(request) { | ||
1731 | if (isType(casper.options.onResourceRequested, "function")) { | ||
1732 | casper.options.onResourceRequested(casper, request); | ||
1733 | } | ||
1734 | }; | ||
1725 | return page; | 1735 | return page; |
1726 | } | 1736 | } |
1727 | 1737 | ... | ... |
... | @@ -216,13 +216,32 @@ casper.thenOpen('tests/site/global.html', function(self) { | ... | @@ -216,13 +216,32 @@ casper.thenOpen('tests/site/global.html', function(self) { |
216 | // Casper.options.onStepComplete | 216 | // Casper.options.onStepComplete |
217 | casper.then(function(self) { | 217 | casper.then(function(self) { |
218 | self.options.onStepComplete = function(self, stepResult) { | 218 | self.options.onStepComplete = function(self, stepResult) { |
219 | self.test.comment('Casper.options.onStepComplete()') | 219 | self.test.comment('Casper.options.onStepComplete()'); |
220 | self.test.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete'); | 220 | self.test.assertEquals(stepResult, 'ok', 'Casper.options.onStepComplete() is called on step complete'); |
221 | self.options.onStepComplete = null; | 221 | self.options.onStepComplete = null; |
222 | }; | 222 | }; |
223 | return 'ok'; | 223 | return 'ok'; |
224 | }); | 224 | }); |
225 | 225 | ||
226 | // Casper.options.onResourceRequested & Casper.options.onResourceReceived | ||
227 | casper.then(function(self) { | ||
228 | self.options.onResourceReceived = function(self, resource) { | ||
229 | self.test.comment('Casper.options.onResourceReceived()'); | ||
230 | self.test.assertType(resource, 'object', 'Casper.options.onResourceReceived() retrieve a resource object'); | ||
231 | self.test.assert('status' in resource, 'Casper.options.onResourceReceived() retrieve a valid resource object') | ||
232 | self.options.onResourceReceived = null; | ||
233 | }; | ||
234 | self.options.onResourceRequested = function(self, request) { | ||
235 | self.test.comment('Casper.options.onResourceRequested()'); | ||
236 | self.test.assertType(request, 'object', 'Casper.options.onResourceRequested() retrieve a request object'); | ||
237 | self.test.assert('method' in request, 'Casper.options.onResourceRequested() retrieve a valid request object') | ||
238 | self.options.onResourceRequested = null; | ||
239 | }; | ||
240 | self.thenOpen('tests/site/page1.html'); | ||
241 | }); | ||
242 | |||
243 | |||
244 | |||
226 | // History | 245 | // History |
227 | casper | 246 | casper |
228 | .thenOpen('tests/site/page1.html') | 247 | .thenOpen('tests/site/page1.html') | ... | ... |
-
Please register or sign in to post a comment