added new 'timeout' option to Casper, I guess its name speaks for itself
Showing
2 changed files
with
9 additions
and
0 deletions
... | @@ -209,6 +209,7 @@ onDie | function | null | A function to be called when Casper#die | ... | @@ -209,6 +209,7 @@ onDie | function | null | A function to be called when Casper#die |
209 | onPageInitialized | function | null | A function to be called after WebPage instance has been initialized | 209 | onPageInitialized | function | null | A function to be called after WebPage instance has been initialized |
210 | page | WebPage | null | An existing WebPage instance | 210 | page | WebPage | null | An existing WebPage instance |
211 | pageSettings | Object | {} | PhantomJS's WebPage settings object | 211 | pageSettings | Object | {} | PhantomJS's WebPage settings object |
212 | timeout | Number | null | Max timeout in milliseconds | ||
212 | verbose | Boolean | false | Realtime output of log messages | 213 | verbose | Boolean | false | Realtime output of log messages |
213 | ``` | 214 | ``` |
214 | 215 | ... | ... |
... | @@ -35,6 +35,7 @@ | ... | @@ -35,6 +35,7 @@ |
35 | * onPageInitialized | function | null | A function to be called after WebPage instance has been initialized | 35 | * onPageInitialized | function | null | A function to be called after WebPage instance has been initialized |
36 | * page | WebPage | null | An existing WebPage instance | 36 | * page | WebPage | null | An existing WebPage instance |
37 | * pageSettings | Object | {} | PhantomJS's WebPage settings object | 37 | * pageSettings | Object | {} | PhantomJS's WebPage settings object |
38 | * timeout | Number | null | Max timeout in milliseconds | ||
38 | * verbose | Boolean | false | Realtime output of log messages | 39 | * verbose | Boolean | false | Realtime output of log messages |
39 | * | 40 | * |
40 | * @param Object options Casper options | 41 | * @param Object options Casper options |
... | @@ -56,6 +57,7 @@ | ... | @@ -56,6 +57,7 @@ |
56 | onPageInitialized: null, | 57 | onPageInitialized: null, |
57 | page: null, | 58 | page: null, |
58 | pageSettings: { userAgent: DEFAULT_USER_AGENT }, | 59 | pageSettings: { userAgent: DEFAULT_USER_AGENT }, |
60 | timeout: null, | ||
59 | verbose: false | 61 | verbose: false |
60 | }; | 62 | }; |
61 | // local properties | 63 | // local properties |
... | @@ -418,6 +420,12 @@ | ... | @@ -418,6 +420,12 @@ |
418 | } | 420 | } |
419 | this.page.settings = mergeObjects(this.page.settings, this.options.pageSettings); | 421 | this.page.settings = mergeObjects(this.page.settings, this.options.pageSettings); |
420 | this.started = true; | 422 | this.started = true; |
423 | if (typeof(this.options.timeout) === "number" && this.options.timeout > 0) { | ||
424 | self.log("execution timeout set to " + this.options.timeout + 'ms', "info"); | ||
425 | setTimeout(function(self) { | ||
426 | self.log("timeout of " + self.options.timeout + "ms exceeded", "info").exit(); | ||
427 | }, this.options.timeout, this); | ||
428 | } | ||
421 | if (typeof(this.options.onPageInitialized) === "function") { | 429 | if (typeof(this.options.onPageInitialized) === "function") { |
422 | this.log("Post-configuring WebPage instance", "debug"); | 430 | this.log("Post-configuring WebPage instance", "debug"); |
423 | this.options.onPageInitialized(this.page); | 431 | this.options.onPageInitialized(this.page); | ... | ... |
-
Please register or sign in to post a comment