Commit bbd5410c bbd5410c38d610da6872d890e712ed4279fa4620 by Nicolas Perriault

added an event as a Casper option

1 parent 38c19678
Showing 1 changed file with 15 additions and 9 deletions
...@@ -26,12 +26,15 @@ ...@@ -26,12 +26,15 @@
26 /** 26 /**
27 * Main Casper class. Available options are: 27 * Main Casper class. Available options are:
28 * 28 *
29 * Type Name Default Description 29 * Name | Type | Default | Description
30 * - Array clientScripts ([]): A collection of script filepaths to include to every page loaded 30 * ——————————————————+——————————+—————————+————————————————————————————————————————————————————————————————————
31 * - String logLevel ("error") Logging level (see logLevels for available values) 31 * clientScripts | Array | [] | A collection of script filepaths to include to every page loaded
32 * - Object pageSettings ({}): PhantomJS's WebPage settings object 32 * logLevel | String | "error" | Logging level (see logLevels for available values)
33 * - WebPage page (null): An existing WebPage instance 33 * onDie | function | null | A function to be called when Casper#die() is called
34 * - Boolean verbose (false): Realtime output of log messages 34 * onPageInitialized | function | null | A function to be called after WebPage instance has been initialized
35 * page | WebPage | null | An existing WebPage instance
36 * pageSettings | Object | {} | PhantomJS's WebPage settings object
37 * verbose | Boolean | false | Realtime output of log messages
35 * 38 *
36 * @param Object options Casper options 39 * @param Object options Casper options
37 * @return Casper 40 * @return Casper
...@@ -48,10 +51,9 @@ ...@@ -48,10 +51,9 @@
48 clientScripts: [], 51 clientScripts: [],
49 logLevel: "error", 52 logLevel: "error",
50 onDie: null, 53 onDie: null,
54 onPageInitialized: null,
51 page: null, 55 page: null,
52 pageSettings: { 56 pageSettings: { userAgent: DEFAULT_USER_AGENT },
53 userAgent: DEFAULT_USER_AGENT,
54 },
55 verbose: false 57 verbose: false
56 }; 58 };
57 // local properties 59 // local properties
...@@ -398,6 +400,10 @@ ...@@ -398,6 +400,10 @@
398 } 400 }
399 this.page.settings = mergeObjects(this.page.settings, this.options.pageSettings); 401 this.page.settings = mergeObjects(this.page.settings, this.options.pageSettings);
400 this.started = true; 402 this.started = true;
403 if (typeof(this.options.onPageInitialized) === "function") {
404 this.log("Post-configuring WebPage instance", "debug");
405 this.options.onPageInitialized(this.page);
406 }
401 if (typeof(location) === "string" && location.length > 0) { 407 if (typeof(location) === "string" && location.length > 0) {
402 if (typeof(then) === "function") { 408 if (typeof(then) === "function") {
403 return this.open(location).then(then); 409 return this.open(location).then(then);
......